30 1.45756829855592995315f, 1.56596305559738380175f, 1.65148449067670455293f,
31 1.71496242737209314555f, 1.75797983805020541226f, 1.78256407885924539336f,
32 1.79095108475838560302f, 1.78541550133410664714f, 1.76815554864306845317f,
33 1.74122069647250410362f, 1.70647127164943679389f, 1.66556087452739887134f,
34 1.61993437242451854274f, 1.57083597368892080581f, 1.51932335059305478886f,
35 1.46628494965214395407f, 1.41245852740172450623f, 1.35844961970384092709f,
36 1.30474913844739281998f, 1.25174963272610817455f, 1.19975998755420620867f};
39 0.00005424820087636473f, 0.00004418549866505454f, 0.00003635151910165377f,
40 0.00003017929012024763f, 0.00002526320226989157f, 0.00002130859310621843f,
41 0.00001809838025320633f, 0.00001547057129129042f, 0.00001330284977336850f,
42 0.00001150184784075764f, 0.00000999557429990163f, 0.00000872799973630707f,
43 0.00000765513700977967f, 0.00000674217203751443f, 0.00000596134125832052f,
44 0.00000529034598065810f, 0.00000471115687557433f, 0.00000420910481110487f,
45 0.00000377218381260133f, 0.00000339051255477280f, 0.00000305591531679811f};
48 0.00000000325126849861f, 0.00000000585395365047f, 0.00000001977191155085f,
49 0.00000007309568762914f, 0.00000020084561514287f, 0.00000040383958096161f,
50 0.00000063551335912363f, 0.00000096707041180970f, 0.00000154797400424410f,
51 0.00000209038647223331f, 0.00000246128056164565f, 0.00000273551299461512f,
52 0.00000215125863128643f, 0.00000159051840791988f, 0.00000112356197979857f,
53 0.00000073527551487574f, 0.00000046450130357806f, 0.00000033096079921048f,
54 0.00000022512612292678f, 0.00000014879129266490f, 0.00000016828623364192f};
56static const float CMF_XYZ[][3] = {{0.00136800000f, 0.00003900000f, 0.00645000100f},
57 {0.01431000000f, 0.00039600000f, 0.06785001000f},
58 {0.13438000000f, 0.00400000000f, 0.64560000000f},
59 {0.34828000000f, 0.02300000000f, 1.74706000000f},
60 {0.29080000000f, 0.06000000000f, 1.66920000000f},
61 {0.09564000000f, 0.13902000000f, 0.81295010000f},
62 {0.00490000000f, 0.32300000000f, 0.27200000000f},
63 {0.06327000000f, 0.71000000000f, 0.07824999000f},
64 {0.29040000000f, 0.95400000000f, 0.02030000000f},
65 {0.59450000000f, 0.99500000000f, 0.00390000000f},
66 {0.91630000000f, 0.87000000000f, 0.00165000100f},
67 {1.06220000000f, 0.63100000000f, 0.00080000000f},
68 {0.85444990000f, 0.38100000000f, 0.00019000000f},
69 {0.44790000000f, 0.17500000000f, 0.00002000000f},
70 {0.16490000000f, 0.06100000000f, 0.00000000000f},
71 {0.04677000000f, 0.01700000000f, 0.00000000000f},
72 {0.01135916000f, 0.00410200000f, 0.00000000000f},
73 {0.00289932700f, 0.00104700000f, 0.00000000000f},
74 {0.00069007860f, 0.00024920000f, 0.00000000000f},
75 {0.00016615050f, 0.00006000000f, 0.00000000000f},
76 {0.00004150994f, 0.00001499000f, 0.00000000000f}};
212 float aerosol_density,
218 float ray_length =
distance(ray_origin, ray_end);
222 float segment_length = ray_length /
STEPS;
223 float3 segment = segment_length * ray_dir;
233 r_spectrum[wl] = 0.0f;
237 float mu =
dot(ray_dir, sun_dir);
242 float3 P = ray_origin + 0.5f * segment;
252 optical_depth += segment_length * density;
257 float3 total_optical_depth = optical_depth + light_optical_depth;
281 r_spectrum[wl] += attenuation *
reduce_add(phase_function * scattering_density) *
298 float aerosol_density,
302 altitude =
clamp(altitude, 1.0f, 59999.0f);
304 const int half_width = width / 2;
305 const int half_height = height / 2;
308 const float longitude_step =
M_2PI_F / width;
309 const int rows_per_task = std::max(1024 / width, 1);
315 float latitude =
M_PI_2_F *
sqr(
float(
y) / half_height - 1.0f);
316 float *pixel_row = pixels + (
y * width * stride);
318 for (
int x = 0;
x < half_width;
x++) {
319 float longitude = longitude_step *
x -
M_PI_F;
323 dir, sun_dir, cam_pos, air_density, aerosol_density, ozone_density, spectrum);
327 int pos_x =
x * stride;
328 pixel_row[pos_x] = xyz.
x;
329 pixel_row[pos_x + 1] = xyz.
y;
330 pixel_row[pos_x + 2] = xyz.
z;
332 int mirror_x = (width -
x - 1) * stride;
333 pixel_row[mirror_x] = xyz.
x;
334 pixel_row[mirror_x + 1] = xyz.
y;
335 pixel_row[mirror_x + 2] = xyz.
z;
341 for (
int y = 0;
y < half_height;
y++) {
343 float latitude =
M_PI_2_F *
sqr(
float(
y) / half_height - 1.0f);
347 fade = 1.0f - dir.
z * 2.5f;
350 float *pixel_row = pixels + (
y * width * stride);
351 float *horizon_row = pixels + (half_height * width * stride);
353 for (
int x = 0, offset = 0;
x < width;
x++, offset += stride) {
354 pixel_row[offset + 0] = horizon_row[offset + 0] *
fade;
355 pixel_row[offset + 1] = horizon_row[offset + 1] *
fade;
356 pixel_row[offset + 2] = horizon_row[offset + 2] *
fade;
382 float angular_diameter,
385 float aerosol_density,
386 float r_pixel_bottom[3],
387 float r_pixel_top[3])
390 altitude =
clamp(altitude, 1.0f, 59999.0f);
391 float half_angular = angular_diameter / 2.0f;
392 float solid_angle =
M_2PI_F * (1.0f -
cosf(half_angular));
394 float bottom = sun_elevation - half_angular;
395 float top = sun_elevation + half_angular;
396 float elevation_bottom, elevation_top;
397 float3 pix_bottom, pix_top, sun_dir;
401 elevation_bottom = (bottom > 0.0f) ? bottom : 0.0f;
402 elevation_top = (
top > 0.0f) ?
top : 0.0f;
403 if (elevation_top > 0.0f) {
405 sun_radiation(sun_dir, altitude, air_density, aerosol_density, solid_angle, spectrum);
408 sun_radiation(sun_dir, altitude, air_density, aerosol_density, solid_angle, spectrum);
417 r_pixel_bottom[0] = pix_bottom.
x;
418 r_pixel_bottom[1] = pix_bottom.
y;
419 r_pixel_bottom[2] = pix_bottom.
z;
420 r_pixel_top[0] = pix_top.
x;
421 r_pixel_top[1] = pix_top.
y;
422 r_pixel_top[2] = pix_top.
z;
void SKY_single_scattering_precompute_texture(float *pixels, int stride, int width, int height, float sun_elevation, float altitude, float air_density, float aerosol_density, float ozone_density)