diff options
| author | Alex Pickering <alex@cogarr.net> | 2026-02-01 13:14:32 -0600 |
|---|---|---|
| committer | Alexander M Pickering <alex@cogarr.net> | 2026-02-01 13:14:32 -0600 |
| commit | 3a975db66a3711f34e8b64bb27a8eaca79fdeca9 (patch) | |
| tree | fcc12f8f9d638ff575c1963796de76b7628854b4 /src/shaders/land.frag | |
| download | ggj26-master.tar.gz ggj26-master.tar.bz2 ggj26-master.zip | |
Diffstat (limited to 'src/shaders/land.frag')
| -rw-r--r-- | src/shaders/land.frag | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/shaders/land.frag b/src/shaders/land.frag new file mode 100644 index 0000000..1eb8d93 --- /dev/null +++ b/src/shaders/land.frag @@ -0,0 +1,100 @@ +precision mediump float; +uniform vec4 black; +uniform vec4 outline; +uniform vec4 highlight; +uniform vec4 foreground; +uniform vec4 midground; +uniform vec4 shadow; +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 vec2 norm; + +// Author @patriciogv - 2015 +float random (vec2 st) { + return fract( + sin( + dot(st.xy,vec2(12.9898,78.233)) + ) * + 43758.5453123 + ); +} + +// 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); + /* + coord.x -= worldxy.x; + coord.y -= worldxy.y; + */ + //coord = coord / 1000.; + // calculate color at this pixel + vec4 normal = texture2D(atlas, norm); + float color = 0.; + 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 * normal.a; + else if(color > 0.8) + gl_FragColor = foreground * normal.a; + else if(color > 0.6) + gl_FragColor = midground * normal.a; + else if(color > 0.4) + gl_FragColor = background * normal.a; + else if(color > 0.2) + gl_FragColor = shadow * normal.a; + else + gl_FragColor = black * normal.a; + /* + gl_FragColor = normal* vec4(color , color, color,1.); + */ + //gl_FragColor = normal* vec4(color , color / 10., color / 1024.,1.); +} |
