Untitled
unknown
plain_text
a year ago
3.7 kB
8
Indexable
precision mediump float;
uniform float iTime;
uniform vec2 iResolution;
float Pi = 6.28318530718; // Pi*2
// GAUSSIAN BLUR SETTINGS {{{
float Directions = 16.0; // BLUR DIRECTIONS (Default 16.0 - More is better but slower)
float Quality = 3.0; // BLUR QUALITY (Default 4.0 - More is better but slower)
float Size = 64.0; // BLUR SIZE (Radius)
// GAUSSIAN BLUR SETTINGS }}}
vec2 Radius = Size/iResolution.xy;
// Normalized pixel coordinates (from 0 to 1)
vec2 uv = fragCoord/iResolution.xy;
// Pixel colour
vec4 Color = texture(iChannel0, uv);
float opSmoothUnion( float d1, float d2, float k ) {
float h = clamp( 0.5 + 0.5*(d2-d1)/k, 0.0, 1.0 );
return mix( d2, d1, h ) - k*h*(1.0-h);
}
float sdSphere( vec3 p, float s ) {
return length(p) - s;
}
float map(vec3 p) {
float d = 2.0;
for (int i = 0; i < 6; i++) {
float fi = float(i);
//fast
// float time = iTime * (fract(fi * 412.531 + 0.513) - 0.5) * 2.0;
float time = iTime * (fract(fi * 412.531 + 0.513) - 0.5) * 0.6;
d = opSmoothUnion(
sdSphere(p + sin(time + fi * vec3(52.5126, 64.62744, 632.25)) * vec3(2.0, 2.0, 0.8), mix(0.5, 1.0, fract(fi * 412.531 + 0.5124))),
d,
0.4
);
}
return d;
}
vec3 calcNormal( in vec3 p ) {
const float h = 1e-5; // small offset for gradient calculation
//1, -1
const vec2 k = vec2(1,-1);
return normalize( k.xyy*map( p + k.xyy*h ) +
k.yyx*map( p + k.yyx*h ) +
k.yxy*map( p + k.yxy*h ) +
k.xxx*map( p + k.xxx*h ) );
}
void mainImage( out vec4 fragColor, in vec2 fragCoord ) {
vec2 uv = fragCoord / iResolution.xy;
// vec3 rayOri = vec3((uv - 0.5) * vec2(iResolution.x / iResolution.y, 1.0) * 6.0, 3.0);
// vec3 rayDir = vec3(0.0, 0.0, -1.0);
vec3 rayOri = vec3((uv - 0.5) * vec2(iResolution.x / iResolution.y, 1.0) * 2.0, 1.5);
vec3 rayDir = vec3(0.5, 0.2, -1.0);
float depth = 0.0;
vec3 p;
for(int i = 0; i < 32; i++) {
p = rayOri + rayDir * depth;
float dist = map(p);
depth += dist;
if (dist < 1e-6) {
break;
}
}
depth = min(6.0, depth);
vec3 n = calcNormal(p);
float b = max(0.0, dot(n, vec3(0.577)));
vec3 col = (0.5 + 0.5 * cos((b + iTime * 3.0) + uv.xyx * 2.0 + vec3(0,2,4))) * (0.85 + b * 0.35);
col *= exp( -depth * 0.3 );
vec3 color = vec3(0.15, b * 1.0, 1.0 );
color *= exp( -depth * 0.3);
vec3 baseColor = vec3(0.3647, 0.5176, 0.9255);
vec3 shadedColor = baseColor * b;
vec4 metaballs = vec4( color , 1.0 - (depth - 0.5) / 2.0)
// shadedColor *= exp( -depth * 0.3 );
// BLUR
// Blur calculations
for( float d=0.0; d<Pi; d+=Pi/Directions)
{
for(float i=1.0/Quality; i<=1.0; i+=1.0/Quality)
{
Color += texture( iChannel0, uv+vec2(cos(d),sin(d))Radiusi);
}
}
// Output to screen
Color /= Quality * Directions - 15.0;
fragColor = Color;
fragColor = metaballs + Color;
}
void main() {
mainImage(gl_FragColor, gl_FragCoord.xy);
}Editor is loading...
Leave a Comment