diff options
author | RandomCatDude <kud.stanislav@gmail.com> | 2023-02-25 16:28:06 +0500 |
---|---|---|
committer | Yuri Sizov <yuris@humnom.net> | 2023-03-27 16:47:46 +0200 |
commit | 149f16b2fa2259fff81e9222f0bfcf9da7d0af32 (patch) | |
tree | cc018e2e57960732ae4a98352f202b91fd709678 /servers | |
parent | bf8ab62ca3a197ebfa568b24b7c479c68bcf29af (diff) |
fix spotlight shadows in volumetric fog
(cherry picked from commit 59c31004f8c6feed601f2bfeedb86959563a4ef0)
Diffstat (limited to 'servers')
-rw-r--r-- | servers/rendering/renderer_rd/shaders/environment/volumetric_fog_process.glsl | 19 |
1 files changed, 5 insertions, 14 deletions
diff --git a/servers/rendering/renderer_rd/shaders/environment/volumetric_fog_process.glsl b/servers/rendering/renderer_rd/shaders/environment/volumetric_fog_process.glsl index 28507e6c12..f961249dce 100644 --- a/servers/rendering/renderer_rd/shaders/environment/volumetric_fog_process.glsl +++ b/servers/rendering/renderer_rd/shaders/environment/volumetric_fog_process.glsl @@ -585,23 +585,14 @@ void main() { if (spot_lights.data[light_index].shadow_opacity > 0.001) { //has shadow vec4 uv_rect = spot_lights.data[light_index].atlas_rect; - vec2 flip_offset = spot_lights.data[light_index].direction.xy; - vec3 local_vert = (spot_lights.data[light_index].shadow_matrix * vec4(view_pos, 1.0)).xyz; + vec4 v = vec4(view_pos, 1.0); - float shadow_len = length(local_vert); //need to remember shadow len from here - vec3 shadow_sample = normalize(local_vert); - - if (shadow_sample.z >= 0.0) { - uv_rect.xy += flip_offset; - } - - shadow_sample.z = 1.0 + abs(shadow_sample.z); - vec3 pos = vec3(shadow_sample.xy / shadow_sample.z, shadow_len - spot_lights.data[light_index].shadow_bias); - pos.z *= spot_lights.data[light_index].inv_radius; + vec4 splane = (spot_lights.data[light_index].shadow_matrix * v); + splane.z -= spot_lights.data[light_index].shadow_bias / (d * spot_lights.data[light_index].inv_radius); + splane /= splane.w; - pos.xy = pos.xy * 0.5 + 0.5; - pos.xy = uv_rect.xy + pos.xy * uv_rect.zw; + vec3 pos = vec3(splane.xy * spot_lights.data[light_index].atlas_rect.zw + spot_lights.data[light_index].atlas_rect.xy, splane.z); float depth = texture(sampler2D(shadow_atlas, linear_sampler), pos.xy).r; |