From ab23d3910ac081066b42c184c6229aaa397dd46c Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 9 Oct 2021 20:54:27 +0300 Subject: [PATCH] Pass the queried position as an argument to get_shadow_factor --- shaderlib/cooktorrance.glsl | 2 +- shaderlib/phong.glsl | 2 +- shaderlib/shadow.glsl | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/shaderlib/cooktorrance.glsl b/shaderlib/cooktorrance.glsl index 79f88f64..d8e07b29 100644 --- a/shaderlib/cooktorrance.glsl +++ b/shaderlib/cooktorrance.glsl @@ -156,7 +156,7 @@ vec3 cooktorrance_lighting(vec3 normal, vec3 look, vec3 base_color, float metaln if(light_sources[i].type!=0) { IncomingLight incoming = get_incoming_light(i, world_vertex.xyz); - float shadow = get_shadow_factor(i); + float shadow = get_shadow_factor(i, world_vertex); color += cooktorrance_one_light_direct(normal, look, incoming.direction, base_color, metalness, roughness)*incoming.color*shadow; } diff --git a/shaderlib/phong.glsl b/shaderlib/phong.glsl index ed091ce9..32fa43cc 100644 --- a/shaderlib/phong.glsl +++ b/shaderlib/phong.glsl @@ -99,7 +99,7 @@ vec3 phong_lighting(vec3 normal, vec3 look, vec3 surface_diffuse, vec3 surface_s if(light_sources[i].type!=0) { IncomingLight incoming = get_incoming_light(i, world_vertex.xyz); - float shadow = get_shadow_factor(i); + float shadow = get_shadow_factor(i, world_vertex); color += phong_one_light(incoming.direction, normal, look, surface_diffuse, surface_specular, shininess)*incoming.color*shadow; } diff --git a/shaderlib/shadow.glsl b/shaderlib/shadow.glsl index c26a1ca3..52cd7c13 100644 --- a/shaderlib/shadow.glsl +++ b/shaderlib/shadow.glsl @@ -18,14 +18,14 @@ uniform sampler2DShadow shadow_map; layout(constant_id=auto) const bool use_shadow_map = false; #pragma MSP stage(fragment) -virtual float get_shadow_factor(int index) +virtual float get_shadow_factor(int index, vec4 world_pos) { if(use_shadow_map) { if(shadows[index].enabled==0) return 1.0; - vec3 shadow_coord = (shadows[index].shd_world_matrix*world_vertex).xyz; + vec3 shadow_coord = (shadows[index].shd_world_matrix*world_pos).xyz; if(shadow_coord.x<0 || shadow_coord.x>1 || shadow_coord.y<0 || shadow_coord.y>1) return 1.0; -- 2.45.2