Skip to content

Instantly share code, notes, and snippets.

@lunasorcery
Created August 15, 2018 21:35
Show Gist options
  • Save lunasorcery/6e8fe226982fa18998a796ae72a7ad68 to your computer and use it in GitHub Desktop.
Save lunasorcery/6e8fe226982fa18998a796ae72a7ad68 to your computer and use it in GitHub Desktop.
#version 410 core
uniform float fGlobalTime; // in seconds
uniform vec2 v2Resolution; // viewport resolution (in pixels)
uniform sampler1D texFFT; // towards 0.0 is bass / lower freq, towards 1.0 is higher / treble freq
uniform sampler1D texFFTSmoothed; // this one has longer falloff and less harsh transients
uniform sampler1D texFFTIntegrated; // this is continually increasing
uniform sampler2D texChecker;
uniform sampler2D texNoise;
uniform sampler2D texTex1;
uniform sampler2D texTex2;
uniform sampler2D texTex3;
uniform sampler2D texTex4;
#define iTime fGlobalTime
layout(location = 0) out vec4 out_color; // out_color must be written in order to see anything
float height(vec2 uv)
{
float curve = smoothstep(1,0,length(uv)) * .5;
float sinus = 0;
//sinus += sin(uv.x*30.+iTime*20.);
//sinus += sin(uv.y*30.+iTime*20.);
sinus += .8-length(fract(uv*6.+iTime*4.)-.5);
//sinus = sinus * .25 + .5;
return curve * sinus;
}
float funnysphere(vec3 p)
{
p.y *= 1.5;
vec3 n = normalize(p);
vec2 sg = p.xz / (1. + p.y);
float offset = length(fract(sg*6.+iTime*4.)-.5)*.35;
return length(p+vec3(0,.4,0))-1. + offset;
}
float _smin( float a, float b, float k )
{
float res = exp( -k*a ) + exp( -k*b );
return -log( res )/k;
}
float smin( float a, float b)
{
return _smin(a,b,25.);
}
float metaballs(vec3 p)
{
p -= vec3(0,.65,0);
vec3 p0 = p + sin(vec3(2.13, 2.17, 2.37)*iTime)*.2;
vec3 p1 = p + sin(vec3(2.15, 2.87, 2.57)*iTime)*.2;
vec3 p2 = p + sin(vec3(2.11, 2.47, 2.97)*iTime)*.2;
return smin(
smin(
length(p0)-.13,
length(p1)-.13
),
length(p2)-.13
);
}
float scene(vec3 p)
{
float a = metaballs(p);
return smin(
smin(
p.y,
funnysphere(p)
),
metaballs(p)
);
float scale = pow(.3,p.y);
return p.y - height(p.xz * scale);
return length(p)-1.;
}
vec2 rotate(vec2 a, float b)
{
float c = cos(b);
float s = sin(b);
return vec2(
a.x * c - a.y * s,
a.x * s + a.y * c
);
}
float sawtooth(float x)
{
x *= 10.;
return (fract(x)+fract(x*1.337))/2.;
}
void main(void)
{
vec2 uv = vec2(gl_FragCoord.x / v2Resolution.x, gl_FragCoord.y / v2Resolution.y);
uv -= 0.5;
uv /= vec2(v2Resolution.y / v2Resolution.x, 1);
#if defined(CHROMAB)
for(int c =0; c < 3;++c)
{
#endif
vec3 cam = vec3(0,0,-5);
vec3 dir = normalize(vec3(uv, 4));
cam.xz = rotate(cam.xz, iTime*.2);
dir.xz = rotate(dir.xz, iTime*.2);
cam.y = .45;
//dir.y = -abs(dir.y);
float t = 0.;
int i = 0;
for (i = 0; i< 100; ++i)
{
float k = scene(cam + dir * t);
t += k * .3;
if(k < .001)
break;
}
float iter = 1.-float(i)/100.;
vec3 h = cam + dir * t;
vec2 o = vec2(.001, 0);
vec3 n = normalize(vec3(
scene(h+o.xyy)-scene(h-o.xyy),
scene(h+o.yxy)-scene(h-o.yxy),
scene(h+o.yyx)-scene(h-o.yyx)
));
float fresnel = pow(1.-max(0.,dot(n,-dir)),5.)*.96+.04;
//fresnel += pow(max(0.,dot(n,-dir)),30.)*.96+.04;
#if defined(CHROMAB)
out_color[c] = fresnel;
#else
out_color = vec4(fresnel);
#endif
//out_color -= step(.1,fract(h.x*4.))*.2;
//out_color -= step(.1,fract(h.z*4.))*.2;
/*out_color = mix(
vec4(0,1,1,0),
vec4(1,0,1,0),
out_color//fract(out_color+iTime)
);*/
#if defined(CHROMAB)
uv *= 1.02;
}
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment