commit 37f174aa62fbc3ccf91199d27ec261d215782e32 parent 345d8d422bdd1ffe02ea7cb69c3f6f21679be295 Author: Michael Savage <mikejsavage@gmail.com> Date: Sun May 7 23:43:15 +0300 PCF Diffstat:
shadow_map.cc | | | 17 | ++++++++++++++--- |
diff --git a/shadow_map.cc b/shadow_map.cc @@ -129,15 +129,26 @@ static const char * shadow_frag_src = GLSL( vec3 light_ndc = smooth_light_position.xyz / smooth_light_position.w; vec3 light_norm = light_ndc * 0.5 + 0.5; - float shadow_depth = texture( shadowmap, light_norm.xy ).r; - float point_depth = light_norm.z; float bias2 = max( bias * ( 1.0 + dot( lightdir, frag_normal ) ), bias / 100 ); - float shadow = point_depth - bias2 <= shadow_depth ? 1.0 : 0.1; + float shadow = 0.1; + if( light_norm.z > 1.0 ) { shadow = 1.0; } + else { + for( int x = -1; x <= 1; x++ ) { + for( int y = -1; y <= 1; y++ ) { + vec2 offset = vec2( x * 1.0 / 1024.0, y * 1.0 / 1024.0 ); + float shadow_depth = texture( shadowmap, light_norm.xy + offset ).r; + if( light_norm.z - bias2 <= shadow_depth ) { + shadow += 0.1; + } + } + } + } screen_colour = vec4( frag_colour * light_colour * lambert * shadow, 1.0 ); + // screen_colour = screen_colour * 0 + vec4( ( frag_normal + 1.0 ) / 2.0, 1 ); } );