BRL-CAD
sh_toyota.c File Reference
#include "common.h"
#include <stddef.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include "vmath.h"
#include "mater.h"
#include "raytrace.h"
#include "optical.h"
#include "plot3.h"
#include "light.h"
Include dependency graph for sh_toyota.c:

Go to the source code of this file.

Data Structures

struct  toyota_specific
 

Macros

#define CLEAR_SKY   0
 
#define MEDIUM_SKY   1
 
#define OVERCAST_SKY   2
 
#define MIKE_TOL   .000001
 
#define CK_NULL   ((struct toyota_specific *)0)
 
#define CL_O(m)   bu_offsetof(struct toyota_specific, m)
 
#define RI_AIR   1.0 /* Refractive index of air. */
 
#define NSIRRAD   992 /* Number of entries in solar irradiance table. */
 
#define NABSORP   38 /* Number of entries in absorption coefficient table. */
 
#define NCOLOR   90
 
#define SPREAD   (10*DEG2RAD)
 

Functions

HIDDEN int toyota_setup (register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
 
HIDDEN int tmirror_setup (register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
 
HIDDEN int tglass_setup (register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
 
HIDDEN int toyota_render (register struct application *ap, const struct partition *pp, struct shadework *swp, void *dp)
 
HIDDEN void toyota_print (register struct region *rp, void *dp)
 
HIDDEN void toyota_free (void *cp)
 
void lambda_to_rgb (fastf_t lambda, fastf_t irrad, fastf_t *rgb)
 
void spectral_dist_table (fastf_t lambda, fastf_t *e_mean, fastf_t *v1, fastf_t *v2)
 
fastf_t atmos_irradiance (fastf_t lambda)
 
fastf_t air_mass (fastf_t in_gamma)
 
fastf_t background_light (fastf_t lambda, struct toyota_specific *ts, fastf_t *Refl, fastf_t *Sun, fastf_t t_vl, struct shadework *swp)
 
fastf_t clear_sky_lum (fastf_t lz, fastf_t *Sky_elmt, fastf_t *Sun, fastf_t *Zenith)
 
fastf_t fresnel_refl (fastf_t cos_eps, fastf_t n1, fastf_t n2)
 
fastf_t homogenous_sky_lum (fastf_t *Sky_elmt, fastf_t *Sun, fastf_t t_vl)
 
fastf_t sun_radiance (fastf_t lambda, fastf_t alpha, fastf_t beta, fastf_t sun_alt, fastf_t sun_sang)
 
fastf_t absorp_coeff (fastf_t lambda, char *material)
 
fastf_t overcast_sky_lum (fastf_t lz, fastf_t *Zenith, fastf_t *Sky_elmt)
 
fastf_t ozone_absorption (fastf_t lambda)
 
fastf_t skylight_spectral_dist (fastf_t lambda, fastf_t *Zenith, fastf_t *Sky_elmt, fastf_t *Sun, int weather, fastf_t t_vl)
 
fastf_t zenith_luminance (fastf_t sun_alt, fastf_t t_vl)
 
fastf_t reflectance (fastf_t lambda, fastf_t alpha, fastf_t *refl, int lines)
 

Variables

struct bu_structparse toyota_parse []
 
struct mfuncs toyota_mfuncs []
 

Detailed Description

Notes - Implementation of model developed by Atsushi Takagi, Hitoshi Takaoka, Tetsuya Oshima, and Yoshinori Ogata described in the paper "Accurate Rendering Technique Based on Colorimetric Conception" in "Computer Graphics, Volume 24, Number 4, August 1990", an ACM SIGGRAPH Publication, pp. 263-72. References to Toyota in this module refer to that paper.

The normals on all surfaces point OUT of the solid. The incoming light rays point IN. Thus the sign change.

Definition in file sh_toyota.c.

Macro Definition Documentation

#define CLEAR_SKY   0

Definition at line 51 of file sh_toyota.c.

Referenced by skylight_spectral_dist(), and toyota_setup().

#define MEDIUM_SKY   1

Definition at line 52 of file sh_toyota.c.

Referenced by skylight_spectral_dist().

#define OVERCAST_SKY   2

Definition at line 53 of file sh_toyota.c.

Referenced by skylight_spectral_dist().

#define MIKE_TOL   .000001

Definition at line 55 of file sh_toyota.c.

Referenced by absorp_coeff(), and background_light().

#define CK_NULL   ((struct toyota_specific *)0)

Definition at line 72 of file sh_toyota.c.

#define CL_O (   m)    bu_offsetof(struct toyota_specific, m)

Definition at line 73 of file sh_toyota.c.

#define RI_AIR   1.0 /* Refractive index of air. */

Definition at line 120 of file sh_toyota.c.

Referenced by toyota_render().

#define NSIRRAD   992 /* Number of entries in solar irradiance table. */

Referenced by atmos_irradiance().

#define NABSORP   38 /* Number of entries in absorption coefficient table. */

Referenced by ozone_absorption().

#define NCOLOR   90

Referenced by lambda_to_rgb().

#define SPREAD   (10*DEG2RAD)

Referenced by background_light().

Function Documentation

HIDDEN int toyota_setup ( register struct region rp,
struct bu_vls matparm,
void **  dpp,
const struct mfuncs *  mfp,
struct rt_i rtip 
)

These should be measured values, but since we're lazy let's use values Toyota carefully measured in Japan one day.

Data measured: 11:28am, October 20, 1989 (Friday)

Location: Toyota-city, Aichi-prefecture, Japan at 35d 2'55.07" North, 137d 9'45.26" East

Measuring Instruments: Precision pyrheliometer (Model MS-52 made by Eko Co., Ltd.), Sun-photo meter (Model MS-110 made by Eko Co., Ltd.), Luminance meter (MINOLTA CS-100)

Definition at line 136 of file sh_toyota.c.

References toyota_specific::alpha, toyota_specific::atmos_trans, toyota_specific::beta, bu_bomb(), BU_CK_VLS, BU_GET, bu_log(), bu_malloc(), BU_PUT, bu_strlcpy, bu_strncmp(), bu_struct_parse(), CLEAR_SKY, toyota_specific::glass, toyota_specific::index_refrac, toyota_specific::material, toyota_specific::refl, toyota_specific::refl_lines, toyota_specific::sun_sang, VSET, toyota_specific::weather, and toyota_specific::Zenith.

Here is the call graph for this function:

HIDDEN int tmirror_setup ( register struct region rp,
struct bu_vls matparm,
void **  dpp,
const struct mfuncs *  mfp,
struct rt_i rtip 
)

Definition at line 223 of file sh_toyota.c.

References BU_CK_VLS, and BU_GET.

HIDDEN int tglass_setup ( register struct region rp,
struct bu_vls matparm,
void **  dpp,
const struct mfuncs *  mfp,
struct rt_i rtip 
)

Definition at line 242 of file sh_toyota.c.

References BU_CK_VLS, and BU_GET.

HIDDEN int toyota_render ( register struct application ap,
const struct partition pp,
struct shadework *  swp,
void *  dp 
)

Lighting model developed by Toyota. "Technique makes it possible to:

(1) Generate an image as if it is an actual object. (2) Render any material and color. (3) Render the appearance at any place and time under any weather conditions."

Definition at line 2239 of file sh_toyota.c.

References application::a_ray, application::a_rt_i, absorp_coeff(), toyota_specific::alpha, background_light(), toyota_specific::beta, fresnel_refl(), toyota_specific::glass, toyota_specific::index_refrac, lambda_to_rgb(), toyota_specific::material, pdv_3line(), pl_color(), xray::r_dir, rdebug, RDEBUG_RAYPLOT, toyota_specific::refl, toyota_specific::refl_lines, reflectance(), RI_AIR, rt_i::rti_nlights, skylight_spectral_dist(), sun_radiance(), toyota_specific::sun_sang, toyota_specific::wavelength, toyota_specific::weather, and toyota_specific::Zenith.

Here is the call graph for this function:

HIDDEN void toyota_print ( register struct region rp,
void *  dp 
)

Definition at line 261 of file sh_toyota.c.

References bu_struct_print(), and region::reg_name.

Here is the call graph for this function:

HIDDEN void toyota_free ( void *  cp)

Definition at line 268 of file sh_toyota.c.

References BU_PUT.

void lambda_to_rgb ( fastf_t  lambda,
fastf_t  irrad,
fastf_t rgb 
)

Given a wavelength in nm of light, return its rgb approximation.

Taken from Wyszecki, Guenter; Stiles, WS; "Color Science: Concepts and Methods, Quantitative Data and Formulae, " John Wiley and Sons, 1982, pp. 615, table taken from pp. 806-7.

They, in turn, took the data from Vos, J J, Colorimetric and photometric properties of a 2 degree fundamental observer, "Color Res. & Appl. 3", 125 (1978).

Table row: wavelength, x_bar(lambda), y_bar(lambda), z_bar(lambda).

Definition at line 1941 of file sh_toyota.c.

References bu_bomb(), bu_log(), and NCOLOR.

Referenced by toyota_render().

Here is the call graph for this function:

void spectral_dist_table ( fastf_t  lambda,
fastf_t e_mean,
fastf_t v1,
fastf_t v2 
)

Do a table lookup to get data on spectral irradiance of daylight. Table taken from Judd, D B; MacAdam, D L; Wyszecki, G J; Journal for Optical Science of America, Vol. 54, 1964, "Spectral Distribution of Typical Daylight as a Function of Correlated Color Temperature, " pp. 1031-40.

Definition at line 1514 of file sh_toyota.c.

References bu_bomb().

Referenced by skylight_spectral_dist().

Here is the call graph for this function:

fastf_t atmos_irradiance ( fastf_t  lambda)

Table of solar irradiance values taken from WMO - No. 590, "Commission for Instruments and Methods of Observation", Abridged Final Report of the Eighth Session, Mexico City, 19-30 October 1981, pp. 71-5.

Return the solar spectral irradiance through the atmosphere for a given wavelength of light. Units: W/m^2

Definition at line 394 of file sh_toyota.c.

References bu_bomb(), and NSIRRAD.

Referenced by sun_radiance().

Here is the call graph for this function:

fastf_t air_mass ( fastf_t  air_gamma)

Return the relative optical air mass as a function of solar altitude. See Kasten, Fritz "Archiv fuer Meterologie Geophysik und Bioklimateorie, Ser. B", Vol. 14, p. 14, 1966, A New Table and Approximation Formula for the Relative Optical Air Mass.

Unitless (ratio).

Definition at line 284 of file sh_toyota.c.

References bu_log().

Referenced by sun_radiance().

Here is the call graph for this function:

fastf_t background_light ( fastf_t  lambda,
struct toyota_specific ts,
fastf_t Refl,
fastf_t Sun,
fastf_t  t_vl,
struct shadework *  swp 
)

Calculate radiance of background light. For a given wavelength, non-zero reflectance values for a range of incident light angles determine the solid angle of contributing background light.

Units: W/m^2/nm/sr

Definition at line 2103 of file sh_toyota.c.

References bn_vec_ortho(), bu_bomb(), M_PI, MIKE_TOL, pdv_3line(), pl_color(), rdebug, RDEBUG_RAYPLOT, toyota_specific::refl, toyota_specific::refl_lines, reflectance(), skylight_spectral_dist(), SPREAD, VSETALL, toyota_specific::weather, and toyota_specific::Zenith.

Referenced by toyota_render().

Here is the call graph for this function:

fastf_t clear_sky_lum ( fastf_t  lz,
fastf_t Sky_elmt,
fastf_t Sun,
fastf_t Zenith 
)

CIE Standard sky luminance function. Sky free from clouds. Luminance units: cd/m^2

Taken from "Continuous Tone Representation of Three-Dimensional Objects Illuminated by Sky Light" in "Computer Graphics, Volume 20, Number 4, August 1986, pp. 127-8."

Definition at line 356 of file sh_toyota.c.

Referenced by skylight_spectral_dist().

fastf_t fresnel_refl ( fastf_t  cos_eps,
fastf_t  n1,
fastf_t  n2 
)

Return reflectance of a material with only regular (specular) reflectance using Fresnel's equations. For materials other than glass, it is better to measure the specular reflectance since usually it will not follow Fresnel's formula.

Note: This works only for unpolarized light. For polarized skylight, the formula must be extended.

SHOULD CONTACT TOYOTA TO UNDERSTAND WHAT THEY DID.

Definition at line 1737 of file sh_toyota.c.

References toyota_specific::refl.

Referenced by toyota_render().

fastf_t homogenous_sky_lum ( fastf_t Sky_elmt,
fastf_t Sun,
fastf_t  t_vl 
)

Intermediate homogeneous sky light luminance function. Sky in which weather homogeneously changes between clear and overcast skies without clouds scattered in the sky. Luminance units: cd/m^2

DON'T KNOW HOW TO DO THIS YET!!! SENT LETTER TO CIE & TOYOTA JULY 7, 1992

Definition at line 339 of file sh_toyota.c.

Referenced by skylight_spectral_dist().

fastf_t sun_radiance ( fastf_t  lambda,
fastf_t  alpha,
fastf_t  beta,
fastf_t  sun_alt,
fastf_t  sun_sang 
)

Calculate spectral radiance of sun on ground. Units: W/m^2/nm/sr.

Definition at line 1694 of file sh_toyota.c.

References air_mass(), atmos_irradiance(), ozone_absorption(), and toyota_specific::sun_sang.

Referenced by toyota_render().

Here is the call graph for this function:

fastf_t absorp_coeff ( fastf_t  lambda,
char *  material 
)

For each type of material which has had its absorption coefficient measured, linear interpolation between data points is used to return the absorption coefficient for a given wavelength.

Data files are 2 column ascii: wavelength (nm), absorption coefficient (1/m).

Definition at line 1781 of file sh_toyota.c.

References bu_bomb(), bu_strlcpy, and MIKE_TOL.

Referenced by toyota_render().

Here is the call graph for this function:

fastf_t overcast_sky_lum ( fastf_t  lz,
fastf_t Zenith,
fastf_t Sky_elmt 
)

CIE Standard sky luminance function. Sky covered with clouds so thick that the sun cannot be seen. Luminance units: cd/m^2

Taken from "Continuous Tone Representation of Three-Dimensional Objects Illuminated by Sky Light" in "Computer Graphics, Volume 20, Number 4, August 1986, pp. 127-8."

Definition at line 322 of file sh_toyota.c.

Referenced by skylight_spectral_dist().

fastf_t ozone_absorption ( fastf_t  lambda)

Definition at line 1431 of file sh_toyota.c.

References bu_bomb(), and NABSORP.

Referenced by sun_radiance().

Here is the call graph for this function:

fastf_t skylight_spectral_dist ( fastf_t  lambda,
fastf_t Zenith,
fastf_t Sky_elmt,
fastf_t Sun,
int  weather,
fastf_t  t_vl 
)

Return sky light spectral distribution for a sky element. Because to date there is no decisive research on the spectral distribution of sky light, the CIE synthesized daylight expression is used. See Judd, D B; MacAdam, D L; Wyszecki, G J; Journal for Optical Science of America, Vol. 54, 1964, p. 1031.

Units: W/m^2/nm/sr

Definition at line 1603 of file sh_toyota.c.

References bu_log(), CLEAR_SKY, clear_sky_lum(), homogenous_sky_lum(), MEDIUM_SKY, OVERCAST_SKY, overcast_sky_lum(), spectral_dist_table(), and zenith_luminance().

Referenced by background_light(), and toyota_render().

Here is the call graph for this function:

fastf_t zenith_luminance ( fastf_t  sun_alt,
fastf_t  t_vl 
)

Return sky luminance at its zenith.

DON'T KNOW HOW TO DO THIS YET!!! SENT LETTER TO CIE & TOYOTA JULY 7, 1992

Luminance units: cd/m^2

Definition at line 304 of file sh_toyota.c.

Referenced by skylight_spectral_dist().

fastf_t reflectance ( fastf_t  lambda,
fastf_t  alpha,
fastf_t refl,
int  lines 
)

For each type of material which has had its spectral reflectance measured, linear interpolation between data points is used to return the reflectance factor for a given wavelength and a given angle of light incidence.

Data files are 3 column ascii: wavelength, angle, reflectance.

Definition at line 1843 of file sh_toyota.c.

References OSL::Strings::alpha, toyota_specific::beta, and out.

Referenced by background_light(), and toyota_render().

Variable Documentation

struct bu_structparse toyota_parse[]
Initial value:
= {
{"%f", 1, "alpha", CL_O(alpha), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%f", 1, "beta", CL_O(beta), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%d", 1, "weather", CL_O(weather), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%f", 1, "sun_sang", CL_O(sun_sang), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%f", 1, "index_refrac", CL_O(index_refrac), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%f", 1, "atmos_trans", CL_O(atmos_trans), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%f", 3, "Zenith", CL_O(Zenith), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%s", 1, "material", CL_O(material), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"%d", 1, "glass", CL_O(glass), BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
{"", 0, (char *)0, 0, BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
}
#define BU_STRUCTPARSE_FUNC_NULL
Definition: parse.h:153
ustring alpha
#define CL_O(m)
Definition: sh_toyota.c:73

Definition at line 75 of file sh_toyota.c.

struct mfuncs toyota_mfuncs[]
Initial value:
= {
{MF_MAGIC, "toyota", 0, MFI_NORMAL|MFI_LIGHT, 0, toyota_setup, toyota_render, toyota_print, toyota_free },
{MF_MAGIC, "tmirror", 0, MFI_NORMAL|MFI_LIGHT, 0, tmirror_setup, toyota_render, toyota_print, toyota_free },
{MF_MAGIC, "tglass", 0, MFI_NORMAL|MFI_LIGHT, 0, tglass_setup, toyota_render, toyota_print, toyota_free },
{0, (char *)0, 0, 0, 0, 0, 0, 0, 0 }
}
HIDDEN void toyota_print(register struct region *rp, void *dp)
Definition: sh_toyota.c:261
HIDDEN int toyota_render(register struct application *ap, const struct partition *pp, struct shadework *swp, void *dp)
Definition: sh_toyota.c:2239
HIDDEN int tmirror_setup(register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
Definition: sh_toyota.c:223
#define MF_MAGIC
Definition: magic.h:205
HIDDEN int tglass_setup(register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
Definition: sh_toyota.c:242
HIDDEN void toyota_free(void *cp)
Definition: sh_toyota.c:268
HIDDEN int toyota_setup(register struct region *rp, struct bu_vls *matparm, void **dpp, const struct mfuncs *mfp, struct rt_i *rtip)
Definition: sh_toyota.c:136

Definition at line 112 of file sh_toyota.c.

Referenced by optical_shader_init().