You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-04 12:00:25 +00:00
Merge pull request #107740 from Kaleb-Reid/compat-directional-shadow-scatter
Apply sun scatter from lights with shadows in compatibility
This commit is contained in:
@@ -1499,6 +1499,9 @@ void RasterizerSceneGLES3::_setup_environment(const RenderDataGLES3 *p_render_da
|
|||||||
// Only render the lights without shadows in the base pass.
|
// Only render the lights without shadows in the base pass.
|
||||||
scene_state.data.directional_light_count = p_render_data->directional_light_count - p_render_data->directional_shadow_count;
|
scene_state.data.directional_light_count = p_render_data->directional_light_count - p_render_data->directional_shadow_count;
|
||||||
|
|
||||||
|
// Lights with shadows still need to be applied to fog sun scatter.
|
||||||
|
scene_state.data.directional_shadow_count = p_render_data->directional_shadow_count;
|
||||||
|
|
||||||
scene_state.data.z_far = p_render_data->z_far;
|
scene_state.data.z_far = p_render_data->z_far;
|
||||||
scene_state.data.z_near = p_render_data->z_near;
|
scene_state.data.z_near = p_render_data->z_near;
|
||||||
|
|
||||||
@@ -3363,6 +3366,10 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
|
|||||||
} else {
|
} else {
|
||||||
spec_constants |= SceneShaderGLES3::DISABLE_LIGHTMAP;
|
spec_constants |= SceneShaderGLES3::DISABLE_LIGHTMAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (p_render_data->directional_light_count > 0 && is_environment(p_render_data->environment) && environment_get_fog_sun_scatter(p_render_data->environment) > 0.001) {
|
||||||
|
spec_constants |= SceneShaderGLES3::USE_SUN_SCATTER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Only base pass uses the radiance map.
|
// Only base pass uses the radiance map.
|
||||||
|
|||||||
@@ -401,7 +401,7 @@ private:
|
|||||||
float ambient_light_color_energy[4];
|
float ambient_light_color_energy[4];
|
||||||
|
|
||||||
float ambient_color_sky_mix;
|
float ambient_color_sky_mix;
|
||||||
uint32_t pad2;
|
uint32_t directional_shadow_count;
|
||||||
float emissive_exposure_normalization;
|
float emissive_exposure_normalization;
|
||||||
uint32_t use_ambient_light = 0;
|
uint32_t use_ambient_light = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ DISABLE_LIGHT_SPOT = false
|
|||||||
DISABLE_REFLECTION_PROBE = true
|
DISABLE_REFLECTION_PROBE = true
|
||||||
DISABLE_FOG = false
|
DISABLE_FOG = false
|
||||||
USE_DEPTH_FOG = false
|
USE_DEPTH_FOG = false
|
||||||
|
USE_SUN_SCATTER = false
|
||||||
USE_RADIANCE_MAP = true
|
USE_RADIANCE_MAP = true
|
||||||
USE_LIGHTMAP = false
|
USE_LIGHTMAP = false
|
||||||
USE_SH_LIGHTMAP = false
|
USE_SH_LIGHTMAP = false
|
||||||
@@ -188,7 +189,7 @@ struct SceneData {
|
|||||||
mediump vec4 ambient_light_color_energy;
|
mediump vec4 ambient_light_color_energy;
|
||||||
|
|
||||||
mediump float ambient_color_sky_mix;
|
mediump float ambient_color_sky_mix;
|
||||||
float pad2;
|
uint directional_shadow_count;
|
||||||
float emissive_exposure_normalization;
|
float emissive_exposure_normalization;
|
||||||
bool use_ambient_light;
|
bool use_ambient_light;
|
||||||
|
|
||||||
@@ -1130,7 +1131,7 @@ struct SceneData {
|
|||||||
mediump vec4 ambient_light_color_energy;
|
mediump vec4 ambient_light_color_energy;
|
||||||
|
|
||||||
mediump float ambient_color_sky_mix;
|
mediump float ambient_color_sky_mix;
|
||||||
float pad2;
|
uint directional_shadow_count;
|
||||||
float emissive_exposure_normalization;
|
float emissive_exposure_normalization;
|
||||||
bool use_ambient_light;
|
bool use_ambient_light;
|
||||||
|
|
||||||
@@ -1205,7 +1206,7 @@ in vec3 additive_specular_light_interp;
|
|||||||
#endif // USE_VERTEX_LIGHTING
|
#endif // USE_VERTEX_LIGHTING
|
||||||
|
|
||||||
// Directional light data.
|
// Directional light data.
|
||||||
#if !defined(DISABLE_LIGHT_DIRECTIONAL) || (!defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT))
|
#if !defined(DISABLE_LIGHT_DIRECTIONAL) || (!defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT)) || defined(USE_SUN_SCATTER)
|
||||||
|
|
||||||
struct DirectionalLightData {
|
struct DirectionalLightData {
|
||||||
mediump vec3 direction;
|
mediump vec3 direction;
|
||||||
@@ -1227,7 +1228,7 @@ layout(std140) uniform DirectionalLights { // ubo:7
|
|||||||
uniform highp sampler2DShadow directional_shadow_atlas; // texunit:-3
|
uniform highp sampler2DShadow directional_shadow_atlas; // texunit:-3
|
||||||
#endif // defined(USE_ADDITIVE_LIGHTING) && (!defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT))
|
#endif // defined(USE_ADDITIVE_LIGHTING) && (!defined(ADDITIVE_OMNI) && !defined(ADDITIVE_SPOT))
|
||||||
|
|
||||||
#endif // !DISABLE_LIGHT_DIRECTIONAL
|
#endif // !DISABLE_LIGHT_DIRECTIONAL || USE_SUN_SCATTER
|
||||||
|
|
||||||
// Omni and spot light data.
|
// Omni and spot light data.
|
||||||
#if !defined(DISABLE_LIGHT_OMNI) || !defined(DISABLE_LIGHT_SPOT) || defined(ADDITIVE_OMNI) || defined(ADDITIVE_SPOT)
|
#if !defined(DISABLE_LIGHT_OMNI) || !defined(DISABLE_LIGHT_SPOT) || defined(ADDITIVE_OMNI) || defined(ADDITIVE_SPOT)
|
||||||
@@ -1770,18 +1771,21 @@ vec4 fog_process(vec3 vertex) {
|
|||||||
*/
|
*/
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef DISABLE_LIGHT_DIRECTIONAL
|
#ifdef USE_SUN_SCATTER
|
||||||
if (scene_data_block.data.fog_sun_scatter > 0.001) {
|
vec4 sun_scatter = vec4(0.0);
|
||||||
vec4 sun_scatter = vec4(0.0);
|
float sun_total = 0.0;
|
||||||
float sun_total = 0.0;
|
vec3 view = normalize(vertex);
|
||||||
vec3 view = normalize(vertex);
|
for (uint i = uint(0); i < scene_data_block.data.directional_light_count; i++) {
|
||||||
for (uint i = uint(0); i < scene_data_block.data.directional_light_count; i++) {
|
vec3 light_color = directional_lights[i].color * directional_lights[i].energy;
|
||||||
vec3 light_color = directional_lights[i].color * directional_lights[i].energy;
|
float light_amount = pow(max(dot(view, directional_lights[i].direction), 0.0), 8.0);
|
||||||
float light_amount = pow(max(dot(view, directional_lights[i].direction), 0.0), 8.0);
|
fog_color += light_color * light_amount * scene_data_block.data.fog_sun_scatter;
|
||||||
fog_color += light_color * light_amount * scene_data_block.data.fog_sun_scatter;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#endif // !DISABLE_LIGHT_DIRECTIONAL
|
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++) {
|
||||||
|
vec3 light_color = directional_lights[i].color * directional_lights[i].energy;
|
||||||
|
float light_amount = pow(max(dot(view, directional_lights[i].direction), 0.0), 8.0);
|
||||||
|
fog_color += light_color * light_amount * scene_data_block.data.fog_sun_scatter;
|
||||||
|
}
|
||||||
|
#endif // USE_SUN_SCATTER
|
||||||
|
|
||||||
float fog_amount = 0.0;
|
float fog_amount = 0.0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user