# GLSL lecture(vincent houze) question

around 1:29:20

I understand up to 14 line.

But I don’t understand it from 16 line

first in 16 why is ‘uStepSize’ multiplied by ‘normalize(RayDirection)’

And also why do I have to normalize?

I think I don’t know the definition of normalize

second

What does the 22nd line ‘for’ mean?

third

In line 25 Why dose He add ‘rayStart’ and ‘currentStep’?

Fourth

What exactly is the meaning of the 30th line ‘BRAEK’?

Fifth

I don’t understand the calculation of the 34th. Maybe it’s because I don’t understand from above.

I’m still not used to glsl.

Thanks again for anyone that helps.

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.xvector.x + vector.yvector.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. (Essence of linear algebra - YouTube)

Hope this helps.
Cheers,
tim

2 Likes