Why lighting appears on opposite side?

前端 未结 1 485
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-27 22:52

I am trying to build lighting using this tutorial. However, lighting appears on wrong side of human object and I do not know why.

Normals were created per triangle. Vert

相关标签:
1条回答
  • 2021-01-27 23:26

    I think the cause of your problem is that you are not applying your model transformation to your normal vectors. Since you definitely do not want to skew them, you will have to create a special matrix for your normals.

    As is explained further down the tutorial that you mentioned, the matrix can be constructed like this

    Normal = mat3(transpose(inverse(model))) * aNormal;
    

    in your vertex shader. However, I highly recommend that you calculate the matrix in your application code instead, since you would calculate it per vertex in the above example. Since you are using the glm library, it would look like this instead:

    glm::mat3 model_normal = glm::mat3(glm::transpose(glm::inverse(model)));
    

    You can then load your new model_normal matrix into the shader as a uniform mat3.

    0 讨论(0)
提交回复
热议问题