37
38
* compute v1 = v2 op v3
38
39
* v1, v2 and v3 are vectors contains 3 float
40
#define vec3opv(v1, v2, op, v3) \
41
v1[0] = (v2[0] op v3[0]); \
42
v1[1] = (v2[1] op v3[1]);\
43
v1[2] = (v2[2] op v3[2]);
41
#define VEC3OPV(v1, v2, op, v3) \
43
v1[0] = (v2[0] op v3[0]); \
44
v1[1] = (v2[1] op v3[1]); \
45
v1[2] = (v2[2] op v3[2]); \
46
49
* compute v1 = v2 op f1
47
50
* v1, v2 are vectors contains 3 float
48
51
* and f1 is a float
50
#define vec3opf(v1, v2, op, f1)\
51
v1[0] = (v2[0] op (f1));\
52
v1[1] = (v2[1] op (f1));\
53
v1[2] = (v2[2] op (f1));
53
#define VEC3OPF(v1, v2, op, f1) \
55
v1[0] = (v2[0] op (f1)); \
56
v1[1] = (v2[1] op (f1)); \
57
v1[2] = (v2[2] op (f1)); \
56
61
* compute v1 = f1 op v2
57
62
* v1, v2 are vectors contains 3 float
58
63
* and f1 is a float
60
#define fopvec3(v1, f1, op, v2)\
61
v1[0] = ((f1) op v2[0]);\
62
v1[1] = ((f1) op v2[1]);\
63
v1[2] = ((f1) op v2[2]);
65
#define FOPVEC3(v1, f1, op, v2) \
67
v1[0] = ((f1) op v2[0]); \
68
v1[1] = ((f1) op v2[1]); \
69
v1[2] = ((f1) op v2[2]); \
130
137
* this function compute some sun,sky parameters according to input parameters and also initiate some other sun, sky parameters
132
* sunSky, is a structure that contains informtion about sun, sky and atmosphere, in this function, most of its values initiated
139
* sunSky, is a structure that contains information about sun, sky and atmosphere, in this function, most of its values initiated
133
140
* turb, is atmosphere turbidity
134
141
* toSun, contains sun direction
135
142
* horizon_brighness, controls the brightness of the horizon colors
269
276
y = PerezFunction(sunsky, sunsky->perez_y, theta, gamma, sunsky->zenith_y);
270
277
Y = 6.666666667e-5f * nfade * hfade * PerezFunction(sunsky, sunsky->perez_Y, theta, gamma, sunsky->zenith_Y);
272
if(sunsky->sky_exposure!=0.0f)
279
if (sunsky->sky_exposure!=0.0f)
273
280
Y = 1.0 - exp(Y*sunsky->sky_exposure);
404
411
fTemp = pi*pi*(n*n-1)*(n*n-1)*(6+3*pn)/(6-7*pn)/N;
405
412
fBeta = 8*fTemp*pi/3;
407
vec3opf(sunSky->atm_BetaRay, vLambda4, *, fBeta);
414
VEC3OPF(sunSky->atm_BetaRay, vLambda4, *, fBeta);
408
415
fBetaDash = fTemp/2;
409
vec3opf(sunSky->atm_BetaDashRay, vLambda4,*, fBetaDash);
416
VEC3OPF(sunSky->atm_BetaDashRay, vLambda4,*, fBetaDash);
412
419
// Mie scattering constants.
413
420
fTemp2 = 0.434f*c*(2*pi)*(2*pi)*0.5f;
414
vec3opf(sunSky->atm_BetaDashMie, vLambda2, *, fTemp2);
421
VEC3OPF(sunSky->atm_BetaDashMie, vLambda2, *, fTemp2);
416
423
fTemp3 = 0.434f*c*pi*(2*pi)*(2*pi);
418
vec3opv(vBetaMieTemp, K, *, fLambda);
419
vec3opf(sunSky->atm_BetaMie, vBetaMieTemp,*, fTemp3);
425
VEC3OPV(vBetaMieTemp, K, *, fLambda);
426
VEC3OPF(sunSky->atm_BetaMie, vBetaMieTemp,*, fTemp3);
455
462
costheta = dot_v3v3(view, sunDirection); // cos(theta)
456
463
Phase_1 = 1 + (costheta * costheta); // Phase_1
458
vec3opf(sunSky->atm_BetaRay, sunSky->atm_BetaRay, *, sunSky->atm_BetaRayMultiplier);
459
vec3opf(sunSky->atm_BetaMie, sunSky->atm_BetaMie, *, sunSky->atm_BetaMieMultiplier);
460
vec3opv(sunSky->atm_BetaRM, sunSky->atm_BetaRay, +, sunSky->atm_BetaMie);
465
VEC3OPF(sunSky->atm_BetaRay, sunSky->atm_BetaRay, *, sunSky->atm_BetaRayMultiplier);
466
VEC3OPF(sunSky->atm_BetaMie, sunSky->atm_BetaMie, *, sunSky->atm_BetaMieMultiplier);
467
VEC3OPV(sunSky->atm_BetaRM, sunSky->atm_BetaRay, +, sunSky->atm_BetaMie);
462
469
//e^(-(beta_1 + beta_2) * s) = E1
463
vec3opf(E1, sunSky->atm_BetaRM, *, -s/(float)M_LN2);
470
VEC3OPF(E1, sunSky->atm_BetaRM, *, -s/(float)M_LN2);
464
471
E1[0] = exp(E1[0]);
465
472
E1[1] = exp(E1[1]);
466
473
E1[2] = exp(E1[2]);
472
479
fTemp = fTemp * sqrtf(fTemp);
473
480
Phase_2 = (1 - sunSky->atm_HGg * sunSky->atm_HGg)/fTemp;
475
vec3opf(vTemp1, sunSky->atm_BetaDashRay, *, Phase_1);
476
vec3opf(vTemp2, sunSky->atm_BetaDashMie, *, Phase_2);
478
vec3opv(vTemp1, vTemp1, +, vTemp2);
479
fopvec3(vTemp2, 1.0f, -, E1);
480
vec3opv(vTemp1, vTemp1, *, vTemp2);
482
fopvec3(vTemp2, 1.0f, / , sunSky->atm_BetaRM);
484
vec3opv(I, vTemp1, *, vTemp2);
482
VEC3OPF(vTemp1, sunSky->atm_BetaDashRay, *, Phase_1);
483
VEC3OPF(vTemp2, sunSky->atm_BetaDashMie, *, Phase_2);
485
VEC3OPV(vTemp1, vTemp1, +, vTemp2);
486
FOPVEC3(vTemp2, 1.0f, -, E1);
487
VEC3OPV(vTemp1, vTemp1, *, vTemp2);
489
FOPVEC3(vTemp2, 1.0f, / , sunSky->atm_BetaRM);
491
VEC3OPV(I, vTemp1, *, vTemp2);
486
vec3opf(I, I, *, sunSky->atm_InscatteringMultiplier);
487
vec3opf(E, E, *, sunSky->atm_ExtinctionMultiplier);
493
VEC3OPF(I, I, *, sunSky->atm_InscatteringMultiplier);
494
VEC3OPF(E, E, *, sunSky->atm_ExtinctionMultiplier);
489
496
//scale to color sun
490
497
ComputeAttenuatedSunlight(sunSky->theta, sunSky->turbidity, sunColor);
491
vec3opv(E, E, *, sunColor);
493
vec3opf(I, I, *, sunSky->atm_SunIntensity);
495
vec3opv(rgb, rgb, *, E);
496
vec3opv(rgb, rgb, +, I);
498
VEC3OPV(E, E, *, sunColor);
500
VEC3OPF(I, I, *, sunSky->atm_SunIntensity);
502
VEC3OPV(rgb, rgb, *, E);
503
VEC3OPV(rgb, rgb, +, I);