mirror of
https://github.com/godotengine/godot.git
synced 2025-10-19 16:03:29 +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:
commit
12aa435bbb
3 changed files with 27 additions and 16 deletions
|
@ -1499,6 +1499,9 @@ void RasterizerSceneGLES3::_setup_environment(const RenderDataGLES3 *p_render_da
|
|||
// 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;
|
||||
|
||||
// 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_near = p_render_data->z_near;
|
||||
|
||||
|
@ -3363,6 +3366,10 @@ void RasterizerSceneGLES3::_render_list_template(RenderListParameters *p_params,
|
|||
} else {
|
||||
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 {
|
||||
// Only base pass uses the radiance map.
|
||||
|
|
|
@ -401,7 +401,7 @@ private:
|
|||
float ambient_light_color_energy[4];
|
||||
|
||||
float ambient_color_sky_mix;
|
||||
uint32_t pad2;
|
||||
uint32_t directional_shadow_count;
|
||||
float emissive_exposure_normalization;
|
||||
uint32_t use_ambient_light = 0;
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ DISABLE_LIGHT_SPOT = false
|
|||
DISABLE_REFLECTION_PROBE = true
|
||||
DISABLE_FOG = false
|
||||
USE_DEPTH_FOG = false
|
||||
USE_SUN_SCATTER = false
|
||||
USE_RADIANCE_MAP = true
|
||||
USE_LIGHTMAP = false
|
||||
USE_SH_LIGHTMAP = false
|
||||
|
@ -188,7 +189,7 @@ struct SceneData {
|
|||
mediump vec4 ambient_light_color_energy;
|
||||
|
||||
mediump float ambient_color_sky_mix;
|
||||
float pad2;
|
||||
uint directional_shadow_count;
|
||||
float emissive_exposure_normalization;
|
||||
bool use_ambient_light;
|
||||
|
||||
|
@ -1130,7 +1131,7 @@ struct SceneData {
|
|||
mediump vec4 ambient_light_color_energy;
|
||||
|
||||
mediump float ambient_color_sky_mix;
|
||||
float pad2;
|
||||
uint directional_shadow_count;
|
||||
float emissive_exposure_normalization;
|
||||
bool use_ambient_light;
|
||||
|
||||
|
@ -1205,7 +1206,7 @@ in vec3 additive_specular_light_interp;
|
|||
#endif // USE_VERTEX_LIGHTING
|
||||
|
||||
// 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 {
|
||||
mediump vec3 direction;
|
||||
|
@ -1227,7 +1228,7 @@ layout(std140) uniform DirectionalLights { // ubo:7
|
|||
uniform highp sampler2DShadow directional_shadow_atlas; // texunit:-3
|
||||
#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.
|
||||
#if !defined(DISABLE_LIGHT_OMNI) || !defined(DISABLE_LIGHT_SPOT) || defined(ADDITIVE_OMNI) || defined(ADDITIVE_SPOT)
|
||||
|
@ -1770,8 +1771,7 @@ vec4 fog_process(vec3 vertex) {
|
|||
*/
|
||||
#endif
|
||||
|
||||
#ifndef DISABLE_LIGHT_DIRECTIONAL
|
||||
if (scene_data_block.data.fog_sun_scatter > 0.001) {
|
||||
#ifdef USE_SUN_SCATTER
|
||||
vec4 sun_scatter = vec4(0.0);
|
||||
float sun_total = 0.0;
|
||||
vec3 view = normalize(vertex);
|
||||
|
@ -1780,8 +1780,12 @@ vec4 fog_process(vec3 vertex) {
|
|||
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;
|
||||
}
|
||||
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 // !DISABLE_LIGHT_DIRECTIONAL
|
||||
#endif // USE_SUN_SCATTER
|
||||
|
||||
float fog_amount = 0.0;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue