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 | |
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 '')
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/entity.fs | 8 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/face.fs | 7 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/fwd_face.fs | 1 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/fwd_sky.fs | 1 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/light.fs | 13 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/sky.fs | 8 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/frag/ssao.fs | 12 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/entity.vs | 4 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/face.vs | 4 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/light.vs | 22 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/quad.vs | 1 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/rml.vs | 1 | ||||
-rw-r--r-- | cwd/assets/altcraft/shaders/vert/sky.vs | 1 |
13 files changed, 33 insertions, 50 deletions
diff --git a/cwd/assets/altcraft/shaders/frag/entity.fs b/cwd/assets/altcraft/shaders/frag/entity.fs index 31e1a7c..813a9af 100644 --- a/cwd/assets/altcraft/shaders/frag/entity.fs +++ b/cwd/assets/altcraft/shaders/frag/entity.fs @@ -1,19 +1,15 @@ #version 330 core -in vec4 entityWorldPos; - layout (location = 0) out vec4 color; layout (location = 1) out vec4 normal; -layout (location = 2) out vec4 worldPos; -layout (location = 3) out vec4 addColor; -layout (location = 4) out vec4 light; +layout (location = 2) out vec4 addColor; +layout (location = 3) out vec4 light; uniform vec3 entityColor; void main() { color = vec4(entityColor, 1.0f); normal = vec4(0.0f, 0.0f, 0.0f, 1.0f); - worldPos = entityWorldPos; addColor = vec4(1.0f); light = vec4(1.0f, 1.0f, 0.0f, 1.0f); } diff --git a/cwd/assets/altcraft/shaders/frag/face.fs b/cwd/assets/altcraft/shaders/frag/face.fs index 65b7d15..ebda304 100644 --- a/cwd/assets/altcraft/shaders/frag/face.fs +++ b/cwd/assets/altcraft/shaders/frag/face.fs @@ -1,6 +1,5 @@ #version 330 core -in vec4 faceWorldPos; in vec3 faceTextureUv; in vec3 faceAddColor; in vec3 faceNormal; @@ -8,9 +7,8 @@ in vec2 faceLight; layout (location = 0) out vec4 color; layout (location = 1) out vec4 normal; -layout (location = 2) out vec4 worldPos; -layout (location = 3) out vec4 addColor; -layout (location = 4) out vec4 light; +layout (location = 2) out vec4 addColor; +layout (location = 3) out vec4 light; uniform sampler2DArray textureAtlas; @@ -21,7 +19,6 @@ void main() { color = vec4(col.rgb, 1.0f); normal = vec4(faceNormal, 1.0f); - worldPos = faceWorldPos; addColor = vec4(faceAddColor, 1.0f); light = vec4(faceLight / 15.0f, 0.0f, 1.0f); } diff --git a/cwd/assets/altcraft/shaders/frag/fwd_face.fs b/cwd/assets/altcraft/shaders/frag/fwd_face.fs index deb8341..12deab8 100644 --- a/cwd/assets/altcraft/shaders/frag/fwd_face.fs +++ b/cwd/assets/altcraft/shaders/frag/fwd_face.fs @@ -13,6 +13,7 @@ uniform sampler2DArray textureAtlas; layout (std140) uniform Globals { mat4 projView; mat4 proj; + mat4 invProj; mat4 view; uvec2 viewportSize; vec4 ssaoKernels[64]; diff --git a/cwd/assets/altcraft/shaders/frag/fwd_sky.fs b/cwd/assets/altcraft/shaders/frag/fwd_sky.fs index b6185fd..9f278b2 100644 --- a/cwd/assets/altcraft/shaders/frag/fwd_sky.fs +++ b/cwd/assets/altcraft/shaders/frag/fwd_sky.fs @@ -7,6 +7,7 @@ out vec4 fragColor; layout (std140) uniform Globals { mat4 projView; mat4 proj; + mat4 invProj; mat4 view; uvec2 viewportSize; vec4 ssaoKernels[64]; diff --git a/cwd/assets/altcraft/shaders/frag/light.fs b/cwd/assets/altcraft/shaders/frag/light.fs index c7e7254..3876388 100644 --- a/cwd/assets/altcraft/shaders/frag/light.fs +++ b/cwd/assets/altcraft/shaders/frag/light.fs @@ -7,7 +7,6 @@ in vec2 uv; uniform sampler2D depthStencil; uniform sampler2D color; uniform sampler2D normal; -uniform sampler2D worldPos; uniform sampler2D addColor; uniform sampler2D light; uniform sampler2D ssao; @@ -18,6 +17,7 @@ uniform bool applySsao; layout (std140) uniform Globals { mat4 projView; mat4 proj; + mat4 invProj; mat4 view; uvec2 viewportSize; vec4 ssaoKernels[64]; @@ -26,16 +26,21 @@ layout (std140) uniform Globals { float gamma; }; +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() { vec4 c = texture(color, uv); vec4 n = texture(normal, uv); n += 1.0f; n /= 2.0f; - vec4 wp = texture(worldPos, uv); vec4 ac = texture(addColor, uv); vec4 l = texture(light, uv); - float d = (1.0f - texture(depthStencil, uv).r) * 16.0f; + float depth = texture(depthStencil, uv).r; + float d = (1.0f - depth) * 16.0f; vec4 s = texture(ssao, uv); float faceLight = l.r; @@ -62,7 +67,7 @@ void main() { fragColor = n; break; case 3: - fragColor = wp; + fragColor = vec4(RecoverViewWorldPos(uv, depth), 1.0f); break; case 4: fragColor = ac; diff --git a/cwd/assets/altcraft/shaders/frag/sky.fs b/cwd/assets/altcraft/shaders/frag/sky.fs index dc97440..f3830b8 100644 --- a/cwd/assets/altcraft/shaders/frag/sky.fs +++ b/cwd/assets/altcraft/shaders/frag/sky.fs @@ -4,13 +4,13 @@ in vec3 facePos; layout (location = 0) out vec4 color; layout (location = 1) out vec4 normal; -layout (location = 2) out vec4 worldPos; -layout (location = 3) out vec4 addColor; -layout (location = 4) out vec4 light; +layout (location = 2) out vec4 addColor; +layout (location = 3) out vec4 light; layout (std140) uniform Globals { mat4 projView; mat4 proj; + mat4 invProj; mat4 view; uvec2 viewportSize; vec4 ssaoKernels[64]; @@ -65,7 +65,7 @@ void main() { color += vec4(Sun().rgb, 1.0f); color += vec4(Moon().rgb, 1.0f); normal = vec4(0.0f, 0.0f, 0.0f, 1.0f); - worldPos = vec4(0.0f, 0.0f, 0.0f, 1.0f); addColor = vec4(1.0f); light = vec4(1.0f, 1.0f, 0.0f, 1.0f); + gl_FragDepth = 1.0f; } 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; } diff --git a/cwd/assets/altcraft/shaders/vert/entity.vs b/cwd/assets/altcraft/shaders/vert/entity.vs index f90fbc1..8cc7f69 100644 --- a/cwd/assets/altcraft/shaders/vert/entity.vs +++ b/cwd/assets/altcraft/shaders/vert/entity.vs @@ -2,13 +2,12 @@ in vec3 pos; -out vec4 entityWorldPos; - uniform mat4 model; layout (std140) uniform Globals { mat4 projView; mat4 proj; + mat4 invProj; mat4 view; uvec2 viewportSize; vec4 ssaoKernels[64]; @@ -19,5 +18,4 @@ layout (std140) uniform Globals { void main() { gl_Position = projView * model * vec4(pos, 1); - entityWorldPos = view * model * vec4(pos, 1.0f); } diff --git a/cwd/assets/altcraft/shaders/vert/face.vs b/cwd/assets/altcraft/shaders/vert/face.vs index a85b2c6..3e6adf7 100644 --- a/cwd/assets/altcraft/shaders/vert/face.vs +++ b/cwd/assets/altcraft/shaders/vert/face.vs @@ -8,7 +8,6 @@ in float animation; in vec3 color; in vec2 light; -out vec4 faceWorldPos; out vec3 faceTextureUv; out vec3 faceNormal; out vec3 faceAddColor; @@ -17,6 +16,7 @@ out vec2 faceLight; layout (std140) uniform Globals { mat4 projView; mat4 proj; + mat4 invProj; mat4 view; uvec2 viewportSize; vec4 ssaoKernels[64]; @@ -28,8 +28,6 @@ layout (std140) uniform Globals { void main() { gl_Position = projView * vec4(pos[gl_VertexID], 1.0f); - faceWorldPos = view * vec4(pos[gl_VertexID], 1.0f); - faceTextureUv = vec3(uv[gl_VertexID], uvLayer); faceTextureUv.y -= (uv[2].y - uv[0].y) * trunc(mod(globalTime * 4.0f, animation)); diff --git a/cwd/assets/altcraft/shaders/vert/light.vs b/cwd/assets/altcraft/shaders/vert/light.vs deleted file mode 100644 index 118ea5b..0000000 --- a/cwd/assets/altcraft/shaders/vert/light.vs +++ /dev/null @@ -1,22 +0,0 @@ -#version 330 core - -in vec2 pos; -in vec2 uvPos; - -out vec2 uv; - -layout (std140) uniform Globals { - mat4 projView; - mat4 proj; - mat4 view; - uvec2 viewportSize; - vec4 ssaoKernels[64]; - float globalTime; - float dayTime; - float gamma; -}; - -void main() { - gl_Position = vec4(pos.x, pos.y, 0.0, 1.0); - uv = uvPos; -} diff --git a/cwd/assets/altcraft/shaders/vert/quad.vs b/cwd/assets/altcraft/shaders/vert/quad.vs index 118ea5b..9add76d 100644 --- a/cwd/assets/altcraft/shaders/vert/quad.vs +++ b/cwd/assets/altcraft/shaders/vert/quad.vs @@ -8,6 +8,7 @@ out vec2 uv; layout (std140) uniform Globals { mat4 projView; mat4 proj; + mat4 invProj; mat4 view; uvec2 viewportSize; vec4 ssaoKernels[64]; diff --git a/cwd/assets/altcraft/shaders/vert/rml.vs b/cwd/assets/altcraft/shaders/vert/rml.vs index c61a4a0..897f49d 100644 --- a/cwd/assets/altcraft/shaders/vert/rml.vs +++ b/cwd/assets/altcraft/shaders/vert/rml.vs @@ -12,6 +12,7 @@ uniform vec2 translation; layout (std140) uniform Globals { mat4 projView; mat4 proj; + mat4 invProj; mat4 view; uvec2 viewportSize; vec4 ssaoKernels[64]; diff --git a/cwd/assets/altcraft/shaders/vert/sky.vs b/cwd/assets/altcraft/shaders/vert/sky.vs index 7043584..c618852 100644 --- a/cwd/assets/altcraft/shaders/vert/sky.vs +++ b/cwd/assets/altcraft/shaders/vert/sky.vs @@ -9,6 +9,7 @@ uniform mat4 model; layout (std140) uniform Globals { mat4 projView; mat4 proj; + mat4 invProj; mat4 view; uvec2 viewportSize; vec4 ssaoKernels[64]; |