BLOKS Shader Bulletin Board
Memory Foam Universe
Shader Preview Unavailable
This realtime shader may be too intensive for your current device or browser.
Shader Code
float hash(vec2 p)
{
return fract(
sin(dot(p, vec2(127.1,311.7)))
* 43758.5453123
);
}
float noise(vec2 p)
{
vec2 i = floor(p);
vec2 f = fract(p);
vec2 u =
f*f*(3.0-2.0*f);
return mix(
mix(hash(i),
hash(i+vec2(1,0)),u.x),
mix(hash(i+vec2(0,1)),
hash(i+vec2(1,1)),u.x),
u.y
);
}
float fbm(vec2 p)
{
float v = 0.0;
float a = 0.5;
for(int i=0;i<5;i++)
{
v += a*noise(p);
p *= 2.0;
a *= 0.5;
}
return v;
}
void mainImage(
out vec4 fragColor,
in vec2 fragCoord
)
{
vec2 uv =
(2.0*fragCoord-iResolution.xy)
/ iResolution.y;
vec2 mouse =
(2.0*iMouse.xy-iResolution.xy)
/ iResolution.y;
if(iMouse.z<=0.0)
{
mouse =
vec2(
sin(iTime*0.15),
cos(iTime*0.12)
)*0.5;
}
float d =
length(uv-mouse);
float dent =
exp(-d*6.0);
float ripple =
sin(
d*30.0
- iTime*4.0
);
ripple *= dent;
vec2 flow =
uv
+ normalize(
uv-mouse
)*ripple*0.03;
float n =
fbm(flow*4.0);
float stars =
smoothstep(
0.82,
1.0,
n
);
vec3 col =
vec3(
0.02,
0.05,
0.12
);
col +=
vec3(
0.1,
0.4,
1.0
)*dent*0.7;
col +=
vec3(
0.3,
0.7,
1.0
)*abs(ripple)*0.2;
col +=
vec3(1.0)
* stars;
float vignette =
smoothstep(
1.4,
0.1,
length(uv)
);
col *= vignette;
fragColor =
vec4(col,1.0);
}
