Re:Breaking down a ripple animation in JavaScript
by kroltan on Thursday August 19, 2021 @04:00PM
(#28238622)
A plea to anyone who wants to do that, I would highly recommend running that kind of thing on the GPU! Looping through all those pixels every frame is ought to hog a lot of UI thread time otherwise, especially with big resolutions!
[ Parent
| on HN ]
Re:Breaking down a ripple animation in JavaScript
by zokier on Thursday August 19, 2021 @05:03PM
(#28239336)
very basic shadertoy shader in the spirit of the article:
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
vec2 center = iMouse.xy/iResolution.xy;
float aspect = iResolution.x/iResolution.y;
vec2 uv = fragCoord/iResolution.xy;
uv.x *= aspect;
center.x *= aspect;
float r = distance(uv, center);
float h = (sin((r*50.0)-(iTime*2.0))+1.0)/2.0;
h *= 1.0 - min(1.0, r);
fragColor = vec4(h,h,h,1.0);
}
Re:Breaking down a ripple animation in JavaScript
by tomxor on Thursday August 19, 2021 @06:42PM
(#28240274)
It's also not necessary to do such high resolutions to get smooth result with this animation due to the nature of the image. Interpolation is much faster based on a low res version, especially the hardware accelerated smooth interpolation built into the browser for canvas. My example in this thread is only 64x64 pixels but you can zoom in as much as you like and it remains fast and smooth.