diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2017-05-20 17:47:33 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2017-05-20 17:58:07 +0300 |
commit | 67b9a5b3d64e0c52b4da844d41c749c924da742d (patch) | |
tree | 4812bd45517566178286e95aa96d5d7f011b22fc /source | |
parent | d9d65a06d3db36efd5848cf7ae3e08c72c2c296b (diff) |
Eevee: Initial implementation of exponential shadowmaps
Also fixes the rendering of depth.
Diffstat (limited to 'source')
6 files changed, 38 insertions, 20 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_lights.c b/source/blender/draw/engines/eevee/eevee_lights.c index 7adc2696746..afc60dc3a44 100644 --- a/source/blender/draw/engines/eevee/eevee_lights.c +++ b/source/blender/draw/engines/eevee/eevee_lights.c @@ -200,7 +200,7 @@ void EEVEE_lights_cache_finish(EEVEE_StorageList *stl, EEVEE_TextureList *txl, E if (!txl->shadow_depth_cube_target) { /* Render Cubemap */ txl->shadow_depth_cube_target = DRW_texture_create_cube(512, DRW_TEX_DEPTH_24, 0, NULL); - txl->shadow_color_cube_target = DRW_texture_create_cube(512, DRW_TEX_R_32, 0, NULL); + txl->shadow_color_cube_target = DRW_texture_create_cube(512, DRW_TEX_R_32, DRW_TEX_FILTER, NULL); if (fbl->shadow_cube_fb) { DRW_framebuffer_texture_attach(fbl->shadow_cube_fb, txl->shadow_depth_cube_target, 0, 0); DRW_framebuffer_texture_attach(fbl->shadow_cube_fb, txl->shadow_color_cube_target, 0, 0); @@ -235,7 +235,7 @@ void EEVEE_lights_cache_finish(EEVEE_StorageList *stl, EEVEE_TextureList *txl, E DRWFboTexture tex_cube_target[2] = { {&txl->shadow_depth_cube_target, DRW_TEX_DEPTH_24, 0}, - {&txl->shadow_color_cube_target, DRW_TEX_R_32, 0}}; + {&txl->shadow_color_cube_target, DRW_TEX_R_32, DRW_TEX_FILTER}}; DRW_framebuffer_init(&fbl->shadow_cube_target_fb, &draw_engine_eevee_type, 512, 512, tex_cube_target, 2); DRWFboTexture tex_cube = {&txl->shadow_depth_cube_pool, DRW_TEX_R_32, DRW_TEX_FILTER}; diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl index 1c124c06744..ecfc670c0d6 100644 --- a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl @@ -129,7 +129,7 @@ float light_visibility(LightData ld, ShadingData sd) vis *= texture(shadowCascades, vec4(shpos.xy, shid * float(MAX_CASCADE_NUM) + cascade, shpos.z)); } - else { + else if (ld.l_shadowid >= 0.0) { /* Shadow Cube */ float shid = ld.l_shadowid; ShadowCubeData scd = shadows_cube_data[int(shid)]; @@ -150,9 +150,12 @@ float light_visibility(LightData ld, ShadingData sd) vec2 uvs = cubevec.xy * (0.5) + 0.5; uvs = uvs * (1.0 - 2.0 * texelSize) + 1.0 * texelSize; /* edge filtering fix */ - float sh_test = step(0, texture(shadowCubes, vec3(uvs, shid)).r - dist); + float z = texture(shadowCubes, vec3(uvs, shid)).r; + + float esm_test = min(1.0, exp(-5.0 * dist) * z); + float sh_test = step(0, z - dist); - vis *= sh_test; + vis *= esm_test; } return vis; diff --git a/source/blender/draw/engines/eevee/shaders/shadow_frag.glsl b/source/blender/draw/engines/eevee/shaders/shadow_frag.glsl index 0b7356d812b..7a8b06e3430 100644 --- a/source/blender/draw/engines/eevee/shaders/shadow_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/shadow_frag.glsl @@ -1,8 +1,15 @@ -in float linearDistance; +layout(std140) uniform shadow_render_block { + mat4 ShadowMatrix[6]; + vec4 lampPosition; + int layer; +}; + +in vec3 worldPosition; out vec4 FragColor; void main() { - FragColor = vec4(linearDistance, 0.0, 0.0, 1.0); + float dist = distance(lampPosition.xyz, worldPosition.xyz); + FragColor = vec4(exp(5.0 * dist), 0.0, 0.0, 1.0); } diff --git a/source/blender/draw/engines/eevee/shaders/shadow_geom.glsl b/source/blender/draw/engines/eevee/shaders/shadow_geom.glsl index c4738de2f31..4bd2999787b 100644 --- a/source/blender/draw/engines/eevee/shaders/shadow_geom.glsl +++ b/source/blender/draw/engines/eevee/shaders/shadow_geom.glsl @@ -9,10 +9,9 @@ layout(triangles) in; layout(triangle_strip, max_vertices=3) out; in vec4 vPos[]; -in float lDist[]; flat in int face[]; -out float linearDistance; +out vec3 worldPosition; void main() { int f = face[0]; @@ -20,7 +19,7 @@ void main() { for (int v = 0; v < 3; ++v) { gl_Position = ShadowMatrix[f] * vPos[v]; - linearDistance = lDist[v]; + worldPosition = vPos[v].xyz; EmitVertex(); } diff --git a/source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl b/source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl index 08453080ed2..67bee97fade 100644 --- a/source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl @@ -17,6 +17,13 @@ vec3 octahedral_to_cubemap_proj(vec2 co) return v; } +void make_orthonormal_basis(vec3 N, out vec3 T, out vec3 B) +{ + vec3 UpVector = abs(N.z) < 0.99999 ? vec3(0.0,0.0,1.0) : vec3(1.0,0.0,0.0); + T = normalize( cross(UpVector, N) ); + B = cross(N, T); +} + void main() { const vec2 texelSize = vec2(1.0 / 512.0); @@ -42,6 +49,16 @@ void main() { /* get cubemap vector */ vec3 cubevec = octahedral_to_cubemap_proj(uvs.xy); - /* get cubemap vector */ - FragColor = texture(shadowCube, cubevec).rrrr; + vec3 T, B; + make_orthonormal_basis(cubevec, T, B); + + vec2 offsetvec = texelSize.xy * vec2(-1.0, 1.0); /* Totally arbitrary */ + + /* get cubemap shadow value */ + FragColor = texture(shadowCube, cubevec + offsetvec.x * T + offsetvec.x * B).rrrr; + FragColor += texture(shadowCube, cubevec + offsetvec.x * T + offsetvec.y * B).rrrr; + FragColor += texture(shadowCube, cubevec + offsetvec.y * T + offsetvec.x * B).rrrr; + FragColor += texture(shadowCube, cubevec + offsetvec.y * T + offsetvec.y * B).rrrr; + + FragColor /= 4.0; }
\ No newline at end of file diff --git a/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl b/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl index 323cf4d2a99..288098ba771 100644 --- a/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl +++ b/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl @@ -1,21 +1,13 @@ -layout(std140) uniform shadow_render_block { - mat4 ShadowMatrix[6]; - vec4 lampPosition; - int layer; -}; - uniform mat4 ShadowModelMatrix; in vec3 pos; out vec4 vPos; -out float lDist; flat out int face; void main() { vPos = ShadowModelMatrix * vec4(pos, 1.0); - lDist = distance(lampPosition.xyz, vPos.xyz); face = gl_InstanceID; }
\ No newline at end of file |