summary refs log tree commit diff
path: root/assets/shaders/terrain.frag.glsl
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2024-02-12 12:55:11 +0100
committerMel <einebeere@gmail.com>2024-02-12 12:55:11 +0100
commitd2b5fc5b3bc648afffa42375706429685ac63794 (patch)
treea2dfbb241e1d46e5616c5884e5f3d685de2a2cb6 /assets/shaders/terrain.frag.glsl
parent588c7e87b7cab270698d43ca5c22d67793ae5fc4 (diff)
downloadmeowcraft-d2b5fc5b3bc648afffa42375706429685ac63794.tar.zst
meowcraft-d2b5fc5b3bc648afffa42375706429685ac63794.zip
Split rendering into own thread and sync through render action lists
Diffstat (limited to 'assets/shaders/terrain.frag.glsl')
-rw-r--r--assets/shaders/terrain.frag.glsl32
1 files changed, 32 insertions, 0 deletions
diff --git a/assets/shaders/terrain.frag.glsl b/assets/shaders/terrain.frag.glsl
new file mode 100644
index 0000000..c7ecf97
--- /dev/null
+++ b/assets/shaders/terrain.frag.glsl
@@ -0,0 +1,32 @@
+#version 330 core
+
+uniform sampler2D tex;
+uniform float mesh_alpha;
+uniform vec3 sun_direction;
+uniform vec3 sky_color;
+
+in vec3 surface_normal;
+in vec2 frag_tex_coord;
+in float frag_light;
+in float frag_ambient_occlusion;
+in float depth;
+
+out vec4 color;
+
+void main() {
+    float brightness = dot(normalize(surface_normal), normalize(-sun_direction));
+    vec3 diffuse = vec3(max(brightness, 0.3));
+
+    vec4 texture_color = texture(tex, frag_tex_coord);
+    if (texture_color.a < 0.5) {
+        discard;
+    }
+
+    float ao = 1 - frag_ambient_occlusion / 2;
+    float light = frag_light;
+
+    vec3 opaque_color = diffuse * texture_color.xyz * ao * light;
+    opaque_color = mix(sky_color, opaque_color, 1 - depth);
+
+    color = vec4(opaque_color, mesh_alpha);
+}
\ No newline at end of file