summaryrefslogtreecommitdiffstats
path: root/cwd/assets/altcraft/shaders/frag
diff options
context:
space:
mode:
Diffstat (limited to 'cwd/assets/altcraft/shaders/frag')
-rw-r--r--cwd/assets/altcraft/shaders/frag/entity.fs8
-rw-r--r--cwd/assets/altcraft/shaders/frag/face.fs7
-rw-r--r--cwd/assets/altcraft/shaders/frag/fwd_face.fs1
-rw-r--r--cwd/assets/altcraft/shaders/frag/fwd_sky.fs1
-rw-r--r--cwd/assets/altcraft/shaders/frag/light.fs13
-rw-r--r--cwd/assets/altcraft/shaders/frag/sky.fs8
-rw-r--r--cwd/assets/altcraft/shaders/frag/ssao.fs12
7 files changed, 28 insertions, 22 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;
}