Pre-calculating the normals, ways to do it? C++, OpenGL 4

Started by
0 comments, last by dpadam450 7 years, 8 months ago
Given that I need to perform
Normal = mat3(transpose(inverse(model))) * normal;
this per vertex normal to efficiently render a model. My current scenario, is that I am importing a model via assimp, and loading it into a vertex and element buffer object. Having now built the VAO how do I update the normals before I bind the model to be rendered.
Do I have to use glBufferSubData or glMapBuffer? Is there a simpler solution where I can isolate the model's normals from the rest of the model's VAO within another VAO and use both attribute objects to render the model? Could I maybe create a texture with the pre-calculated normals and pass that?
Am not sure what to do here, any help would be appreciated.
Advertisement

how do I update the normals before I bind the model to be rendered

You never update the normals. They are calculated offline based on the surface, not based off of any view/model matrix. Normals represent the surface when you talk about calculating them. What you are talking about is strictly transforming them, which is the same as a vertex. The inputs stay the same, the outputs change relative to the camera view.

Your vertex shader should output a new normal every frame, by taking OutputNormal = normalMatrix*in_normal;

normalMatrix should be computed once and sent down. The normal matrix is simply the same as the model matrix (minus translation) if you have no non-uniform scaling (IE scaling is fine as long as it is equal across x,y and z). Otherwise the normal matrix is what you have, and should again be computed only once. So don't compute it if you don't need to.

FYI: The inverse of a 3D rotation matrix (no scaling applied to the model) ... inverse = transpose. So in the case of no scaling on your matrix. You are simply transposing the model matrix twice, which gives you the model matrix as the result anyway.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

This topic is closed to new replies.

Advertisement