medfall

A super great game engine
Log | Files | Refs

commit 849d34a0f7892d76e4680d442f394093fa52f6e6
parent 10f29dec0c134eb431ec6370ab945c38ae05f58c
Author: Michael Savage <mikejsavage@gmail.com>
Date:   Mon Aug 28 17:47:15 +0100

Much better shadow map biasing

Diffstat:
shaders/shadowed_vertex_colours.glsl | 13+++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/shaders/shadowed_vertex_colours.glsl b/shaders/shadowed_vertex_colours.glsl @@ -50,14 +50,23 @@ void main() { in VSOut v2f; out vec4 screen_colour; +// http://the-witness.net/news/2013/09/shadow-mapping-summary-part-1/ +vec2 get_shadow_offsets( vec3 N, vec3 L ) { + float cos_alpha = dot_sat( N, L ); + float offset_scale_N = sqrt( 1.0 - cos_alpha * cos_alpha ); + float offset_scale_L = offset_scale_N / cos_alpha; + return vec2( offset_scale_N, min( 5.0, offset_scale_L ) ); +} + void main() { vec3 light_colour = vec3( 400.0, 400.0, 400.0 ); - vec3 lightdir = normalize( v2f.position - light_pos ); + vec3 lightdir = normalize( light_pos - v2f.position ); vec3 to_camera = normalize( camera_pos - v2f.position ); vec3 light_ndc = v2f.light_space_position.xyz / v2f.light_space_position.w; vec3 light_norm = light_ndc * 0.5 + 0.5; - float bias2 = max( bias * ( 1.0 + dot( lightdir, v2f.normal ) ), bias / 100 ); + vec2 offsets = get_shadow_offsets( v2f.normal, lightdir ); + float bias = 0.00002 + 0.00001 * offsets.x + 0.00005 * offsets.y; float shadow = 0;