]> git.tdb.fi Git - libs/gl.git/commitdiff
Pass the queried position as an argument to get_shadow_factor
authorMikko Rasa <tdb@tdb.fi>
Sat, 9 Oct 2021 17:54:27 +0000 (20:54 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sat, 9 Oct 2021 17:54:27 +0000 (20:54 +0300)
shaderlib/cooktorrance.glsl
shaderlib/phong.glsl
shaderlib/shadow.glsl

index 79f88f6475db747479996e81c73079de8d1106bd..d8e07b292e4e2ecdaa434875ef21f0f7cd1eec72 100644 (file)
@@ -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;
                }
 
index ed091ce9a9374d0646ca900b9ca6210fd4be9dfb..32fa43cc61ef6143343fd893c2d304ee72107229 100644 (file)
@@ -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;
                }
 
index c26a1ca3782039cbb3ba1e6261abeace13c78859..52cd7c13ab767a4cb07b24e11b4be7bb1c898df4 100644 (file)
@@ -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;