1

I'm currently learning lighting in OpenGL and was reading learnopengl.com when I noticed that they calculated the direction of the light (diffuse lighting) by subtracting the light position to the fragment position: vec3 lightDir = normalize(lightPos - FragPos); (I've attached an image to show what this would look like) Direction Vector Image

Why would they get a vector that points from the Fragment position to the light position? If they want to get the light direction, wouldn't we want to get a vector from the light position to the fragment position: vec3 lightDir = normalize(FragPos - lightPos);

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
OpenGLUser
  • 11
  • 1
  • 2
    The diffuse light is calculated by the [Dot product](https://en.wikipedia.org/wiki/Dot_product) of the normal vector and the vector form the surface to the light source. See [How does the calculation of the light model work in a shader program?](https://stackoverflow.com/questions/7061745/how-does-the-calculation-of-the-light-model-work-in-a-shader-program/45121641#45121641) – Rabbid76 Nov 14 '21 at 20:19

1 Answers1

0

The diffuse light is calculated by the Dot product of the normal vector and the vector form the surface to the light source. See How does the calculation of the light model work in a shader program?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174