summaryrefslogtreecommitdiff
path: root/gfx/gl/shaders/landmass.frag
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2026-01-31 02:51:16 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2026-01-31 02:51:16 +0000
commitbc0958cc863083b4082161bf12456fdf28ab1c77 (patch)
treef970782f232d86325f14a36b83125791f24335af /gfx/gl/shaders/landmass.frag
parentInitial commit using tesselation shader to create curves (diff)
downloadilt-bc0958cc863083b4082161bf12456fdf28ab1c77.tar.bz2
ilt-bc0958cc863083b4082161bf12456fdf28ab1c77.tar.xz
ilt-bc0958cc863083b4082161bf12456fdf28ab1c77.zip
Rename shader source in keeping with glsl expectations
Swaps name/type of generated files to match class names and source files.
Diffstat (limited to 'gfx/gl/shaders/landmass.frag')
-rw-r--r--gfx/gl/shaders/landmass.frag73
1 files changed, 73 insertions, 0 deletions
diff --git a/gfx/gl/shaders/landmass.frag b/gfx/gl/shaders/landmass.frag
new file mode 100644
index 0000000..b5c7fa1
--- /dev/null
+++ b/gfx/gl/shaders/landmass.frag
@@ -0,0 +1,73 @@
+#version 460 core
+
+include(`materialOut.glsl')
+in vec3 FragPos;
+in vec3 Normal;
+
+uniform sampler2D texture0;
+uniform ivec3 viewPoint;
+uniform vec3 colourBias;
+
+const vec3 grass = vec3(.1, .4, .05);
+const vec3 slope = vec3(.6, .6, .4);
+const vec3 rock = vec3(.2, .2, .1);
+const vec3 sand = vec3(.76, .7, .5);
+const vec3 snow = vec3(.97, .97, .99);
+
+const int beachline = 500;
+const int snowline_low = 28000;
+const int snowline_high = 30000;
+
+const float slope_min = .99;
+const float slope_mid = .95;
+const float slope_max = .90;
+
+vec3
+mixBetween(vec3 colA, vec3 colB, float blend, float low, float high)
+{
+ return mix(colA, colB, (blend - low) / (high - low));
+}
+
+void
+main()
+{
+ ivec3 position = ivec3(FragPos) + viewPoint;
+ vec3 color = texture(texture0, vec2(position.xy % 10000) / 10000.0).rgb;
+
+ int height = position.z;
+ if (colourBias.r >= 0) {
+ color *= colourBias;
+ }
+ else if (height < beachline) { // Sandy beach
+ color *= sand;
+ }
+ else if (Normal.z < slope_max) { // Dark rocky face
+ color *= rock;
+ }
+ else { // Colour by lesser slope
+ if (Normal.z < slope_mid) {
+ color *= mixBetween(rock, slope, Normal.z, slope_max, slope_mid);
+ }
+ else if (Normal.z < slope_min) {
+ color *= mixBetween(slope, grass, Normal.z, slope_mid, slope_min);
+ }
+ else {
+ color *= grass;
+ }
+
+ // Add a snow covering
+ if (height > snowline_low) {
+ vec3 tsnow = color * snow;
+ if (height > snowline_high) {
+ color = tsnow;
+ }
+ else {
+ color = mixBetween(color, tsnow, height, snowline_low, snowline_high);
+ }
+ }
+ }
+
+ gPosition = ivec4(position, 1);
+ gNormal = vec4(Normal, 1);
+ gAlbedoSpec = vec4(color, 1);
+}