summaryrefslogtreecommitdiff
path: root/src/shaders
diff options
context:
space:
mode:
authorAlexander M Pickering <alex@cogarr.net>2025-01-21 16:02:51 -0600
committerAlexander M Pickering <alex@cogarr.net>2025-01-21 16:02:51 -0600
commit0370d64b3bd7914be55358817e52bbc8a529a7d3 (patch)
treea717bb9582f8a4c8dc7caf0d455e25113c7b8704 /src/shaders
parentda9dd31f504d30f33922cdf362a7c01673a6b927 (diff)
downloadggj25-0370d64b3bd7914be55358817e52bbc8a529a7d3.tar.gz
ggj25-0370d64b3bd7914be55358817e52bbc8a529a7d3.tar.bz2
ggj25-0370d64b3bd7914be55358817e52bbc8a529a7d3.zip
work
Diffstat (limited to 'src/shaders')
-rw-r--r--src/shaders/lake.frag5
-rw-r--r--src/shaders/lake.moon29
-rw-r--r--src/shaders/lake.vert13
-rw-r--r--src/shaders/land.frag50
-rw-r--r--src/shaders/land.vert14
-rw-r--r--src/shaders/player.frag14
-rw-r--r--src/shaders/player.vert23
7 files changed, 148 insertions, 0 deletions
diff --git a/src/shaders/lake.frag b/src/shaders/lake.frag
new file mode 100644
index 0000000..d45917e
--- /dev/null
+++ b/src/shaders/lake.frag
@@ -0,0 +1,5 @@
+precision mediump float;
+uniform vec4 color;
+void main() {
+ gl_FragColor = color;
+}
diff --git a/src/shaders/lake.moon b/src/shaders/lake.moon
new file mode 100644
index 0000000..bac2c42
--- /dev/null
+++ b/src/shaders/lake.moon
@@ -0,0 +1,29 @@
+
+shader_shim = require("shader_shim")
+win = require("window")
+world = require("world")
+
+node = shader_shim.lake\append(am.bind({
+ MV: mat4(
+ 1, 0, 0, 0,
+ 0, 1, 0, 0,
+ 0, 0, 1, 0,
+ (-win.width / 2), (-win.height/2), 0, 1
+ ),
+ P: mat4(1)
+ lake: am.vec3_array({})
+ light1: am.vec4_array({})
+ light2: am.vec4_array({})
+ light3: am.vec4_array({})
+ world_x: 0
+ world_y: 0
+ time: am.current_time()
+}))\append(am.draw("triangles"))
+
+node\action((self) ->
+ self("bind").time = am.current_time!
+ self("bind").world_x = world.world_x
+ self("bind").world_y = world.world_y
+)
+
+node
diff --git a/src/shaders/lake.vert b/src/shaders/lake.vert
new file mode 100644
index 0000000..2745cf9
--- /dev/null
+++ b/src/shaders/lake.vert
@@ -0,0 +1,13 @@
+precision highp float;
+attribute vec3 lake;
+attribute vec4 lamp1; //position, strength
+attribute vec4 lamp2;
+attribute vec4 lamp3; // max 3 lamps per shaded vertex
+uniform float time; //used for noise
+uniform float world_x;
+uniform float world_y;
+uniform mat4 MV;
+uniform mat4 P;
+void main() {
+ gl_Position = P * MV * vec4(lake.x - world_x, lake.y - world_y, 0., 1.0);
+}
diff --git a/src/shaders/land.frag b/src/shaders/land.frag
new file mode 100644
index 0000000..3c23990
--- /dev/null
+++ b/src/shaders/land.frag
@@ -0,0 +1,50 @@
+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
+varying vec2 worldxy;
+varying mat4 pre;
+
+// Author @patriciogv - 2015
+float random (vec2 st) {
+ return fract(
+ sin(
+ dot(st.xy,vec2(12.9898,78.233))
+ ) *
+ 43758.5453123
+ );
+}
+
+void main() {
+ vec4 coord = gl_FragCoord + vec4(worldxy * 256., 0, 0);
+ /*
+ coord.x -= worldxy.x;
+ coord.y -= worldxy.y;
+ */
+ //coord = coord / 1000.;
+ float color = 0.;
+ vec2 lamppos = (lamp1.xy * 256.) - (worldxy * 1.);
+ color += (lamp1.w * 256.) - distance((lamp1.xy * 256.) - worldxy, coord.xy);
+ /*
+ if(color > 1.)
+ gl_FragColor = highlight;
+ else if(color > 0.8)
+ gl_FragColor = foreground;
+ else if(color > 0.6)
+ gl_FragColor = midground;
+ else if(color > 0.4)
+ gl_FragColor = background;
+ else if(color > 0.2)
+ gl_FragColor = shadow;
+ else
+ gl_FragColor = black;
+ */
+ gl_FragColor = vec4(color / (256. * lamp1.w), color / (256. * lamp1.w), color / (256. * lamp1.w),1.);
+}
diff --git a/src/shaders/land.vert b/src/shaders/land.vert
new file mode 100644
index 0000000..2004ab3
--- /dev/null
+++ b/src/shaders/land.vert
@@ -0,0 +1,14 @@
+precision highp float;
+attribute vec3 land;
+uniform float time; //used for noise
+uniform float world_x;
+uniform float world_y;
+uniform mat4 MV;
+uniform mat4 P;
+varying vec2 worldxy;
+varying mat4 pre;
+void main() {
+ worldxy = vec2(world_x, world_y);
+ pre = P * MV;
+ gl_Position = P * MV * vec4(land.x - world_x, land.y - world_y, 0., 1.0);
+}
diff --git a/src/shaders/player.frag b/src/shaders/player.frag
new file mode 100644
index 0000000..5d329fa
--- /dev/null
+++ b/src/shaders/player.frag
@@ -0,0 +1,14 @@
+precision mediump float;
+varying vec2 textureuv; // uv
+uniform sampler2D textures;
+uniform sampler2D emissives;
+uniform sampler2D normals;
+varying mat3 light1; // position, color, intensity-fadetime-?
+varying vec4 v_color;
+void main() {
+ vec2 uv = textureuv;
+ //gl_FragColor = texture2D(textures,uv);// + vec4(uv.xy / 4.,0.,1.);
+ gl_FragColor = vec4(uv.xy / 1., 0., max(uv.x, uv.y));
+ //gl_FragColor = texture2D(textures,screen_intersection.xy);
+
+}
diff --git a/src/shaders/player.vert b/src/shaders/player.vert
new file mode 100644
index 0000000..ce53bf5
--- /dev/null
+++ b/src/shaders/player.vert
@@ -0,0 +1,23 @@
+precision highp float;
+attribute vec3 player;
+attribute vec2 texuv;
+varying vec2 textureuv;
+attribute vec4 lamp1; //vec3 position, float strength
+attribute vec4 lamp2;
+attribute vec4 lamp3; // max 3 lamps per shaded player
+uniform float time; //used for noise
+uniform float world_x;
+uniform float world_y;
+uniform float dir;
+uniform mat4 MV;
+uniform mat4 P;
+void main() {
+ textureuv=texuv;
+ mat2 rotate = mat2(
+ cos(dir), -sin(dir),
+ sin(dir), cos(dir)
+ );
+ vec2 world = vec2(world_x, world_y);
+ vec2 local = (player.xy - world) * rotate;
+ gl_Position = P * MV * vec4(local.xy, -2, 1.0);
+}