
This is a small project of a ray-marching shader written in GLSL.
Ray Marching is a rendering technique like ray tracing or rasterizing where you throw a ray and evaluate the distance to the object with a SDF (signed distance function).
-1 : you touch the object, 0 it's on the surface and 1 you are outside.
Code
For this you need some signed distance functions, here is one for a sphere:
float sphereSDF(vec3 pos, vec3 origin, float radius)
{
return length(pos + origin) - radius;
}
Then for each ray in the view frustrum, we compute the closest point in the scene and if it touches we estimate it's normal and shade it accordingly.
All the references can be found in articles by Inigo Quilez on his website.
Then it's just a matter of animating and combining signed distance functions to make complex shapes! (using Constructive Solid Geometry)
Editor
To write and debug GLSL code, it's quite difficult.
That's why I used SHADERed, which is an open source shader editor:
