@@ -605,8 +605,9 @@ template std::pair<Ray::Ref::fvec4, Ray::Ref::fvec4> Ray::Ref::IntegrateScatteri
605605
606606Ray::Ref::fvec4 Ray::Ref::IntegrateScattering (const atmosphere_params_t ¶ms, fvec4 ray_start, const fvec4 &ray_dir,
607607 float ray_length, const fvec4 &light_dir, const float light_angle,
608- const fvec4 &light_color, Span<const float > transmittance_lut,
609- Span<const float > multiscatter_lut, uint32_t rand_hash) {
608+ const fvec4 &light_color, const fvec4 &light_color_point,
609+ Span<const float > transmittance_lut, Span<const float > multiscatter_lut,
610+ uint32_t rand_hash) {
610611 const fvec2 atm_intersection = AtmosphereIntersection (params, ray_start, ray_dir);
611612 ray_length = fminf (ray_length, atm_intersection.get <1 >());
612613 if (atm_intersection.get <0 >() > 0 ) {
@@ -651,7 +652,7 @@ Ray::Ref::fvec4 Ray::Ref::IntegrateScattering(const atmosphere_params_t ¶ms,
651652 rand_hash = hash (rand_hash);
652653
653654 total_radiance += IntegrateScatteringMain (params, ray_start, ray_dir, pre_atmosphere_ray_length, light_dir,
654- moon_dir, light_color , transmittance_lut, multiscatter_lut,
655+ moon_dir, light_color_point , transmittance_lut, multiscatter_lut,
655656 rand_offset, SKY_PRE_ATMOSPHERE_SAMPLE_COUNT, total_transmittance)
656657 .first ;
657658 }
@@ -754,7 +755,7 @@ Ray::Ref::fvec4 Ray::Ref::IntegrateScattering(const atmosphere_params_t ¶ms,
754755 float cloud_blend = linstep (SKY_CLOUDS_HORIZON_CUTOFF + 0 .25f , SKY_CLOUDS_HORIZON_CUTOFF, ray_dir.get <1 >());
755756 cloud_blend = 1 .0f - powf (cloud_blend, 5 .0f );
756757
757- total_radiance += cloud_blend * clouds * light_color ;
758+ total_radiance += cloud_blend * clouds * light_color_point ;
758759 total_transmittance = mix (transmittance_before, total_transmittance, cloud_blend);
759760 }
760761 }
@@ -808,11 +809,11 @@ Ray::Ref::fvec4 Ray::Ref::IntegrateScattering(const atmosphere_params_t ¶ms,
808809 }
809810
810811 if (light_dir.get <1 >() > -0 .025f ) {
811- total_radiance +=
812- total_transmittance * GetLightEnergy ( 0 . 002f , dC, phase_w) * light_transmittance * dC * light_color ;
812+ total_radiance += total_transmittance * GetLightEnergy ( 0 . 002f , dC, phase_w) * light_transmittance * dC *
813+ light_color_point ;
813814 } else if (params.moon_radius > 0 .0f ) {
814815 total_radiance += SKY_MOON_SUN_RELATION * total_transmittance * GetLightEnergy (0 .002f , dC, moon_phase_w) *
815- moon_transmittance * dC * light_color ;
816+ moon_transmittance * dC * light_color_point ;
816817 }
817818 total_transmittance *= expf (-dC * 0 .002f * 1000 .0f );
818819 }
@@ -833,7 +834,7 @@ Ray::Ref::fvec4 Ray::Ref::IntegrateScattering(const atmosphere_params_t ¶ms,
833834 rand_hash = hash (rand_hash);
834835
835836 total_radiance += IntegrateScatteringMain (params, main_ray_start, ray_dir, main_ray_length, light_dir, moon_dir,
836- light_color , transmittance_lut, multiscatter_lut, rand_offset,
837+ light_color_point , transmittance_lut, multiscatter_lut, rand_offset,
837838 SKY_MAIN_ATMOSPHERE_SAMPLE_COUNT, total_transmittance)
838839 .first ;
839840 }
@@ -842,14 +843,10 @@ Ray::Ref::fvec4 Ray::Ref::IntegrateScattering(const atmosphere_params_t ¶ms,
842843 // Sun disk (bake directional light into the texture)
843844 //
844845 if (light_angle > 0 .0f && planet_intersection.get <0 >() < 0 .0f && light_brightness > 0 .0f ) {
845- const float cos_theta = cosf (light_angle);
846+ const float cos_theta = cosf (fmaxf ( light_angle, SKY_SUN_MIN_ANGLE) );
846847 const float smooth_blend_val = fminf (SKY_SUN_BLEND_VAL, 1 .0f - cos_theta);
847- fvec4 sun_disk =
848+ const fvec4 sun_disk =
848849 total_transmittance * smoothstep (cos_theta - smooth_blend_val, cos_theta + smooth_blend_val, costh);
849- // 'de-multiply' by disk area (to get original brightness)
850- const float radius = tanf (light_angle);
851- sun_disk /= (PI * radius * radius);
852-
853850 total_radiance += sun_disk * light_color;
854851 }
855852
@@ -959,22 +956,24 @@ void Ray::Ref::ShadeSky(const pass_settings_t &ps, const float limit, Span<const
959956 const light_t &l = sc.lights [li_index];
960957
961958 const fvec4 light_dir = {l.dir .dir [0 ], l.dir .dir [1 ], l.dir .dir [2 ], 0 .0f };
962- fvec4 light_col = {l.col [0 ], l.col [1 ], l.col [2 ], 0 .0f };
959+ const fvec4 light_col = {l.col [0 ], l.col [1 ], l.col [2 ], 0 .0f };
960+ fvec4 light_col_point = light_col;
963961 if (l.dir .tan_angle != 0 .0f ) {
964962 const float radius = l.dir .tan_angle ;
965- light_col *= (PI * radius * radius);
963+ light_col_point *= (PI * radius * radius);
966964 }
967965
968- color += IntegrateScattering (
969- sc.env .atmosphere , fvec4{0 .0f , sc.env .atmosphere .viewpoint_height , 0 .0f , 0 .0f }, I, MAX_DIST,
970- light_dir, l.dir .angle , light_col, sc.sky_transmittance_lut , sc.sky_multiscatter_lut , rand_hash);
966+ color +=
967+ IntegrateScattering (sc.env .atmosphere , fvec4{0 .0f , sc.env .atmosphere .viewpoint_height , 0 .0f , 0 .0f },
968+ I, MAX_DIST, light_dir, l.dir .angle , light_col, light_col_point,
969+ sc.sky_transmittance_lut , sc.sky_multiscatter_lut , rand_hash);
971970 }
972971 } else if (sc.env .atmosphere .stars_brightness > 0 .0f ) {
973972 // Use fake lightsource (to light up the moon)
974973 const fvec4 light_dir = {0 .0f , -1 .0f , 0 .0f , 0 .0f }, light_col = {144809 .859f , 129443 .617f , 127098 .89f , 0 .0f };
975974
976975 color += IntegrateScattering (sc.env .atmosphere , fvec4{0 .0f , sc.env .atmosphere .viewpoint_height , 0 .0f , 0 .0f },
977- I, MAX_DIST, light_dir, 0 .0f , light_col, sc.sky_transmittance_lut ,
976+ I, MAX_DIST, light_dir, 0 .0f , light_col, light_col, sc.sky_transmittance_lut ,
978977 sc.sky_multiscatter_lut , rand_hash);
979978 }
980979
0 commit comments