@@ -15,6 +15,7 @@ DISABLE_LIGHT_SPOT = false
1515DISABLE_REFLECTION_PROBE = true
1616DISABLE_FOG = false
1717USE_DEPTH_FOG = false
18+ USE_SUN_SCATTER = false
1819USE_RADIANCE_MAP = true
1920USE_LIGHTMAP = false
2021USE_SH_LIGHTMAP = false
@@ -188,7 +189,7 @@ struct SceneData {
188189 mediump vec4 ambient_light_color_energy;
189190
190191 mediump float ambient_color_sky_mix;
191- float pad2 ;
192+ uint directional_shadow_count ;
192193 float emissive_exposure_normalization;
193194 bool use_ambient_light;
194195
@@ -1130,7 +1131,7 @@ struct SceneData {
11301131 mediump vec4 ambient_light_color_energy;
11311132
11321133 mediump float ambient_color_sky_mix;
1133- float pad2 ;
1134+ uint directional_shadow_count ;
11341135 float emissive_exposure_normalization;
11351136 bool use_ambient_light;
11361137
@@ -1205,7 +1206,7 @@ in vec3 additive_specular_light_interp;
12051206#endif // USE_VERTEX_LIGHTING
12061207
12071208// Directional light data.
1208- #if ! defined(DISABLE_LIGHT_DIRECTIONAL) || (! defined(ADDITIVE_OMNI) && ! defined(ADDITIVE_SPOT))
1209+ #if ! defined(DISABLE_LIGHT_DIRECTIONAL) || (! defined(ADDITIVE_OMNI) && ! defined(ADDITIVE_SPOT)) || defined(USE_SUN_SCATTER)
12091210
12101211struct DirectionalLightData {
12111212 mediump vec3 direction;
@@ -1227,7 +1228,7 @@ layout(std140) uniform DirectionalLights { // ubo:7
12271228uniform highp sampler2DShadow directional_shadow_atlas; // texunit:-3
12281229#endif // defined(USE_ADDITIVE_LIGHTING) && (!defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT))
12291230
1230- #endif // !DISABLE_LIGHT_DIRECTIONAL
1231+ #endif // !DISABLE_LIGHT_DIRECTIONAL || USE_SUN_SCATTER
12311232
12321233// Omni and spot light data.
12331234#if ! defined(DISABLE_LIGHT_OMNI) || ! defined(DISABLE_LIGHT_SPOT) || defined(ADDITIVE_OMNI) || defined(ADDITIVE_SPOT)
@@ -1770,18 +1771,21 @@ vec4 fog_process(vec3 vertex) {
17701771 */
17711772#endif
17721773
1773- #ifndef DISABLE_LIGHT_DIRECTIONAL
1774- if (scene_data_block.data.fog_sun_scatter > 0.001 ) {
1775- vec4 sun_scatter = vec4 (0.0 );
1776- float sun_total = 0.0 ;
1777- vec3 view = normalize (vertex);
1778- for (uint i = uint (0 ); i < scene_data_block.data.directional_light_count; i++ ) {
1779- vec3 light_color = directional_lights[i].color * directional_lights[i].energy;
1780- float light_amount = pow (max (dot (view, directional_lights[i].direction), 0.0 ), 8.0 );
1781- fog_color += light_color * light_amount * scene_data_block.data.fog_sun_scatter;
1782- }
1774+ #ifdef USE_SUN_SCATTER
1775+ vec4 sun_scatter = vec4 (0.0 );
1776+ float sun_total = 0.0 ;
1777+ vec3 view = normalize (vertex);
1778+ for (uint i = uint (0 ); i < scene_data_block.data.directional_light_count; i++ ) {
1779+ vec3 light_color = directional_lights[i].color * directional_lights[i].energy;
1780+ float light_amount = pow (max (dot (view, directional_lights[i].direction), 0.0 ), 8.0 );
1781+ fog_color += light_color * light_amount * scene_data_block.data.fog_sun_scatter;
17831782 }
1784- #endif // !DISABLE_LIGHT_DIRECTIONAL
1783+ for (uint i = uint (MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS) - uint (scene_data_block.data.directional_shadow_count); i < uint (MAX_DIRECTIONAL_LIGHT_DATA_STRUCTS); i++ ) {
1784+ vec3 light_color = directional_lights[i].color * directional_lights[i].energy;
1785+ float light_amount = pow (max (dot (view, directional_lights[i].direction), 0.0 ), 8.0 );
1786+ fog_color += light_color * light_amount * scene_data_block.data.fog_sun_scatter;
1787+ }
1788+ #endif // USE_SUN_SCATTER
17851789
17861790 float fog_amount = 0.0 ;
17871791
0 commit comments