add shader sources
authorhgn <hgodden00@gmail.com>
Thu, 4 Jan 2024 09:26:37 +0000 (09:26 +0000)
committerhgn <hgodden00@gmail.com>
Thu, 4 Jan 2024 09:26:37 +0000 (09:26 +0000)
21 files changed:
.gitignore
shaders/background.fs.glsl [new file with mode: 0644]
shaders/background.vs.glsl [new file with mode: 0644]
shaders/ball.fs.glsl [new file with mode: 0644]
shaders/ball.vs.glsl [new file with mode: 0644]
shaders/button.fs.glsl [new file with mode: 0644]
shaders/button.vs.glsl [new file with mode: 0644]
shaders/post_blur.fs.glsl [new file with mode: 0644]
shaders/post_blur.vs.glsl [new file with mode: 0644]
shaders/post_comp.fs.glsl [new file with mode: 0644]
shaders/post_comp.vs.glsl [new file with mode: 0644]
shaders/post_darken.fs.glsl [new file with mode: 0644]
shaders/post_darken.vs.glsl [new file with mode: 0644]
shaders/sprite.fs.glsl [new file with mode: 0644]
shaders/sprite.vs.glsl [new file with mode: 0644]
shaders/tile_colour.fs.glsl [new file with mode: 0644]
shaders/tile_colour.vs.glsl [new file with mode: 0644]
shaders/tile_main.fs.glsl [new file with mode: 0644]
shaders/tile_main.vs.glsl [new file with mode: 0644]
shaders/wire.fs.glsl [new file with mode: 0644]
shaders/wire.vs.glsl [new file with mode: 0644]

index 8d4aa820a1c7d34d8258c293dd6e939112675530..22c8eae7672295da98e20c8287c64d132b21dfd8 100755 (executable)
@@ -27,7 +27,7 @@ restricted/
 # GLSL shader source files
 !*.fs
 !*.vs
-!*.gls
+!*.glsl
 
 # Python source files
 !*.py
diff --git a/shaders/background.fs.glsl b/shaders/background.fs.glsl
new file mode 100644 (file)
index 0000000..b6f817b
--- /dev/null
@@ -0,0 +1,34 @@
+out vec4 FragColor;
+
+uniform sampler2D uTexMain;
+uniform sampler2D uSamplerNoise;
+uniform float uVariance;
+uniform float uVisibility;
+
+in vec2 aTexCoords;
+
+void main(){
+   vec4 data_this_tile = texture( uTexMain, aTexCoords );
+
+   float ao_accum = 0.0;
+   vec2 random_noise;
+
+   for( int i=0; i<10; ++i ){
+       random_noise = (texture( uSamplerNoise, 
+                               aTexCoords*10.0 + float(i)*0.2 ).xy - vec2(0.5)) 
+                               * uVariance;
+       vec4 background = texture( uTexMain, aTexCoords + random_noise );
+      float height_diff = min(data_this_tile.r - background.r,0.0);
+       ao_accum += height_diff * clamp((1.0 - length( random_noise )), 0.0, 1.0);
+   }
+   ao_accum *= 0.15;
+
+   vec2 square_coords = fract( aTexCoords * 64.0 );
+   vec2 grid_coords = abs( square_coords - 0.5 );
+   float gridline = step( 0.49, max(grid_coords.x,grid_coords.y) );
+
+   vec3 colour_main = mix( vec3( 0.14 ) + random_noise.x*0.5, 
+                           vec3( 0.1 ) + gridline*0.02, 
+                           data_this_tile.g * uVisibility );
+   FragColor = vec4( colour_main + ao_accum*0.05, 1.0 );
+}
diff --git a/shaders/background.vs.glsl b/shaders/background.vs.glsl
new file mode 100644 (file)
index 0000000..d7ca02d
--- /dev/null
@@ -0,0 +1,11 @@
+layout (location=0) in vec2 a_co;
+uniform mat3 uPv;
+uniform vec3 uOffset;
+
+out vec2 aTexCoords;
+
+void main(){
+   vec2 world_pos = a_co * uOffset.z + uOffset.xy;
+   gl_Position = vec4( uPv * vec3( world_pos, 1.0 ), 1.0 );
+   aTexCoords = a_co;
+}
diff --git a/shaders/ball.fs.glsl b/shaders/ball.fs.glsl
new file mode 100644 (file)
index 0000000..634aef6
--- /dev/null
@@ -0,0 +1,30 @@
+out vec4 FragColor;
+
+uniform sampler2D uTexMain;
+uniform vec3 uColour;
+uniform vec2 uTexOffset;
+
+in vec4 aTexCoords;
+
+void main(){
+       vec2 center_coords = aTexCoords.xy - 0.5;
+       vec2 center_coords_sqr = center_coords*center_coords;
+       float circle_factor = smoothstep( 0.07, 0.0625, 
+                                     center_coords_sqr.x+center_coords_sqr.y );
+       
+       float bulge_amt = center_coords_sqr.x+center_coords_sqr.y;
+       vec2 warped_coords = aTexCoords.zw+uTexOffset - center_coords;
+       vec4 noise_sample = texture( uTexMain, warped_coords );
+       
+       float rim_light = (center_coords_sqr.x+center_coords_sqr.y)*15.0;
+       
+       vec2 shadow_coords = center_coords + vec2(0.02,0.07);
+       vec2 shadow_coords_sqr = shadow_coords*shadow_coords;
+       float shadow = exp(-((shadow_coords_sqr.x+shadow_coords_sqr.y)-0.0125)*15.0);
+       
+       vec3 marble_comp = uColour*0.6 + 
+                        (noise_sample.x*2.7+pow(rim_light,3.0)*2.0) * 0.1;
+       vec4 colour_comp = mix( vec4(0.0,0.0,0.0,shadow), 
+                           vec4(marble_comp,1.0), circle_factor );
+       FragColor = colour_comp;
+}
diff --git a/shaders/ball.vs.glsl b/shaders/ball.vs.glsl
new file mode 100644 (file)
index 0000000..4f00555
--- /dev/null
@@ -0,0 +1,14 @@
+layout (location=0) in vec2 a_co;
+uniform vec3 uOffset;
+uniform mat3 uPv;
+
+out vec4 aTexCoords;
+
+void main(){
+  // Vertex transform
+  vec3 worldpos = vec3( (a_co * 0.5 - 0.25) * uOffset.z + uOffset.xy, 1.0 );
+  gl_Position = vec4( uPv * worldpos, 1.0 );
+
+  // Create texture coords
+  aTexCoords = vec4( a_co, worldpos.xy );
+}
diff --git a/shaders/button.fs.glsl b/shaders/button.fs.glsl
new file mode 100644 (file)
index 0000000..848a8de
--- /dev/null
@@ -0,0 +1,14 @@
+out vec4 FragColor;
+
+uniform sampler2D uTexMain;
+uniform vec4 uColour; // rgb, light amount
+
+in vec2 aTexCoords;
+
+void main(){
+       vec4 glyph = texture( uTexMain, aTexCoords.xy );
+       
+       FragColor = vec4( uColour.rgb * 
+                     (mix(glyph.r,glyph.g,uColour.a)+0.02)*2.6 + glyph.b * 0.4, 
+                     glyph.a );
+}
diff --git a/shaders/button.vs.glsl b/shaders/button.vs.glsl
new file mode 100644 (file)
index 0000000..c4d5c3e
--- /dev/null
@@ -0,0 +1,17 @@
+layout (location=0) in vec2 a_co;
+uniform vec4 uOffset;  // Tile x/y, uv x/y
+uniform mat3 uPv;
+
+out vec2 aTexCoords;
+
+void main(){
+       // Vertex transform
+       vec3 worldpos = vec3( a_co + uOffset.xy, 1.0 );
+       gl_Position = vec4( uPv * worldpos, 1.0 );
+
+       // Create texture coords
+       vec2 edge_safe_coords = a_co * 0.98 + 0.01;
+   vec2 tex_uv = (edge_safe_coords + uOffset.zw) * 0.25;
+        tex_uv = vec2( tex_uv.x, 1.0-tex_uv.y );
+       aTexCoords = tex_uv;
+}
diff --git a/shaders/post_blur.fs.glsl b/shaders/post_blur.fs.glsl
new file mode 100644 (file)
index 0000000..089f02e
--- /dev/null
@@ -0,0 +1,21 @@
+uniform sampler2D uTexMain;
+uniform vec2 uDir;
+out vec4 FragColor;
+
+in vec2 aTexCoords;
+
+void main(){
+   vec4 colour = vec4(0.0);
+
+   vec2 off1 = vec2(1.411764705882353)  * uDir;
+   vec2 off2 = vec2(3.2941176470588234) * uDir;
+   vec2 off3 = vec2(5.176470588235294)  * uDir;
+   colour += texture2D( uTexMain, aTexCoords ) * 0.1964825501511404;
+   colour += texture2D( uTexMain, aTexCoords + off1 ) * 0.2969069646728344;
+   colour += texture2D( uTexMain, aTexCoords - off1 ) * 0.2969069646728344;
+   colour += texture2D( uTexMain, aTexCoords + off2 ) * 0.09447039785044732;
+   colour += texture2D( uTexMain, aTexCoords - off2 ) * 0.09447039785044732;
+   colour += texture2D( uTexMain, aTexCoords + off3 ) * 0.010381362401148057;
+   colour += texture2D( uTexMain, aTexCoords - off3 ) * 0.010381362401148057;
+       FragColor = colour;
+}
diff --git a/shaders/post_blur.vs.glsl b/shaders/post_blur.vs.glsl
new file mode 100644 (file)
index 0000000..25b8aab
--- /dev/null
@@ -0,0 +1,7 @@
+layout (location=0) in vec2 a_co;
+out vec2 aTexCoords;
+
+void main(){
+       gl_Position = vec4( a_co * 2.0 - 1.0, 0.0, 1.0 );
+       aTexCoords = a_co;
+}
diff --git a/shaders/post_comp.fs.glsl b/shaders/post_comp.fs.glsl
new file mode 100644 (file)
index 0000000..79037a7
--- /dev/null
@@ -0,0 +1,17 @@
+uniform sampler2D uTexMain;
+uniform sampler2D uTexBloom;
+uniform vec2 uComp; /* x: bloom, y: vignette */
+out vec4 FragColor;
+
+in vec2 aTexCoords;
+
+void main(){
+       vec4 texture_sample = texture( uTexMain, aTexCoords );
+   vec4 bloom_sample = texture( uTexBloom, aTexCoords );
+   
+   vec2 vigCoord = aTexCoords - 0.5;
+   float vig = pow(1.0 - dot( vigCoord, vigCoord ), 2.0);
+   
+       FragColor = (texture_sample + bloom_sample*0.3*uComp.x)
+                * max(uComp.y, vig);
+}
diff --git a/shaders/post_comp.vs.glsl b/shaders/post_comp.vs.glsl
new file mode 100644 (file)
index 0000000..25b8aab
--- /dev/null
@@ -0,0 +1,7 @@
+layout (location=0) in vec2 a_co;
+out vec2 aTexCoords;
+
+void main(){
+       gl_Position = vec4( a_co * 2.0 - 1.0, 0.0, 1.0 );
+       aTexCoords = a_co;
+}
diff --git a/shaders/post_darken.fs.glsl b/shaders/post_darken.fs.glsl
new file mode 100644 (file)
index 0000000..1f956cc
--- /dev/null
@@ -0,0 +1,9 @@
+uniform sampler2D uTexMain;
+out vec4 FragColor;
+
+in vec2 aTexCoords;
+
+void main(){
+       vec4 texture_sample = texture( uTexMain, aTexCoords );
+       FragColor = vec4(pow(texture_sample.rgb,vec3(2.2)), 1.0);
+}
diff --git a/shaders/post_darken.vs.glsl b/shaders/post_darken.vs.glsl
new file mode 100644 (file)
index 0000000..25b8aab
--- /dev/null
@@ -0,0 +1,7 @@
+layout (location=0) in vec2 a_co;
+out vec2 aTexCoords;
+
+void main(){
+       gl_Position = vec4( a_co * 2.0 - 1.0, 0.0, 1.0 );
+       aTexCoords = a_co;
+}
diff --git a/shaders/sprite.fs.glsl b/shaders/sprite.fs.glsl
new file mode 100644 (file)
index 0000000..b058401
--- /dev/null
@@ -0,0 +1,9 @@
+uniform sampler2D uTexMain;
+out vec4 FragColor;
+
+in vec2 aTexCoords;
+
+void main(){
+       vec4 texture_sample = texture( uTexMain, aTexCoords );
+       FragColor = texture_sample;
+}
diff --git a/shaders/sprite.vs.glsl b/shaders/sprite.vs.glsl
new file mode 100644 (file)
index 0000000..e8727e5
--- /dev/null
@@ -0,0 +1,13 @@
+layout (location=0) in vec2 a_co; // quad mesh
+uniform vec4 uUv;
+uniform vec3 uPos;
+
+uniform mat3 uPv;
+
+out vec2 aTexCoords;
+
+void main(){
+       vec2 vertex_world = uUv.zw * (a_co-0.5) * uPos.z + uPos.xy;
+       gl_Position = vec4( uPv * vec3( vertex_world, 1.0 ), 1.0 );
+       aTexCoords = uUv.xy + a_co*uUv.zw;
+}
diff --git a/shaders/tile_colour.fs.glsl b/shaders/tile_colour.fs.glsl
new file mode 100644 (file)
index 0000000..9690fc6
--- /dev/null
@@ -0,0 +1,5 @@
+out vec4 FragColor;
+uniform vec4 uColour;
+void main(){
+   FragColor = uColour;
+}
diff --git a/shaders/tile_colour.vs.glsl b/shaders/tile_colour.vs.glsl
new file mode 100644 (file)
index 0000000..4614773
--- /dev/null
@@ -0,0 +1,7 @@
+layout (location=0) in vec2 a_co;
+uniform mat3 uPv;
+uniform vec3 uOffset;
+
+void main(){
+   gl_Position = vec4( uPv * vec3( a_co * uOffset.z + uOffset.xy, 1.0 ), 1.0 );
+}
diff --git a/shaders/tile_main.fs.glsl b/shaders/tile_main.fs.glsl
new file mode 100644 (file)
index 0000000..2a48c03
--- /dev/null
@@ -0,0 +1,34 @@
+out vec4 FragColor;
+
+uniform sampler2D uTexGlyphs;
+uniform sampler2D uTexGlow;
+uniform sampler2D uTexWood;
+uniform float uGhost;
+uniform float uForeground;
+uniform vec2 uMousePos;
+uniform vec4 uColour;
+uniform vec3 uShadowing;
+uniform vec3 uGlowA;
+uniform vec3 uGlowB;
+
+in vec4 aTexCoords;
+in vec2 aWorldCoords;
+
+void main(){
+   vec4 glyph = texture( uTexGlyphs, aTexCoords.xy );
+   vec4 glyph_glow = texture( uTexGlow, aTexCoords.xy );
+   vec4 wood = texture( uTexWood, aTexCoords.zw );
+   vec4 wood_secondary = texture( uTexWood, aTexCoords.zw + 0.25 );
+   vec3 wood_comp = mix( wood_secondary.rgb * uShadowing, 
+                         wood.rgb, clamp( glyph.b*2.0-1.0, 0.0, 1.0 ) );
+   
+   vec3 shadows = mix( uShadowing, vec3(1.0,1.0,1.0), glyph.r );
+   vec4 output_regular = vec4( wood_comp * shadows, 
+                               mix( glyph.a, glyph.b, uForeground ) );
+   
+   float ghost_dist = clamp( 1.5-distance(uMousePos, aWorldCoords), 0.0, 1.0 );
+   vec4 output_ghost = vec4( 1.0, 1.0, 1.0, glyph.g*ghost_dist );
+   vec4 glow_comp = vec4(glyph_glow.b*uGlowA+glyph_glow.g*uGlowB,0.0);
+   
+   FragColor = mix( output_regular, output_ghost, uGhost )*uColour + glow_comp;
+}
diff --git a/shaders/tile_main.vs.glsl b/shaders/tile_main.vs.glsl
new file mode 100644 (file)
index 0000000..fb9c04b
--- /dev/null
@@ -0,0 +1,32 @@
+layout (location=0) in vec2 a_co;
+uniform vec4 uOffset;  // Tile x/y, uv x/y
+uniform mat3 uPv;
+uniform mat2 uSubTransform;
+uniform float uVisibility;
+
+out vec4 aTexCoords;
+out vec2 aWorldCoords;
+
+vec2 hash22(vec2 p){
+       vec3 p3 = fract(vec3(p.xyx) * vec3(.1031, .1030, .0973));
+       p3 += dot(p3, p3.yzx+33.33);
+       return fract((p3.xx+p3.yz)*p3.zy);
+}
+
+void main(){
+       vec2 hash_val = hash22(uOffset.xy);
+       float scaling_factor = smoothstep( hash_val.x, hash_val.x+1.0, uVisibility );
+
+       // Vertex transform
+       vec2 subtransform = uSubTransform * (a_co-0.5) * scaling_factor + 0.5;
+       vec3 worldpos = vec3( subtransform + uOffset.xy, 1.0 );
+       gl_Position = vec4( uPv * worldpos, 1.0 );
+
+       // Create texture coords
+       vec2 random_offset = floor(hash_val * 4.0) * 0.25;
+       vec2 edge_safe_coords = a_co * 0.98 + 0.01;
+   vec2 tex_uv = (edge_safe_coords + uOffset.zw) * 0.25;
+        tex_uv = vec2( tex_uv.x, 1.0-tex_uv.y );
+       aTexCoords = vec4( tex_uv, edge_safe_coords * 0.25 + random_offset );
+       aWorldCoords = worldpos.xy;             
+}
diff --git a/shaders/wire.fs.glsl b/shaders/wire.fs.glsl
new file mode 100644 (file)
index 0000000..174eb64
--- /dev/null
@@ -0,0 +1,21 @@
+out vec4 FragColor;
+
+uniform sampler2D uTexMain;
+uniform vec4 uColour;
+uniform float uTime;
+uniform float uGlow;
+
+in vec2 aTexCoords;
+
+void main(){
+       // Compute shadowing
+       float shadow = 1.0 - abs(aTexCoords.y - 0.5) * 2.0;
+       float masking = smoothstep( 0.5, 0.8, shadow );
+       
+       vec3 colour_comp = mix( vec3(0.0,0.0,0.0), uColour.rgb, masking );
+       
+       float flow_thing = fract( aTexCoords.x + uTime );
+       vec3 final_comp = colour_comp + flow_thing * uGlow;
+       
+       FragColor = vec4( final_comp, max( shadow* 0.2, masking ) * uColour.a );
+}
diff --git a/shaders/wire.vs.glsl b/shaders/wire.vs.glsl
new file mode 100644 (file)
index 0000000..6e28718
--- /dev/null
@@ -0,0 +1,30 @@
+layout (location=0) in vec2 a_co;
+uniform vec3 uStart;
+uniform vec3 uEnd;
+uniform mat3 uPv;
+uniform float uCurve;
+
+out vec2 aTexCoords;
+
+vec3 sample_curve_time( float t ){
+       vec3 line_coord = mix( uStart, uEnd, t );
+
+       float curve_amt = 1.0-(pow((t*2.0-1.0),2.0));
+       return vec3( line_coord.x, line_coord.y - curve_amt*uCurve, line_coord.z );
+}
+
+void main(){
+       // Vertex transform
+       vec3 p0 = sample_curve_time( a_co.x );
+       vec3 p1 = sample_curve_time( a_co.x + 0.025 );
+       
+       vec2 line_tangent = normalize(p1.xy-p0.xy);
+       vec2 line_normal = vec2( -line_tangent.y, line_tangent.x );
+       
+       vec2 worldfinal = p0.xy + line_normal*a_co.y*p0.z;
+       
+       gl_Position = vec4( uPv * vec3(worldfinal, 1.0), 1.0 );
+
+       // Create texture coords (todo: include stretch adjusted coords?)
+       aTexCoords = vec2( a_co.x, a_co.y + 0.5 );
+}