diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2021-03-14 01:11:53 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2021-03-14 01:11:53 +0300 |
commit | e30315ba9591b4571399908850863a725d0f1a1a (patch) | |
tree | 834474a1befcc0091deead2dd1a5736052da7211 | |
parent | 75fc6e3b2b3f3db9f734415ff457b723664834f9 (diff) |
EEVEE: RenderPass: Fix Ambient Occlusion pass
The shader was not using the horizon texture and was trying to
trace the AO again.
Also the depth reconstruction was off because now using the maxzBuffer.
-rw-r--r-- | source/blender/draw/engines/eevee/eevee_shaders.c | 5 | ||||
-rw-r--r-- | source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl | 20 |
2 files changed, 14 insertions, 11 deletions
diff --git a/source/blender/draw/engines/eevee/eevee_shaders.c b/source/blender/draw/engines/eevee/eevee_shaders.c index 06763c34766..d5e529ea2fd 100644 --- a/source/blender/draw/engines/eevee/eevee_shaders.c +++ b/source/blender/draw/engines/eevee/eevee_shaders.c @@ -688,7 +688,10 @@ GPUShader *EEVEE_shaders_effect_ambient_occlusion_debug_sh_get(void) { if (e_data.gtao_debug_sh == NULL) { e_data.gtao_debug_sh = DRW_shader_create_fullscreen_with_shaderlib( - datatoc_effect_gtao_frag_glsl, e_data.lib, "#define DEBUG_AO\n"); + datatoc_effect_gtao_frag_glsl, + e_data.lib, + "#define DEBUG_AO\n" + "#define ENABLE_DEFERED_AO"); } return e_data.gtao_debug_sh; } diff --git a/source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl index 932632abd75..70f1e9f1e66 100644 --- a/source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl +++ b/source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl @@ -46,17 +46,11 @@ vec3 view_position_derivative_from_depth(vec2 uvs, vec2 ofs, vec3 vP, float dept } /* TODO(fclem) port to a common place for other effects to use. */ -bool reconstruct_view_position_and_normal_from_depth(vec2 texel, out vec3 vP, out vec3 vNg) +bool reconstruct_view_position_and_normal_from_depth(vec2 uvs, out vec3 vP, out vec3 vNg) { - vec2 texel_size = 1.0 / vec2(textureSize(maxzBuffer, 0).xy); - vec2 uvs = texel * texel_size; + vec2 texel_size = vec2(abs(dFdx(uvs.x)), abs(dFdy(uvs.y))); float depth_center = textureLod(maxzBuffer, uvs, 0.0).r; - /* Background case. */ - if (depth_center == 1.0) { - return false; - } - vP = get_view_space_from_depth(uvs, depth_center); vec3 dPdx = view_position_derivative_from_depth(uvs, texel_size * vec2(1, 0), vP, depth_center); @@ -64,6 +58,11 @@ bool reconstruct_view_position_and_normal_from_depth(vec2 texel, out vec3 vP, ou vNg = safe_normalize(cross(dPdx, dPdy)); + /* Background case. */ + if (depth_center == 1.0) { + return false; + } + return true; } @@ -72,8 +71,9 @@ bool reconstruct_view_position_and_normal_from_depth(vec2 texel, out vec3 vP, ou void main() { vec3 vP, vNg; + vec2 uvs = uvcoordsvar.xy; - if (!reconstruct_view_position_and_normal_from_depth(gl_FragCoord.xy, vP, vNg)) { + if (!reconstruct_view_position_and_normal_from_depth(uvs * hizUvScale.xy, vP, vNg)) { /* Handle Background case. Prevent artifact due to uncleared Horizon Render Target. */ FragColor = vec4(0.0); } @@ -81,7 +81,7 @@ void main() vec3 P = transform_point(ViewMatrixInverse, vP); vec3 V = cameraVec(P); vec3 vV = viewCameraVec(vP); - vec3 vN = normal_decode(texture(normalBuffer, uvcoordsvar.xy).rg, vV); + vec3 vN = normal_decode(texture(normalBuffer, uvs).rg, vV); vec3 N = transform_direction(ViewMatrixInverse, vN); vec3 Ng = transform_direction(ViewMatrixInverse, vNg); |