diff options
author | LaG1924 <lag1924@gmail.com> | 2021-12-11 16:44:40 +0100 |
---|---|---|
committer | LaG1924 <lag1924@gmail.com> | 2021-12-11 16:44:40 +0100 |
commit | be808181b2c84358b232e4a32d1a6dd9dd6659ed (patch) | |
tree | 5a0089532532a52fc307d836e2b1e90eced06779 /cwd/assets/altcraft/shaders/frag/ssao.fs | |
parent | Removed unnecessary framebuffers copying (diff) | |
download | AltCraft-be808181b2c84358b232e4a32d1a6dd9dd6659ed.tar AltCraft-be808181b2c84358b232e4a32d1a6dd9dd6659ed.tar.gz AltCraft-be808181b2c84358b232e4a32d1a6dd9dd6659ed.tar.bz2 AltCraft-be808181b2c84358b232e4a32d1a6dd9dd6659ed.tar.lz AltCraft-be808181b2c84358b232e4a32d1a6dd9dd6659ed.tar.xz AltCraft-be808181b2c84358b232e4a32d1a6dd9dd6659ed.tar.zst AltCraft-be808181b2c84358b232e4a32d1a6dd9dd6659ed.zip |
Diffstat (limited to 'cwd/assets/altcraft/shaders/frag/ssao.fs')
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/ssao.fs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/cwd/assets/altcraft/shaders/frag/ssao.fs b/cwd/assets/altcraft/shaders/frag/ssao.fs index 4ed93fd..662852f 100644 --- a/cwd/assets/altcraft/shaders/frag/ssao.fs +++ b/cwd/assets/altcraft/shaders/frag/ssao.fs @@ -5,7 +5,7 @@ out vec4 fragColor; in vec2 uv; uniform sampler2D normal; -uniform sampler2D worldPos; +uniform sampler2D depthStencil; uniform sampler2D ssaoNoise; uniform int ssaoSamples; @@ -13,6 +13,7 @@ uniform int ssaoSamples; layout (std140) uniform Globals { mat4 projView; mat4 proj; + mat4 invProj; mat4 view; uvec2 viewportSize; vec4 ssaoKernels[64]; @@ -26,9 +27,14 @@ const int kernelSize = 64; const float radius = 0.5f; const float bias = 0.025f; +vec3 RecoverViewWorldPos(vec2 screenPos, float depth) { + vec4 viewPos = invProj * vec4(screenPos * 2.0 - 1.0, depth * 2.0 - 1.0, 1.0); + return viewPos.xyz / viewPos.w; +} + void main() { vec3 normal = texture(normal, uv).xyz; - vec3 fragPos = texture(worldPos, uv).xyz; + vec3 fragPos = RecoverViewWorldPos(uv, texture(depthStencil, uv).r); vec2 noiseUv = uv * viewportSize / noiseScale; vec3 randomVec = texture(ssaoNoise, noiseUv).xyz; @@ -49,7 +55,7 @@ void main() { offset.xyz /= offset.w; offset.xyz = offset.xyz * 0.5 + 0.5; - float sampleDepth = texture(worldPos, offset.xy).z; + float sampleDepth = RecoverViewWorldPos(offset.xy, texture(depthStencil, offset.xy).r).z; float rangeCheck = smoothstep(0.0, 1.0, radius / abs(fragPos.z - sampleDepth)); occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck; } |