Jump to content
  • Advertisement
Sign in to follow this  
Andre Rogers

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

This topic is 829 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!