Skip to content

Instantly share code, notes, and snippets.

@tigercoding56
Created May 5, 2024 18:09
Show Gist options
  • Save tigercoding56/52fd00c5e59cdc14342b007646c2131a to your computer and use it in GitHub Desktop.
Save tigercoding56/52fd00c5e59cdc14342b007646c2131a to your computer and use it in GitHub Desktop.
circuit_shader credit to https://www.shadertoy.com/view/ttVfzR for base
vec2 Rotate(in vec2 p, in float r) {
float c = cos(r), s = sin(r);
return p * mat2(c, -s, s, c);
}
// Hashes from "Hash without Sine" by Dave_Hoskins (https://www.shadertoy.com/view/4djSRW)
float Hash21(in vec2 p) {
vec3 p3 = fract(p.xyx * 0.1031);
p3 += dot(p3, p3.yzx + 33.33);
return fract((p3.x + p3.y) * p3.z);
}
float Hash31(in vec3 p) {
vec3 p3 = fract(p * 0.1031);
p3 += dot(p3, p3.zyx + 31.32);
return fract((p3.x + p3.y) * p3.z);
}
// Smooth 3D noise
float snoise(in vec3 p) {
vec3 c = floor(p);
vec3 l = fract(p);
l *= l * (3.0 - 2.0 * l);
float ldb = Hash31(c);
float rdb = Hash31(c + vec3(1.0, 0.0, 0.0));
float lub = Hash31(c + vec3(0.0, 1.0, 0.0));
float rub = Hash31(c + vec3(1.0, 1.0, 0.0));
float ldf = Hash31(c + vec3(0.0, 0.0, 1.0));
float rdf = Hash31(c + vec3(1.0, 0.0, 1.0));
float luf = Hash31(c + vec3(0.0, 1.0, 1.0));
float ruf = Hash31(c + 1.0);
return mix(mix(mix(ldb, rdb, l.x), mix(lub, rub, l.x), l.y),
mix(mix(ldf, rdf, l.x), mix(luf, ruf, l.x), l.y),
l.z);
}
// Hairy looking noise
float hnoise(in vec3 p, in float scale, in float octaves) {
p *= scale;
float value = 0.0;
float nscale = 1.0;
float tscale = 0.0;
for (float octave=0.0; octave < octaves; octave++) {
// Magic numbers
p.xz *= mat2(-0.48406725864, -0.87503079323, 0.87503079323, -0.48406725864);
p.yz *= mat2(0.15022546991, -0.98865176285, 0.98865176285, 0.15022546991);
value += abs(snoise(p) * 2.0 - 1.0) * nscale;
tscale += nscale;
nscale *= 0.25;
p *= 2.0;
}
return value / tscale;
}
// Tile patterns
float tile1(in vec2 cuv) {
float e = dot( cuv, vec2(0.71));
return min(abs(max( max(cuv.x, cuv.y), e + 0.2)), abs(max(-min(cuv.x, cuv.y), 0.2 - e))) - 0.025;
}
float tile2(in vec2 cuv) {
return abs(abs(dot(cuv, vec2(0.71))) - 0.355) - 0.02;
}
void mainImage2(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y ;
//uv[0]=uv[0]*(1.0-uv[1]);
float unit = 10.0 / iResolution.y;
vec3 color = vec3(0.0);
uv *= 5.0;
vec2 cid = floor(uv);
vec2 cuv = fract(uv) - 0.5;
float h21 = Hash21(cid);
cuv = Rotate(cuv, floor(h21 * 4.0) * 1.57);
float d = h21 < 0.5 ? tile1(cuv) : tile2(cuv);
color.gb += vec2(0.25 + 0.25 * sin(uv.x + uv.y - iTime), 1.0) * smoothstep(unit, 0.0, d);
color.b += 0.5 * sin(d * 100.0);
color *= pow(1.0 - hnoise(vec3(uv, iTime), 1.0, 5.0), 3.0) * 2.0;
fragColor = vec4(color, 1.0-uv[1]);
}
void mainImage(out vec4 fragColor, in vec2 fragCoord) {
vec2 uv = (fragCoord - 0.5 * iResolution.xy) / iResolution.y ;
//uv[0]=uv[0]*(1.0-uv[1]);
const float baseScale = 0.2;
const float firstBand = 0.08;
const float bandScale = 0.74;
float band = log((iResolution.y - fragCoord.y) / firstBand) / log(1.0 + bandScale);
float scale = baseScale * pow(bandScale, band);
float xCoord = (fragCoord.x - (iResolution.x / 2.0)) * scale;
float yCoord = (fragCoord.y - (iResolution.y / 2.0)) * scale;
float unit = 10.0 / iResolution.y;
uv[0]=xCoord;
uv[1]=yCoord;
mainImage2(fragColor,uv*iResolution.xy*0.72);
fragColor*=max(0.0,1.0-uv[1]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment