Copy together a few more shaders

Signed-off-by: David Oberhollenzer <goliath@infraroot.at>
This commit is contained in:
David Oberhollenzer 2023-12-04 09:56:16 +01:00
parent 12396a8bb0
commit 2c6354926a
6 changed files with 338 additions and 0 deletions

55
shaders/noise.frag Normal file
View file

@ -0,0 +1,55 @@
const mat2 m = mat2(0.80, 0.60, -0.60, 0.80);
float noise(in vec2 p)
{
return sin(p.x) * sin(p.y);
}
float fbm4(vec2 p)
{
float f = 0.0;
f += 0.5000 * noise(p); p = m * p * 2.02;
f += 0.2500 * noise(p); p = m * p * 2.02;
f += 0.1250 * noise(p); p = m * p * 2.02;
f += 0.0625 * noise(p);
return f / 0.9375;
}
float fbm6(vec2 p)
{
float f = 0.0;
f += 0.500000 * (0.5 + 0.5 * noise(p)); p = m * p * 2.02;
f += 0.500000 * (0.5 + 0.5 * noise(p)); p = m * p * 2.02;
f += 0.500000 * (0.5 + 0.5 * noise(p)); p = m * p * 2.02;
f += 0.250000 * (0.5 + 0.5 * noise(p)); p = m * p * 2.02;
return f / 0.96875;
}
vec2 fbm4_2(vec2 p)
{
return vec2(fbm4(p), fbm4(p + vec2(7.8)));
}
vec2 fbm6_2(vec2 p)
{
return vec2(fbm6(p + vec2(16.8)), fbm6(p + vec2(11.5)));
}
float func(vec2 q, float t)
{
q += 0.03 * sin(vec2(0.27, 0.23) * t + length(q) * vec2(4.1, 4.3));
vec2 o = fbm4_2(0.9 * q);
o += 0.04 * sin(vec2(0.12, 0.14) * t + length(o));
vec2 n = fbm6_2(3.0 * o);
float f = 0.5 + 0.5 * fbm4(1.8 * q + 6.0 * n);
return mix(f, f * f * f * 3.5, f * abs(n.x));
}
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 uv = (2.0 * fragCoord.xy - iResolution.xy) / min(iResolution.x, iResolution.y);
float f = func(uv, iTime * 4.0);
vec3 col = f * (0.5 + 0.5 * cos(iTime + uv.xyx + vec3(0.0, 2.0, 4.0)));
fragColor = vec4(col, 1.0);
}

79
shaders/noise2.frag Normal file
View file

@ -0,0 +1,79 @@
const mat2 m = mat2(0.80, 0.60, -0.60, 0.80);
float noise(in vec2 p)
{
return sin(p.x) * sin(p.y);
}
float fbm4(vec2 p)
{
float f = 0.0;
f += 0.5000 * noise(p); p = m * p * 2.02;
f += 0.2500 * noise(p); p = m * p * 2.03;
f += 0.1250 * noise(p); p = m * p * 2.01;
f += 0.0625 * noise(p);
return f / 0.9375;
}
float fbm6(vec2 p)
{
float f = 0.0;
f += 0.500000 * (0.5 + 0.5 * noise(p)); p = m * p * 2.02;
f += 0.250000 * (0.5 + 0.5 * noise(p)); p = m * p * 2.03;
f += 0.125000 * (0.5 + 0.5 * noise(p)); p = m * p * 2.01;
f += 0.062500 * (0.5 + 0.5 * noise(p)); p = m * p * 2.04;
f += 0.031250 * (0.5 + 0.5 * noise(p)); p = m * p * 2.01;
f += 0.015625 * (0.5 + 0.5 * noise(p));
return f / 0.96875;
}
vec2 fbm4_2(vec2 p)
{
return vec2(fbm4(p), fbm4(p + vec2(7.8)));
}
vec2 fbm6_2(vec2 p)
{
return vec2(fbm6(p + vec2(16.8)), fbm6(p + vec2(11.5)));
}
float func(vec2 q, out vec4 ron)
{
q += 0.03 * sin(vec2(0.27, 0.23) * iTime + length(q) * vec2(4.1, 4.3));
vec2 o = fbm4_2(0.9 * q);
o += 0.04 * sin(vec2(0.12, 0.14) * iTime + length(o));
vec2 n = fbm6_2(3.0 * o);
ron = vec4(o, n);
float f = 0.5 + 0.5 * fbm4(1.8 * q + 6.0 * n);
return mix(f, f * f * f * 3.5, f * abs(n.x));
}
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 p = (2.0 * fragCoord - iResolution.xy) / iResolution.y;
float e = 2.0 / iResolution.y;
vec4 on = vec4(0.0);
float f = func(p, on);
vec3 col = vec3(0.0);
col = mix( vec3(0.9,0.7,0.1), vec3(0.1,0.5,0.05), f );
col = mix( col, vec3(0.3,0.3,0.1), dot(on.zw,on.zw) );
col = mix( col, vec3(0.4,0.3,0.3), 0.2 + 0.5*on.y*on.y );
col = mix( col, vec3(0.7,0.2,0.1), 0.5*smoothstep(1.2,1.3,abs(on.z)+abs(on.w)) );
col = clamp( col*f*2.0, 0.0, 1.0 );
// gpu derivatives - bad quality, butfast
vec3 nor = normalize(vec3(dFdx(f) * iResolution.x, 6.0,
dFdy(f) * iResolution.y));
vec3 lig = normalize(vec3(0.9, 0.2, -0.4));
float dif = clamp(0.3 + 0.7 * dot(nor, lig), 0.0, 1.0);
vec3 lin = vec3(0.70, 0.90, 0.95) * (nor.y * 0.5 + 0.5) + vec3(0.15, 0.10, 0.05) * dif;
col *= 1.2*lin;
col = 1.0 - col;
col = 1.1*col*col;
fragColor = vec4( col, 1.0 );
}

101
shaders/noise3.frag Normal file
View file

@ -0,0 +1,101 @@
// Author: @samloeschen
// Title: paint archipelago
// Quick exploration in fractal brownian motion and generating
// oil paint-like forms
//generic random
float random(in vec2 st)
{
return fract(sin(dot(st.xy, vec2(12.9898 ,78.233))) * 43758.5453123);
}
//@morgan3D noise
float noise(in vec2 st)
{
vec2 i = floor(st);
vec2 f = fract(st);
// Four corners in 2D of a tile
float a = random(i);
float b = random(i + vec2(1.0, 0.0));
float c = random(i + vec2(0.0, 1.0));
float d = random(i + vec2(1.0, 1.0));
vec2 u = f * f * (3.0 - 2.0 * f);
return mix(a, b, u.x) +
(c - a)* u.y * (1.0 - u.x) +
(d - b) * u.x * u.y;
}
//could probably reduce octaves but meh
#define octaves 11
float fbm(in vec2 p)
{
float value = 0.0;
float freq = 1.0;
float amp = 0.5;
for (int i = 0; i < octaves; i++) {
value += amp * (noise((p - vec2(1.0)) * freq));
freq *= 1.9;
amp *= 0.6;
}
return value;
}
//basically all the fbm warps are offset by big slow sine patterns
//when they diverge/are moving away from each other the fluidity feels faster,
//and when they converge its more chilled out
//I haven't tried animating the fbm scales yet but could be cool?
//TODO: add params to further manipulate color ramps with the domain warping
float pattern(in vec2 p)
{
vec2 offset = vec2(-0.5);
//generate main peaks/valleys
vec2 aPos = vec2(sin(iTime * 0.005), sin(iTime * 0.01)) * 6.;
vec2 aScale = vec2(3.0);
float a = fbm(p * aScale + aPos);
//1st domain warp
vec2 bPos = vec2(sin(iTime * 0.01), sin(iTime * 0.01)) * 1.;
vec2 bScale = vec2(0.5);
float b = fbm((p + a) * bScale + bPos);
//2nd domain warp, yay now its paint. this one creates a bunch of diagonal countours that it wasn't
//immediately obvious how to remove, but they kind of look like sun shafts so whatever
vec2 cPos = vec2(-0.6, -0.5) + vec2(sin(-iTime * 0.001), sin(iTime * 0.01)) * 2.;
vec2 cScale = vec2(2.); //this scale "zooms" the image
float c = fbm((p + b) * cScale + cPos);
return c;
}
//iq palette
vec3 palette(in float t)
{
vec3 a = vec3(0.5, 0.5, 0.5);
vec3 b = vec3(0.45, 0.25, 0.14);
vec3 c = vec3(1.0 ,1.0, 1.0);
vec3 d = vec3(0.0, 0.1, 0.2);
return a + b * cos(6.28318 * (c * t + d));
}
#define hue(v) (.5 + cos(6.3 * (v) + vec4(0, 23, 21, 0)))
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 p = fragCoord.xy / iResolution.xy;
p.x *= iResolution.x / iResolution.y;
float value = pow(pattern(p), 2.);
vec3 color = hue(value + fbm(p + iTime * .1) + iTime * .5).rgb;
fragColor = vec4(color, 1.0);
}

22
shaders/noise4.frag Normal file
View file

@ -0,0 +1,22 @@
#define PI 3.14159
#define TWO_PI (PI * 2.0)
#define N 26
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 v = (fragCoord.xy - iResolution.xy) / min(iResolution.x, iResolution.y);
v *= 5.0;
v -= vec2(200.0);
float col = 0.10;
for (int i = 0; i < N; i++) {
float a = float(i) * (TWO_PI / N) * 61.95;
col += cos(TWO_PI * (v.y * cos(a) + v.x * sin(a) + sin(iTime * 0.004) * 100.0));
}
col /= 3.0;
fragColor = vec4(col*1.50, -col*1.0,-col*1.0, 1.0);
}

48
shaders/noise5.frag Normal file
View file

@ -0,0 +1,48 @@
bool mode;
vec3 fcos(vec3 x)
{
vec3 w = fwidth(x);
return cos(x) * sin(0.5 * w) / (0.5 * w);
}
vec3 getColor(in float t)
{
vec3 col = vec3(0.4,0.4,0.4);
col += 0.12*fcos(6.28318*t* 1.0+vec3(0.0,0.8,1.1));
col += 0.11*fcos(6.28318*t* 3.1+vec3(0.3,0.4,0.1));
col += 0.10*fcos(6.28318*t* 5.1+vec3(0.1,0.7,1.1));
col += 0.09*fcos(6.28318*t* 9.1+vec3(0.2,0.8,1.4));
col += 0.08*fcos(6.28318*t* 17.1+vec3(0.2,0.6,0.7));
col += 0.07*fcos(6.28318*t* 31.1+vec3(0.1,0.6,0.7));
col += 0.06*fcos(6.28318*t* 65.1+vec3(0.0,0.5,0.8));
col += 0.06*fcos(6.28318*t*115.1+vec3(0.1,0.4,0.7));
col += 0.09*fcos(6.28318*t*265.1+vec3(1.1,1.4,2.7));
return col;
}
void mainImage(out vec4 fragColor, in vec2 fragCoord )
{
vec2 p = (2.0 * fragCoord.xy - iResolution.xy) / max(iResolution.x, iResolution.y);
// deform 1
p *= 0.25;
p = 0.5 * p / dot(p, p);
vec2 q = p;
p.x += iTime * 0.1;
// deform 2
p += 0.2 * cos(1.5 * p.yx + 0.03 * 1.0 * iTime + vec2(0.1, 1.1));
p += 0.2 * cos(2.4 * p.yx + 0.03 * 1.6 * iTime + vec2(4.5, 2.6));
p += 0.2 * cos(3.3 * p.yx + 0.03 * 1.2 * iTime + vec2(3.2, 3.4));
p += 0.2 * cos(4.2 * p.yx + 0.03 * 1.7 * iTime + vec2(1.8, 5.2));
p += 0.2 * cos(9.1 * p.yx + 0.03 * 1.1 * iTime + vec2(6.3, 3.9));
// base color pattern
vec3 col = getColor(0.5 * length(p));
// lighting
col *= 1.4 - 0.07 * length(q);
fragColor = vec4(col, 1.0);
}

33
shaders/noise6.frag Normal file
View file

@ -0,0 +1,33 @@
mat2 rotate2D(float r)
{
return mat2(cos(r), sin(r), -sin(r), cos(r));
}
void mainImage(out vec4 fragColor, in vec2 fragCoord)
{
vec2 uv = (fragCoord.xy - 0.5 * iResolution.xy) / min(iResolution.x, iResolution.y);
vec3 col = vec3(0);
float t = iTime * 0.15;
vec2 n = vec2(0);
vec2 q = vec2(0);
vec2 p = uv;
float d = dot(p, p);
float S = 20.0;
float a = 0.0;
mat2 m = rotate2D(4.0);
for (int j = 0; j < 20; ++j) {
p *= m;
n *= m;
q = p * S + t * 1.0 + sin(t * 4. - d * 6.) * 0.8 + float(j) + n;
a += dot(cos(q) / S, vec2(0.2));
n += sin(q);
S *= 1.2;
}
col = vec3(1.3, 2.5, 4) * (a + 0.3) + a + a + a - (d * 0.5);
fragColor = vec4(col, 1.0);
}