1. Hey! Guest! The 36th GMC Jam will take place between February 27th, 12:00 UTC - March 2nd, 12:00 UTC. Why not join in! Click here to find out more!
    Dismiss Notice

GM:S 1.4 How do Normal Vectors affect lighting?

Discussion in 'Programming' started by DekuNut, Dec 10, 2018.

  1. DekuNut

    DekuNut Member

    Joined:
    Jun 29, 2016
    Posts:
    40
    Code:
    d3d_model_vertex_normal_texture(m, x, y, z, nx, ny, nz, xtex, ytex);
    
    Could someone help me understand how normal vectors affect lighting on my model? I've looked through a couple tutorials and forum discussions, and they've told me how to calculate the normals, but not exactly what they will do. I understand if all my vectors are pointing up, my model will look flat. I don't know how adjusting them will affect the lighting on the model though.
     
  2. icuurd12b42

    icuurd12b42 TMC Founder GMC Elder

    Joined:
    Apr 22, 2016
    Posts:
    1,840
    each point has a vertex normal. they point in the direction, perpendicular to the plane of the facet they are the corner of... in its most simple implementation...

    upload_2018-12-10_2-40-48.png

    this tells the direction the light reflects, roughly speaking.

    upload_2018-12-10_2-46-3.png

    each point of the triangle can have it's own vector, as opposed to the entire triangle defining the reflection vector, which allows smoothing... or rounding things by smoothing the lighting..., like each vertex on the cannon has its lighting normals point outward at an angle matching round cylinder for example

    upload_2018-12-10_2-48-36.png
     
    Last edited: Dec 10, 2018
    Yal and DekuNut like this.
  3. DekuNut

    DekuNut Member

    Joined:
    Jun 29, 2016
    Posts:
    40
    Wow, thanks for the quick reply and those images were perfect. I think I understand how it works now.
     
  4. Yal

    Yal GMC Memer GMC Elder

    Joined:
    Jun 20, 2016
    Posts:
    4,214
    Generally speaking, the normal vector is the "up" direction of the plane the triangle is in. It's useful for lighting, but it's also important in collisions. For instance, the normal vector of a wall is close to horizontal, the normal vector of a floor points upwards, and the normal vector of a ceiling points downwards - so checking the z component of the normal vector can tell you how to collide with a triangle.
     

Share This Page