Hi there Plamuro,

At line 14 the ‘rayDirection’ vector is set to a vector from rayStart to rayStop (so for example if rayStart is 1,0,0… and rayStop is 1,5,0, the rayDirection would be 0,5,0) (3 numbers since its a vec3 (x y and z))

Then line 16, normalizing a vector means making the length of the vector 1. In our case the length is 5 (0,5,0). So this becomes 0,1,0. In other words you can see it as pythagoras: normalize(vector) = sqrt(vector.x*vector.x + vector.y*vector.y + vector.z*vector.z)

Then this vector is being multiplied with uStepSize. Since the length of the normalized vector 1, multiplying this vector with some scalar (uStepSize) will just change the length of the vector to uStepSize. So you can see ‘step’ as being a vector pointing to the right direction but having a length of uStepSize.

Then in line 22 a ‘for’-loop starts. Check out python ‘for’-loops first if you dont feel you understand this loop thingie. It’s similar in most programming languages and comes down to loop MAXSTEPS times and increasing i by 1 every iteration.

The line 30 ‘break’ statement is used only in these kind of loops and means to jump out of the loop. So if density > uThreshold then break out of the loop (even if i is < MAXSTEPS).

To jump back to line 25. What it does (in combination with the loop) is it starts at ‘rayStart’, adds ‘currentStep’ to it (which is 0,0,0 in the first iteration). Sampling the density from the texture and then in line 34 it adds the ‘step’ vector we just calculated (ray direction & length of uStepSize).

So in other words it ‘walks’ or ‘marches’ over the ray/line from rayStart towards rayStop with ‘uStepSize’ steps. Tests if a certain density is reached, if so it breaks the loop.

It can be a bit confusing at first with doing math with vectors (linear algebra). A very good introduction to the topic is the course of 3blue1brown. (https://www.youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab)

Hope this helps.

Cheers,

tim