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/blur.fs22
-rw-r--r--cwd/assets/altcraft/shaders/frag/copy.fs11
-rw-r--r--cwd/assets/altcraft/shaders/frag/entity.fs10
-rw-r--r--cwd/assets/altcraft/shaders/frag/face.fs21
-rw-r--r--cwd/assets/altcraft/shaders/frag/fbo.fs11
-rw-r--r--cwd/assets/altcraft/shaders/frag/fwd_entity.fs11
-rw-r--r--cwd/assets/altcraft/shaders/frag/fwd_face.fs39
-rw-r--r--cwd/assets/altcraft/shaders/frag/fwd_sky.fs66
-rw-r--r--cwd/assets/altcraft/shaders/frag/light.fs83
-rw-r--r--cwd/assets/altcraft/shaders/frag/rml.fs8
-rw-r--r--cwd/assets/altcraft/shaders/frag/rmltex.fs12
-rw-r--r--cwd/assets/altcraft/shaders/frag/sky.fs37
-rw-r--r--cwd/assets/altcraft/shaders/frag/ssao.fs68
13 files changed, 355 insertions, 44 deletions
diff --git a/cwd/assets/altcraft/shaders/frag/blur.fs b/cwd/assets/altcraft/shaders/frag/blur.fs
new file mode 100644
index 0000000..89d4498
--- /dev/null
+++ b/cwd/assets/altcraft/shaders/frag/blur.fs
@@ -0,0 +1,22 @@
+#version 330 core
+
+out vec4 fragColor;
+
+in vec2 uv;
+
+uniform sampler2D blurInput;
+uniform int blurScale;
+
+void main() {
+ vec2 texelSize = 1.0f / vec2(textureSize(blurInput, 0));
+ vec4 result = vec4(0.0f);
+ for (int x = -blurScale; x < blurScale; x++)
+ {
+ for (int y = -blurScale; y < blurScale; y++)
+ {
+ vec2 offset = vec2(float(x), float(y)) * texelSize;
+ result += texture(blurInput, uv + offset);
+ }
+ }
+ fragColor = result / pow(blurScale * 2.0f, 2);
+}
diff --git a/cwd/assets/altcraft/shaders/frag/copy.fs b/cwd/assets/altcraft/shaders/frag/copy.fs
new file mode 100644
index 0000000..a5a7a2b
--- /dev/null
+++ b/cwd/assets/altcraft/shaders/frag/copy.fs
@@ -0,0 +1,11 @@
+#version 330 core
+
+in vec2 uv;
+
+out vec4 fragColor;
+
+uniform sampler2D inputTexture;
+
+void main() {
+ fragColor = texture(inputTexture, uv);
+}
diff --git a/cwd/assets/altcraft/shaders/frag/entity.fs b/cwd/assets/altcraft/shaders/frag/entity.fs
index 06d5759..a857da1 100644
--- a/cwd/assets/altcraft/shaders/frag/entity.fs
+++ b/cwd/assets/altcraft/shaders/frag/entity.fs
@@ -1,9 +1,13 @@
#version 330 core
-out vec4 fragColor;
+layout (location = 0) out vec4 color;
+layout (location = 1) out vec4 normal;
+layout (location = 2) out vec4 light;
-uniform vec3 color;
+uniform vec3 entityColor;
void main() {
- fragColor = vec4(color, 1);
+ color = vec4(entityColor, 1.0f);
+ normal = vec4(0.0f, 0.0f, 0.0f, 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 30d44d2..f9af02c 100644
--- a/cwd/assets/altcraft/shaders/frag/face.fs
+++ b/cwd/assets/altcraft/shaders/frag/face.fs
@@ -1,18 +1,23 @@
#version 330 core
-in VS_OUT {
- vec3 Texture;
- vec3 Color;
-} fs_in;
+in vec3 faceTextureUv;
+in vec3 faceAddColor;
+in vec3 faceNormal;
+in vec2 faceLight;
+in float faceAmbientOcclusion;
-out vec4 fragColor;
+layout (location = 0) out vec4 color;
+layout (location = 1) out vec4 normal;
+layout (location = 2) out vec4 light;
uniform sampler2DArray textureAtlas;
void main() {
- vec4 color = texture(textureAtlas,fs_in.Texture);
- if (color.a < 0.3)
+ vec4 col = texture(textureAtlas, faceTextureUv);
+ if (col.a < 0.3)
discard;
- fragColor = vec4(color.rgb * fs_in.Color, 1.0);
+ color = vec4(col.rgb * faceAddColor.rgb, 1.0f);
+ normal = vec4(faceNormal, 1.0f);
+ light = vec4(faceLight / 15.0f, faceAmbientOcclusion, 1.0f);
}
diff --git a/cwd/assets/altcraft/shaders/frag/fbo.fs b/cwd/assets/altcraft/shaders/frag/fbo.fs
deleted file mode 100644
index df624b3..0000000
--- a/cwd/assets/altcraft/shaders/frag/fbo.fs
+++ /dev/null
@@ -1,11 +0,0 @@
-#version 330 core
-
-out vec4 FragColor;
-in vec2 TexCoords;
-
-uniform sampler2D inputTexture;
-
-void main()
-{
- FragColor = texture(inputTexture, TexCoords);
-} \ No newline at end of file
diff --git a/cwd/assets/altcraft/shaders/frag/fwd_entity.fs b/cwd/assets/altcraft/shaders/frag/fwd_entity.fs
new file mode 100644
index 0000000..094aaf2
--- /dev/null
+++ b/cwd/assets/altcraft/shaders/frag/fwd_entity.fs
@@ -0,0 +1,11 @@
+#version 330 core
+
+in vec4 entityWorldPos;
+
+out vec4 fragColor;
+
+uniform vec3 entityColor;
+
+void main() {
+ fragColor = vec4(entityColor, 1.0f);
+}
diff --git a/cwd/assets/altcraft/shaders/frag/fwd_face.fs b/cwd/assets/altcraft/shaders/frag/fwd_face.fs
new file mode 100644
index 0000000..12deab8
--- /dev/null
+++ b/cwd/assets/altcraft/shaders/frag/fwd_face.fs
@@ -0,0 +1,39 @@
+#version 330 core
+
+in vec4 faceWorldPos;
+in vec3 faceTextureUv;
+in vec3 faceAddColor;
+in vec3 faceNormal;
+in vec2 faceLight;
+
+out vec4 fragColor;
+
+uniform sampler2DArray textureAtlas;
+
+layout (std140) uniform Globals {
+ mat4 projView;
+ mat4 proj;
+ mat4 invProj;
+ mat4 view;
+ uvec2 viewportSize;
+ vec4 ssaoKernels[64];
+ float globalTime;
+ float dayTime;
+ float gamma;
+};
+
+void main() {
+ vec4 col = texture(textureAtlas, faceTextureUv);
+ if (col.a < 0.3f)
+ discard;
+
+ float localLight = faceLight.r / 15.0f;
+ float skyLight = faceLight.g / 15.0f;
+ float lightLevel = clamp(localLight + skyLight * dayTime, 0.01f, 1.0f);
+ lightLevel = pow(lightLevel, 3);
+ lightLevel = clamp(lightLevel, 0.005f, 1.0f);
+
+ fragColor = vec4(col.rgb * faceAddColor.rgb * lightLevel, 1.0f);
+
+ fragColor.rgb = pow(fragColor.rgb, vec3(1.0f / gamma));
+}
diff --git a/cwd/assets/altcraft/shaders/frag/fwd_sky.fs b/cwd/assets/altcraft/shaders/frag/fwd_sky.fs
new file mode 100644
index 0000000..9f278b2
--- /dev/null
+++ b/cwd/assets/altcraft/shaders/frag/fwd_sky.fs
@@ -0,0 +1,66 @@
+#version 330 core
+
+in vec3 facePos;
+
+out vec4 fragColor;
+
+layout (std140) uniform Globals {
+ mat4 projView;
+ mat4 proj;
+ mat4 invProj;
+ mat4 view;
+ uvec2 viewportSize;
+ vec4 ssaoKernels[64];
+ float globalTime;
+ float dayTime;
+ float gamma;
+};
+
+uniform sampler2DArray textureAtlas;
+uniform vec4 sunTexture;
+uniform float sunTextureLayer;
+uniform vec4 moonTexture;
+uniform float moonTextureLayer;
+
+const vec4 DaySkyColor = vec4(0.21, 0.4, 1, 1);
+
+const vec3 SunPos = vec3(0, 0.1, 0.5);
+
+const vec3 MoonPos = vec3(0, 0.1, -0.5);
+
+const vec4 NightSkyColor = vec4(0.0, 0.0008, 0.002, 1.0);
+
+vec3 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords, float Layer) {
+ float x = TextureAtlasCoords.x;
+ float y = TextureAtlasCoords.y;
+ float w = TextureAtlasCoords.z;
+ float h = TextureAtlasCoords.w;
+ vec2 A = vec2(x, 1 - y - h);
+ vec2 B = vec2(x + w, 1 - y);
+ vec2 transformed = A + UvCoords * (B - A);
+ return vec3(transformed.x, transformed.y, Layer);
+}
+
+vec4 Sun() {
+ vec3 sunDelta = (facePos - SunPos) * 3.0f;
+ float distanceToSun = length(sunDelta);
+ vec4 sunColor = texture(textureAtlas, TransformTextureCoord(sunTexture, (vec2(sunDelta.xy) + 0.5f), sunTextureLayer));
+ vec4 sun = mix(vec4(0, 0, 0, 1), sunColor, clamp(1 - distanceToSun * 2.0f, 0, 1));
+ return sun;
+}
+
+vec4 Moon() {
+ vec3 moonDelta = (facePos - MoonPos) * 4.5f;
+ float distanceToMoon = length(moonDelta);
+ vec4 moonColor = texture(textureAtlas, TransformTextureCoord(moonTexture, (vec2(moonDelta.xy) + 0.5f), moonTextureLayer));
+ vec4 moon = mix(vec4(0, 0, 0, 1),moonColor, clamp(1 - distanceToMoon * 2.0f, 0, 1));
+ return moon;
+}
+
+void main() {
+ fragColor = vec4(mix(NightSkyColor, DaySkyColor, dayTime).rgb, 1.0f);
+ fragColor += vec4(Sun().rgb, 1.0f);
+ fragColor += vec4(Moon().rgb, 1.0f);
+
+ fragColor.rgb = pow(fragColor.rgb, vec3(1.0f / gamma));
+}
diff --git a/cwd/assets/altcraft/shaders/frag/light.fs b/cwd/assets/altcraft/shaders/frag/light.fs
new file mode 100644
index 0000000..a0cda02
--- /dev/null
+++ b/cwd/assets/altcraft/shaders/frag/light.fs
@@ -0,0 +1,83 @@
+#version 330 core
+
+out vec4 fragColor;
+
+in vec2 uv;
+
+uniform sampler2D depthStencil;
+uniform sampler2D color;
+uniform sampler2D normal;
+uniform sampler2D light;
+uniform sampler2D ssao;
+
+uniform int renderBuff;
+uniform bool applySsao;
+
+layout (std140) uniform Globals {
+ mat4 projView;
+ mat4 proj;
+ mat4 invProj;
+ mat4 view;
+ uvec2 viewportSize;
+ vec4 ssaoKernels[64];
+ float globalTime;
+ float dayTime;
+ 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 l = texture(light, uv);
+ float depth = texture(depthStencil, uv).r;
+ float d = (1.0f - depth) * 16.0f;
+ vec4 s = texture(ssao, uv);
+
+ float faceLight = l.r;
+ float skyLight = l.g;
+ float lightLevel = clamp(faceLight + skyLight * dayTime, 0.01f, 1.0f);
+ lightLevel = pow(lightLevel, 3);
+ if (applySsao) {
+ lightLevel *= pow(s.r, 2);
+ }
+ lightLevel = clamp(lightLevel, 0.005f, 1.0f);
+
+ vec4 finalColor = vec4(c.rgb * lightLevel, 1.0f);
+
+ finalColor.rgb = pow(finalColor.rgb, vec3(1.0f / gamma));
+
+ switch(renderBuff) {
+ case 0:
+ fragColor = finalColor;
+ break;
+ case 1:
+ fragColor = c;
+ break;
+ case 2:
+ fragColor = n;
+ break;
+ case 3:
+ fragColor = vec4(RecoverViewWorldPos(uv, depth), 1.0f);
+ break;
+ case 4:
+ fragColor = vec4(0.5f);
+ break;
+ case 5:
+ fragColor = vec4(l.r, l.g, 1.0f - l.b, 1.0f);
+ break;
+ case 6:
+ fragColor = vec4(vec3(d), 1.0f);
+ break;
+ case 7:
+ fragColor = vec4(pow(s.r, 2));
+ break;
+ }
+}
diff --git a/cwd/assets/altcraft/shaders/frag/rml.fs b/cwd/assets/altcraft/shaders/frag/rml.fs
index 54c3f36..fa1c596 100644
--- a/cwd/assets/altcraft/shaders/frag/rml.fs
+++ b/cwd/assets/altcraft/shaders/frag/rml.fs
@@ -1,12 +1,10 @@
#version 330 core
-in VS_OUT {
- vec4 color;
- vec2 tex_coord;
-} fs_in;
+in vec4 color;
+in vec2 uv;
out vec4 fragColor;
void main() {
- fragColor = fs_in.color;
+ fragColor = color;
}
diff --git a/cwd/assets/altcraft/shaders/frag/rmltex.fs b/cwd/assets/altcraft/shaders/frag/rmltex.fs
index d885b3b..af86b5b 100644
--- a/cwd/assets/altcraft/shaders/frag/rmltex.fs
+++ b/cwd/assets/altcraft/shaders/frag/rmltex.fs
@@ -1,14 +1,12 @@
#version 330 core
-uniform sampler2D fontTexture;
-
-in VS_OUT {
- vec4 color;
- vec2 tex_coord;
-} fs_in;
+in vec4 color;
+in vec2 uv;
out vec4 fragColor;
+uniform sampler2D fontTexture;
+
void main() {
- fragColor = fs_in.color * texture(fontTexture, fs_in.tex_coord);
+ fragColor = color * texture(fontTexture, uv);
}
diff --git a/cwd/assets/altcraft/shaders/frag/sky.fs b/cwd/assets/altcraft/shaders/frag/sky.fs
index 53e0cf4..731246a 100644
--- a/cwd/assets/altcraft/shaders/frag/sky.fs
+++ b/cwd/assets/altcraft/shaders/frag/sky.fs
@@ -1,22 +1,37 @@
#version 330 core
-in vec3 pos;
+in vec3 facePos;
-out vec4 fragColor;
+layout (location = 0) out vec4 color;
+layout (location = 1) out vec4 normal;
+layout (location = 2) out vec4 light;
+
+layout (std140) uniform Globals {
+ mat4 projView;
+ mat4 proj;
+ mat4 invProj;
+ mat4 view;
+ uvec2 viewportSize;
+ vec4 ssaoKernels[64];
+ float globalTime;
+ float dayTime;
+ float gamma;
+};
uniform sampler2DArray textureAtlas;
-uniform float DayTime;
uniform vec4 sunTexture;
uniform float sunTextureLayer;
uniform vec4 moonTexture;
uniform float moonTextureLayer;
-const vec4 DaySkyColor = vec4(0.49, 0.66, 1, 1);
+const vec4 DaySkyColor = vec4(0.21, 0.4, 1, 1);
const vec3 SunPos = vec3(0, 0.1, 0.5);
const vec3 MoonPos = vec3(0, 0.1, -0.5);
+const vec4 NightSkyColor = vec4(0.0, 0.0008, 0.002, 1.0);
+
vec3 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords, float Layer) {
float x = TextureAtlasCoords.x;
float y = TextureAtlasCoords.y;
@@ -29,7 +44,7 @@ vec3 TransformTextureCoord(vec4 TextureAtlasCoords, vec2 UvCoords, float Layer)
}
vec4 Sun() {
- vec3 sunDelta = (pos - SunPos) * 3.0f;
+ vec3 sunDelta = (facePos - SunPos) * 3.0f;
float distanceToSun = length(sunDelta);
vec4 sunColor = texture(textureAtlas, TransformTextureCoord(sunTexture, (vec2(sunDelta.xy) + 0.5f), sunTextureLayer));
vec4 sun = mix(vec4(0, 0, 0, 1), sunColor, clamp(1 - distanceToSun * 2.0f, 0, 1));
@@ -37,7 +52,7 @@ vec4 Sun() {
}
vec4 Moon() {
- vec3 moonDelta = (pos - MoonPos) * 4.5f;
+ vec3 moonDelta = (facePos - MoonPos) * 4.5f;
float distanceToMoon = length(moonDelta);
vec4 moonColor = texture(textureAtlas, TransformTextureCoord(moonTexture, (vec2(moonDelta.xy) + 0.5f), moonTextureLayer));
vec4 moon = mix(vec4(0, 0, 0, 1),moonColor, clamp(1 - distanceToMoon * 2.0f, 0, 1));
@@ -45,8 +60,10 @@ vec4 Moon() {
}
void main() {
- vec4 starColor = vec4(0.0f, 0.04f, 0.06f, 1.0f);
- fragColor = mix(starColor, DaySkyColor, DayTime);
- fragColor += Sun();
- fragColor += Moon();
+ color = vec4(mix(NightSkyColor, DaySkyColor, dayTime).rgb, 1.0f);
+ color += vec4(Sun().rgb, 1.0f);
+ color += vec4(Moon().rgb, 1.0f);
+ normal = vec4(0.0f, 0.0f, 0.0f, 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
new file mode 100644
index 0000000..1c9db1f
--- /dev/null
+++ b/cwd/assets/altcraft/shaders/frag/ssao.fs
@@ -0,0 +1,68 @@
+#version 330 core
+
+out vec4 fragColor;
+
+in vec2 uv;
+
+uniform sampler2D normal;
+uniform sampler2D light;
+uniform sampler2D depthStencil;
+uniform sampler2D ssaoNoise;
+
+uniform int ssaoSamples;
+
+layout (std140) uniform Globals {
+ mat4 projView;
+ mat4 proj;
+ mat4 invProj;
+ mat4 view;
+ uvec2 viewportSize;
+ vec4 ssaoKernels[64];
+ float globalTime;
+ float dayTime;
+ float gamma;
+};
+
+const vec2 noiseScale = vec2(4.0f, 4.0f);
+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 = RecoverViewWorldPos(uv, texture(depthStencil, uv).r);
+ vec2 noiseUv = uv * viewportSize / noiseScale;
+
+ vec3 randomVec = texture(ssaoNoise, noiseUv).xyz;
+
+ vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal));
+ vec3 bitangent = cross(normal, tangent);
+ mat3 TBN = mat3(tangent, bitangent, normal);
+
+ float occlusion = 0.0;
+ int samples = min(kernelSize, ssaoSamples);
+ for(int i = 0; i < samples; i++)
+ {
+ vec3 samplePos = TBN * ssaoKernels[i].xyz;
+ samplePos = fragPos + samplePos * radius;
+
+ vec4 offset = vec4(samplePos, 1.0);
+ offset = proj * offset;
+ offset.xyz /= offset.w;
+ offset.xyz = offset.xyz * 0.5 + 0.5;
+
+ float sampleDepth = RecoverViewWorldPos(offset.xy, texture(depthStencil, offset.xy).r).z;
+ float rangeCheck = smoothstep(0.0, 1.0, radius / abs(fragPos.z - sampleDepth));
+ float aoMask = texture(light, offset.xy).b;
+ occlusion += (sampleDepth >= samplePos.z + bias ? 1.0 : 0.0) * rangeCheck * aoMask;
+ }
+
+ occlusion = 1.0f - (occlusion / samples);
+
+ fragColor = vec4(vec3(occlusion), 1.0f);
+}