techkaczynski.dev / code

summaryrefslogtreecommitdiff
path: root/res/sdr/mdl_two_sided_cutoff.fs
diff options
context:
space:
mode:
Diffstat (limited to 'res/sdr/mdl_two_sided_cutoff.fs')
-rw-r--r--res/sdr/mdl_two_sided_cutoff.fs51
1 files changed, 51 insertions, 0 deletions
diff --git a/res/sdr/mdl_two_sided_cutoff.fs b/res/sdr/mdl_two_sided_cutoff.fs
new file mode 100644
index 0000000..c4ac07e
--- /dev/null
+++ b/res/sdr/mdl_two_sided_cutoff.fs
@@ -0,0 +1,51 @@
+#version 330
+
+uniform sampler2D texture0;
+uniform vec4 colDiffuse;
+
+uniform vec3 sun_direction;
+uniform vec3 sun_colour;
+uniform float sun_intensity;
+
+uniform vec3 moon_direction;
+uniform vec3 moon_colour;
+uniform float moon_intensity;
+
+uniform vec3 ambient_colour;
+uniform float ambient_intensity;
+
+in vec2 frag_texcoord;
+in vec4 frag_colour;
+in vec3 frag_normal;
+
+out vec4 finalColor;
+
+void main() {
+ vec4 texel = texture(texture0, frag_texcoord) * frag_colour;
+
+ if (texel.a < 0.5) {
+ discard;
+ }
+
+ texel.rgb += colDiffuse.rgb;
+
+ vec3 normal = normalize(frag_normal);
+
+ if (!gl_FrontFacing) {
+ normal = -normal;
+ }
+
+ float sun_diffuse = max(dot(normal, sun_direction), 0.0);
+ float moon_diffuse = max(dot(normal, moon_direction), 0.0);
+
+ vec3 ambient_light = ambient_colour * ambient_intensity;
+ vec3 sun_light = sun_colour * sun_intensity * sun_diffuse;
+ vec3 moon_light = moon_colour * moon_intensity * moon_diffuse;
+
+ vec3 lighting = max(
+ ambient_light + sun_light + moon_light,
+ vec3(0.0)
+ );
+
+ finalColor = vec4(texel.rgb * lighting, 1.0);
+}