diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2018-05-01 18:31:35 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2018-05-01 18:59:40 +0300 |
commit | 1bef7f9318c83523c5f9449eae2c1ad0823ac8dd (patch) | |
tree | 6be526f6abdb3be473ecc998f0f74aeec63acded /source | |
parent | 8c92a027206f781ee929d7b8906a175abf4ed674 (diff) |
Eevee: Contact Shadows: Add slope based bias & fix brightening.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/lamps_lib.glsl | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl b/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl index 2e7c78e287d..6b765b1d263 100644 --- a/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl +++ b/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl @@ -211,15 +211,27 @@ float light_visibility(LightData ld, vec3 W, vec3 ray_dir = L.xyz + T * rand.z + B * rand.w; ray_dir = transform_direction(ViewMatrix, ray_dir); ray_dir = normalize(ray_dir); - vec3 ray_origin = viewPosition + viewNormal * (gl_FrontFacing ? data.sh_contact_offset : -data.sh_contact_offset); - vec3 hit_pos = raycast(-1, ray_origin, ray_dir * trace_distance, data.sh_contact_thickness, rand.x, - 0.75, 0.01, false); + + vec3 ray_ori = viewPosition; + + float bias = 0.5; /* Constant Bias */ + bias += 1.0 - abs(dot(viewNormal, ray_dir)); /* Angle dependant bias */ + bias *= gl_FrontFacing ? data.sh_contact_offset : -data.sh_contact_offset; + + vec3 nor_bias = viewNormal * bias; + ray_ori += nor_bias; + + ray_dir *= trace_distance; + ray_dir -= nor_bias; + + vec3 hit_pos = raycast(-1, ray_ori, ray_dir, data.sh_contact_thickness, rand.x, + 0.1, 0.001, false); if (hit_pos.z > 0.0) { hit_pos = get_view_space_from_depth(hit_pos.xy, hit_pos.z); float hit_dist = distance(viewPosition, hit_pos); float dist_ratio = hit_dist / trace_distance; - return mix(0.0, vis, dist_ratio * dist_ratio * dist_ratio); + return vis * saturate(dist_ratio * dist_ratio * dist_ratio); } } #endif |