some basic shaders

This commit is contained in:
Daniel Bulant 2023-01-01 11:01:45 +01:00
parent e451981ccb
commit acd56d4e6b
10 changed files with 128 additions and 0 deletions

View file

@ -0,0 +1,3 @@
void main() {
gl_Position = vec4( position, 1.0 );
}

View file

@ -0,0 +1,10 @@
precision mediump float;
vec2 brickTile(vec2 _st, float _zoom){
_st *= _zoom;
// Here is where the offset is happening
_st.x += step(1., mod(_st.y,2.0)) * 0.5;
return fract(_st);
}

View file

@ -0,0 +1,8 @@
precision mediump float;
mediump float circle(in vec2 _st, in float _radius){
vec2 dist = _st-vec2(0.5);
return 1.-smoothstep(_radius-(_radius*0.01),
_radius+(_radius*0.01),
dot(dist,dist)*4.0);
}

View file

@ -0,0 +1,17 @@
precision mediump float;
mediump float cog(in vec2 st){
vec2 pos = vec2(0.5)-st;
float r = length(pos)*2.0;
float a = atan(pos.y,pos.x);
return smoothstep(
-1.2, // lower cog part
1.5, // upper cog part
cos(
a * 10. // number of teeth
))
*0.5 // inner size
+ 0.5; // outer size
}

View file

@ -0,0 +1,5 @@
precision mediump float;
vec2 move(in vec2 st, in vec2 move) {
return st + move;
}

View file

@ -0,0 +1,21 @@
precision mediump float;
#define PI 3.14159265359
#define TWO_PI 6.28318530718
// sides should probably be an integer, but it can be abused for morphin effects
mediump float polygon(in vec2 st, in float sides){
vec3 color = vec3(0.0);
// Remap the space to -1. to 1.
st = st *2. -1.;
// Angle and radius from the current pixel
float a = atan(st.x,st.y)+PI;
float r = TWO_PI/float(sides);
// Shaping function that modulate the distance
return cos(floor(0.500+a/r)*r-a)*length(st);
// when it's not 0.5 exactly, the triangles will not match perfectly for the polygon to take shape. Can be abused for cool effects
// (possibly transitions)
}

View file

@ -0,0 +1,27 @@
precision mediump float;
float random (vec2 st) {
return fract(sin(dot(st.xy,
vec2(12.9898,78.233)))*
43758.5453123);
}
vec2 random2(vec2 st){
st = vec2( dot(st,vec2(127.1,311.7)),
dot(st,vec2(269.5,183.3)) );
return -1.0 + 2.0*fract(sin(st)*43758.5453123);
}
// Gradient Noise by Inigo Quilez - iq/2013
// https://www.shadertoy.com/view/XdXGW8
float noise(vec2 st) {
vec2 i = floor(st);
vec2 f = fract(st);
vec2 u = f*f*(3.0-2.0*f);
return mix( mix( dot( random2(i + vec2(0.0,0.0) ), f - vec2(0.0,0.0) ),
dot( random2(i + vec2(1.0,0.0) ), f - vec2(1.0,0.0) ), u.x),
mix( dot( random2(i + vec2(0.0,1.0) ), f - vec2(0.0,1.0) ),
dot( random2(i + vec2(1.0,1.0) ), f - vec2(1.0,1.0) ), u.x), u.y);
}

View file

@ -0,0 +1,9 @@
precision mediump float;
vec2 repeat(in vec2 st, in float repeat) {
return st * repeat;
}
vec2 repeat(in vec2 st, in vec2 repeat) {
return vec2(st.x * repeat.x, st.y * repeat.y);
}

View file

@ -0,0 +1,14 @@
precision mediump float;
mat2 mat_rotate2d(in float angle){
return mat2(cos(angle),-sin(angle),
sin(angle),cos(angle));
}
vec2 rotate2d(in vec2 _st, in float angle) {
vec2 st = _st;
st -= 0.5;
st *= mat_rotate2d(angle);
st += 0.5;
return st;
}

View file

@ -0,0 +1,14 @@
precision mediump float;
mat2 mat_scale(vec2 _scale){
return mat2(_scale.x,0.0,
0.0,_scale.y);
}
vec2 scale(in vec2 _st, in vec2 _scale) {
vec2 st = _st;
st -= 0.5;
st *= mat_scale(_scale);
st += 0.5;
return st;
}