Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

At the moment i'm using .obj file format to store 3D models. It's popular, easy to read and parse. The issue is that it stores sufrace normals for each face. This isn't an issue for me yet, but i'm keeping in mind that i have to deal with lights once i'm done with the basics of my engine. This will require vertex normals and not surface normals. I want to avoid vertex multiplication and i want nice, curved surfaces. Blender seems to be unable to store vertex normals, only sufrace normals, is this typical of 3D rendering software and file formats?

Now i'm still kind of bad at profiling and i lack experience of what's "standard", but still i want to write effective code and i can't benchmark my ideas, so please excuse me asking weird questions here.

Is it "normal" to load surface normals from the .obj file and then for each vertex do an average of all the surface normals of surfaces that use this vertex (f.e. a plane "f " in .obj says vertex of index "i" has some normal "n", so i averate this normal "n" with the one already stored for this vertex)? This seems like such an expensive calculation to do when loading a model, is this the right way to think about it? Or is there a better way (or a file format/3D editor) to deal with this issue. Having multiple normals per vertex means that i have to duplicate vertices which is out of the question, not to mention that i'd get flat shading.

I'm mostly asking this because it seems illogical that a 3D model would be stored with surface normals that are very easy to calculate and not vertex normals which aren't easy to calculate and which are required for realistic lighting. Maybe it's a "legacy" thing?


Also, while we're on the subject, how do people deal with surfaces that have to be flat planes like a brick? For light calculations these models need vertices normals to be surface normals. but if i had a model like a knife that would consist of the blade that needs to be flat and the handle that i want round i would have to have the blade with duplicate vertices and the handle with not duplicate vertices which seems like a weird thing to request from my 3D softare (if it's even possible).

How do people deal with it, the only "smart" idea i can think of is to do separate models for flat objects (that would be stored in an innefficient way with vertex copies instead of indices) and separate models for round objets that would use the averating described above. The other idea is to have a program with a geometry shader in case i want to render a flat surface that would calculate a surface normal and set each vertex's normal to the one calculated and pass that to the fragment shader (though the extent of my geometry shader knowledge is a short article, haven't used them yet, is this even possible in OpenGL?).

I feel like i'm trying to brute force the issue, maybe there's a "magic" math trick that could help me or am i just stuck with more models or shader programs to manage.

share|improve this question

1 Answer 1

up vote 5 down vote accepted

Pretty much every mesh file format includes vertex normals, including .obj. If you're not getting vertex normals, then it would likely be because of how you're exporting the mesh, not the file format.

share|improve this answer
    
though, aren't these vertex normals face normals? when you look at a .obj file you'll get something along the lines "f 47//1 1//1 3//1", this information contains the indices and normals for the indices, however the same indices can have different normals in the same file, because they form a different face, this is my issue, i can't have multiple normals assigned to a single vertex, it's not feasible to use this information for rendering, i'm just wondering if i can somehow force the popular modeling software to write the proper vertex normals to a file –  dreta May 5 '12 at 22:55
    
@dreta: Blender is perfectly capable of writing vertex normals. I don't use .obj files myself, but the COLLADA documents I export use vertex normals just fine. Perhaps you should ask a question about how to get Blender to generate vertex normals, not one about the .obj format. –  Nicol Bolas May 5 '12 at 23:01
    
for example, the Suzanne model exported from Blender to .obj contains these two lines "f 259//221 257//221 239//221" and "f 261//241 257//241 259//241" as you can see the vertex number 259 has two normals, 241 and 221, also as you can see, each vertex set that forms a face has the same normal –  dreta May 5 '12 at 23:02
    
sounds reasonable, i just wanted to confirm that, because when i look for .obj models, they all have the same "issue" –  dreta May 5 '12 at 23:04
3  
@dreta please don't feel like an idiot; debugging data problems is a valuable skill that anyone working on content pipelines like you are should know. Now you're one step ahead. –  Patrick Hughes May 5 '12 at 23:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.