Hi, community!
Here’s an example of using the parameters (n, d) of a plane in shaders to find the distance from a point to the plane and do some funny stuff with the result
A picture of funny stuff:
If someone didn’t get what’s on the picture, it’s Anubis (a god of the Ancient Egypt).
Why Anubis?. Warning! Watching this video can damage your brain!
As I don’t know how to work with modelling software, I modelled all the scene manually, using only codepen’s editor So you can see my mad skillz
Here is a working example:
All the trick is in this part of the fragment shader:
if (dot(worldPosition.xyz, divisorPlane.xyz) > divisorPlane.w){
float dist = dot(worldPosition.xyz, divisorPlane.xyz) + divisorPlane.w;
float stripes = sin(dist * 3.1415926 - time * 3.1415926 * 2.) * 0.5 + 0.5;
gl_FragColor.xyz = mix(gl_FragColor.grb, stripeColor, step(stripes, 0.5));
}
divisorPlane
, stripeColor
and time
are uniforms.