# Lighting algorithm

Hi

Looking here

http://www.lighthouse3d.com/tutorial.../point-lights/

I can see that to get the light direction you need to use the formula

“light direction = light position – vertex position”

The text following this says

“Before we can compute this vector we must apply the View Model matrix (m_viewModel in the shader) to the vertex position.”

The vertex position would not be calculated from the viewModel matrix it would be calculated from the model matrix only.

This tutorial uses the model matrix as I would expect but then has other logic to work out the spec light

https://learnopengl.com/#!Lighting/Basic-Lighting

Can someone say if there is a typo in the first formula or if there is something basic that I haven;t understood which would explain it and also what the difference is between the two tutorials?

Any help would be much appreciated.

(Also posted the same question on opengl.org)

Both tutorials are correct. The difference is just the coordinate system, space or “frame of reference” in which the lighting computation is performed.

The lighthouse3d tutorial does it in view/camera/eye-space, as it says:
“It is assumed that the light’s position is in camera space. Once we move the vertex position to the same space, the direction computation is straightforward”
and then comes the formula which you also quoted.

The learnopengl.com tutorial does it in world-space, which is also correct. Just another frame of reference, as it says:
“We’re going to do all the lighting calculations in world space so we want a vertex position that is in world space. We can accomplish this by multiplying the vertex position attribute with the model matrix only (not the view and projection matrix) to transform it to world space coordinates.”

One additional info: In the fixed-function pipeline of OpenGL, lighting was computed in view-space (when setting the light’s position, it was always immediately transformed into view-space via the modelview matrix). So, that’s probably the reason why that shader tutorial on lighthouse3d also did it in view-space, because they might have wanted to not break with well-known behaviour of OpenGL when bringing people from the FFP to shaders.

Thanks for the quick reply KaiHH, I missed the bit about the light position being in camera space so the formula makes a whole lot more sense now and the difference between the two is clear. I think I like the world space method better