Robomoo
Robomoo

Reputation: 57

How is normal data usually stored?

This is quite a basic question. I'm learning about 3D graphics and lighting at the moment and I was wondering about how normal data is (normally) stored.

Is it standard to keep this data as part of any external 'model' file you load into your program, or to compute normal data anew from vertex data each time a new model is loaded? Or are there advantages to both methods and they are sometimes used for different reasons?

Upvotes: 3

Views: 582

Answers (3)

Reto Koradi
Reto Koradi

Reputation: 54602

In the general case, this is not just a performance consideration. The normals are part of the model, and cannot be thrown away and re-generated from the vertex positions.

Picture a typical case where you build a shape in a modelling program. The internal data describing the shape in the software most likely consists of analytical surfaces, e.g. spline surfaces. When you export the shape to a vertex based format, the analytical surface is approximated by a triangle mesh. The vertices of the mesh will be written out as vertex positions, along with connectivity information that defines how the vertices form a mesh. The normals of the analytical surface at the vertex position will be calculated for each vertex, and written out along with the vertex positions.

If you have a mesh of vertices without normals (e.g. because you never exported normals, or you discarded them), you can still calculate surface normals. This is typically done by averaging the face normals of all faces adjacent to the each vertex, possibly as a weighted average that takes the area or angle of the face into account. But no matter how this calculation is done, the result is an approximation of the normals of the original analytical surface.

The difference between using exact normals from the original analytical surface and using approximated normals reconstructed from the triangle mesh can be very visible when rendering. It will depend heavily on how fine the tessellation is, and on what lighting model is used. But in most cases, reconstructed normals are not as good as the normals from the original model, and the rendered surface will look much smoother/cleaner if the original normals are used.

Upvotes: 1

ratchet freak
ratchet freak

Reputation: 48206

opengl allows several attributes about each vertex when sending to the GPU for processing, most commonly used for this is position, normals and texture mappings

the most basic of all model filed (the obj file) allows the choice of whether to include the data at all. But for most more complicated models the normals aren't standard and require storing in the model files

Upvotes: 1

Bartek Banachewicz
Bartek Banachewicz

Reputation: 39380

This, as always in graphics, depends.

If you have a simple model, it shouldn't be a problem to recompute the normals. Storing them is basically caching, then.

If you use per-pixel lighting, however, normals are stored per-pixel in normal (bump etc) maps. In this case they typically can't be generated procedurally (they are generated from models with higher poly count).

Upvotes: 2

Related Questions