// ESCAPE THROUGH SUBSPACE 1K by Seven/Fulcrum
// -------------------------------------------
float f, // the number of steps we have marched so far.
x=270*gl_Color.x-3, // we are abusing glColor to pass a time value. x=0 is the moment the spaceship starts to appear.
z=0, // the distance that we have marched in the main loop, starts at 0
n, // temp variable for a fractal
m, // distance from the ships *hull*. Will be negative inside the hull. For coloring the ship green and the warp effect purple
r; // another temp variable for a fractal
// The distance function.
float e(vec3 t)
{
t+=vec3(-.4,.9,x-9); // The camera motion. The camera moves in a straight line.
m=9; // Start distance, initialized to a large enough value.
// Calculate the shape of the ships hull. It is one big saucer, with two smaller saucers as the superstructures,
// with four smaller saucers as the engines etc.
vec3 v=t; // temporary coordinate that will be mutilated by the fractal calculation
for(float f=0;f<4;f++) // Always use the same control variable in your for loops, if possible.
{
v.yx=abs(v.yx); // mirror around the x and y axis. This will also double the amount of saucers in each new pass
m=min(m, // the hull is the union of all saucers
pow(.6,f)* // Each new copy of the saucer should be smaller than the previous
(length(v+vec3(3,19,1))-20)); // This is a big off-center sphere. Due to the mirroring, we get a big saucer.
v=1.6*v // compensate the 0.6 scaling so the distance formula is kept valid
-vec3(2.7,.8,4); // move each new saucer a bit more off-center and towards the rear of the ship.
v.yx=vec2(.6*v.y+.8*v.x,-.8*v.y+.6*v.x); // rotate the saucers so they almost alternate between horizontal and vertical
}
// speed optimisation: if we're not close to the hull, don't bother intersecting with the fractal.
if(.01