Jump to content
  • Advertisement
Sign in to follow this  
ic0de

OpenGL pre-computed surface normals?

This topic is 2590 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

I have some questions about surface normals specifically in OpenGL,

Do normals have to be calculated on the fly or can they be calculated beforehand and stored with the vertex data in a model file?

Since i'm loading them from a file and not computing them during run-time, is there any program or web applet that can calculate surface normals for me?

Is there such thing as a vertex normal (can each vertex have specific lighting properties)?

If I do indeed need to calculate them on the go is there an API or an algorithm I can use for them?

thanks in advance for anybody who can answer these smile.gif

Share this post


Link to post
Share on other sites
Advertisement

Do normals have to be calculated on the fly or can they be calculated beforehand and stored with the vertex data in a model file?


They can be computed pretty much anywhere. At model authoring time, in a separate asset compilation step, at model load time, or even at rendering (with the assist of a geometry shader) if the model deforms. The best method is to let the artist author these, that allows the artist to define the normals at a very fine detail, and allows him/her to create hard and soft edges, and anything in between.



Since i'm loading them from a file and not computing them during run-time, is there any program or web applet that can calculate surface normals for me?



If you are already loading the normals from file, it's the fastest method, since you are not doing any computations yourself. Why do you want to change this?




Is there such thing as a vertex normal (can each vertex have specific lighting properties)?



Yes. You can specify a normal vector for a surface (i.e. a triangle or a plane), but you can also specify a normal vector for an individual vertex. In fact, this is what the GPUs use. The vertex buffers store per-vertex normals and not per-triangle normals. This allows fine control over the lighting, and the creation of hard and soft edges.


If I do indeed need to calculate them on the go is there an API or an algorithm I can use for them?


You can compute the vertex normals manually, but I recommend having the artist export them from the modelling package, since that is more flexible. Manual generation of vertex normals using an algorithm can not allow the artist to have "an artistic effect" on the model lighting, and hard edges and soft edges need to be inferred by heuristic means, e.g. by setting a threshold for the angle between adjacent triangles.

If you still want to manually generate the vertex normals from scratch, For an algorithm on how to generate vertex try searching previous GameDev forum posts, the procedure has been discussed several times.

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!