summaryrefslogtreecommitdiff
path: root/src/shaders/land.frag
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2025-01-25 20:40:09 -0600
committerAlexander M Pickering <alex@cogarr.net>2025-01-25 20:40:09 -0600
commitb174b8c00026253fd40ec262e430b0bb764e31ea (patch)
tree173d294b98fe14727aef9cd42542f41a940f5ffa /src/shaders/land.frag
parent89a8f94ac0206412c1a2d7b8766d97dbdbd36253 (diff)
downloadggj25-b174b8c00026253fd40ec262e430b0bb764e31ea.tar.gz
ggj25-b174b8c00026253fd40ec262e430b0bb764e31ea.tar.bz2
ggj25-b174b8c00026253fd40ec262e430b0bb764e31ea.zip
work
Diffstat (limited to 'src/shaders/land.frag')
-rw-r--r--src/shaders/land.frag72
1 files changed, 61 insertions, 11 deletions
diff --git a/src/shaders/land.frag b/src/shaders/land.frag
index 3c23990..1eb8d93 100644
--- a/src/shaders/land.frag
+++ b/src/shaders/land.frag
@@ -9,8 +9,18 @@ uniform vec4 background;
uniform vec4 lamp1; //vec3 position, float strength
uniform vec4 lamp2;
uniform vec4 lamp3; // max 3 lamps per shaded vertex
+uniform vec4 lamp4;
+uniform vec4 lamp5;
+uniform vec4 lamp6;
+uniform vec4 lamp7;
+uniform vec4 lamp8;
+uniform float streamer; // turn off the noise in the light
+uniform float time; //used for noise
+uniform sampler2D atlas;
+uniform float nlamps;
+uniform float water;
varying vec2 worldxy;
-varying mat4 pre;
+varying vec2 norm;
// Author @patriciogv - 2015
float random (vec2 st) {
@@ -22,6 +32,28 @@ float random (vec2 st) {
);
}
+// stolen from https://www.shadertoy.com/view/Msf3WH
+vec2 hash( vec2 p ) // replace this by something better
+{
+ p = vec2( dot(p,vec2(127.1,311.7)), dot(p,vec2(269.5,183.3)) );
+ return -1.0 + 2.0*fract(sin(p)*43758.5453123);
+}
+float noise( in vec2 p )
+{
+ const float K1 = 0.366025404; // (sqrt(3)-1)/2;
+ const float K2 = 0.211324865; // (3-sqrt(3))/6;
+
+ vec2 i = floor( p + (p.x+p.y)*K1 );
+ vec2 a = p - i + (i.x+i.y)*K2;
+ float m = step(a.y,a.x);
+ vec2 o = vec2(m,1.0-m);
+ vec2 b = a - o + K2;
+ vec2 c = a - 1.0 + 2.0*K2;
+ vec3 h = max( 0.5-vec3(dot(a,a), dot(b,b), dot(c,c) ), 0.0 );
+ vec3 n = h*h*h*h*vec3( dot(a,hash(i+0.0)), dot(b,hash(i+o)), dot(c,hash(i+1.0)));
+ return dot( n, vec3(70.0) );
+}
+
void main() {
vec4 coord = gl_FragCoord + vec4(worldxy * 256., 0, 0);
/*
@@ -29,22 +61,40 @@ void main() {
coord.y -= worldxy.y;
*/
//coord = coord / 1000.;
+ // calculate color at this pixel
+ vec4 normal = texture2D(atlas, norm);
float color = 0.;
- vec2 lamppos = (lamp1.xy * 256.) - (worldxy * 1.);
- color += (lamp1.w * 256.) - distance((lamp1.xy * 256.) - worldxy, coord.xy);
- /*
+ vec4 lamp1_norm = lamp1 * 256.;
+ color += lamp1_norm.w - distance(lamp1_norm.xy - worldxy, coord.xy);
+ color = max(color,(lamp2.w * 256.) - distance((lamp2.xy * 256.) - worldxy, coord.xy));
+ color = max(color,(lamp3.w * 256.) - distance((lamp3.xy * 256.) - worldxy, coord.xy));
+ // divide to get a normalized color
+ //color /= (256. * max(max(lamp1.w, lamp2.w), lamp3.w));
+ color /= 256. * 5.;
+ //color = sqrt(color / 2046.);
+ // see the normal texture under the color
+ color = dot(vec4(color),normal) / 1.;
+ // make the colors fuzzy near the border (or don't if we're streaming)
+ float rng = random(vec2(coord.x, coord.y) + vec2(color, time));
+ color -= (pow(rng / 1.3, 10. * color)) * streamer;
+ // add noise to water
+ if(water > 1.)
+ color += (noise(coord.xy + vec2(time, time)) - 0.0) * 0.1;
+ /* */
if(color > 1.)
- gl_FragColor = highlight;
+ gl_FragColor = highlight * normal.a;
else if(color > 0.8)
- gl_FragColor = foreground;
+ gl_FragColor = foreground * normal.a;
else if(color > 0.6)
- gl_FragColor = midground;
+ gl_FragColor = midground * normal.a;
else if(color > 0.4)
- gl_FragColor = background;
+ gl_FragColor = background * normal.a;
else if(color > 0.2)
- gl_FragColor = shadow;
+ gl_FragColor = shadow * normal.a;
else
- gl_FragColor = black;
+ gl_FragColor = black * normal.a;
+ /*
+ gl_FragColor = normal* vec4(color , color, color,1.);
*/
- gl_FragColor = vec4(color / (256. * lamp1.w), color / (256. * lamp1.w), color / (256. * lamp1.w),1.);
+ //gl_FragColor = normal* vec4(color , color / 10., color / 1024.,1.);
}