Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OBJ format and Flat vs Smooth Shading

I'm using OpenGL ES 1.1 and working on converting an OBJ export from Blender into some binary files containing vertex data. I actually already have a working tool, but I'm working on changing some things and came across a question.

Even with Smooth shading, it seems that with correct normals (perpendicular to the face plane) it achieves a flat appearance for faces. With Smooth shading enabled and the proper normals (simply via edges marked as sharp in Blender and an edge-split modifier applied), I can get the affect of smooth parts and sharp edges.

Where I'm going with this brings 2 questions.

  1. Are the "s 1" or "s off" lines where smooth or flat shading is denoted in the OBJ file completely unnecessary from a smooth shading and use of normals standpoint?

  2. When actually set to Flat shading in OpenGL, are normals completely ignored (or just assumed to all be perpendicular to the faces)?

like image 602
Maximus Avatar asked May 07 '11 18:05

Maximus


People also ask

When should I shade smooth in blender?

Shade Auto Smooth This method works great for objects with both sharp and smooth areas. Selecting the Shade Flat will revert the shading back to flat; additionally, pressing Shade Smooth will disable all flat normals, making the entire object appear smooth again.

What does shade smooth do?

The appearance of the mesh edges are determined to be evened out or well defined within the 3D Viewport and render. In Edit Mode, individual faces can be selected to determine which faces are smoothed or flattened.

What is smooth shading in 3D?

Smooth shading uses linear interpolation of either colors or normals between vertices. Edges appear more pronounced than they would on a real object because in reality almost all edges are somewhat round. The edges disappear with this technique. Same color for any point of the face.

How do I make my blender shading smooth?

All you have to do is import a model in Blender (or use the default cube), right-click the object, and select “Shade Smooth”. You can switch back to the default shading mode by right-clicking on the model again and choosing “Shade Flat”.


1 Answers

For a vertex to look smooth, its normal has to be the average of the adjacent face normals (or something the like), but not perpendicular to the face plane (except if you meaned the average plane of all its adjacent faces).

GL_FLAT means, the color of a face is not interpolated over the triangle, but taken from a single triangle corner (don't know which, first or last). This color comes either from vertex colors or vertex lighting, so in fact you get per-face normals, but this is not neccessarily the faces direction, but the normal of a corner vertex.

If you got per vertex normals in the OBJ file you do not need the s parts. But you can use these to compute vertex normals. The s parts are the smoothing groups and are to be interpreted as 32bit bitfields. So there are actually 32 different smoothing groups and every face can be part of more than one. So all faces after an "s 5" line are part of smoothing groups 1 and 3 (first and third bits set). When two neighbouring faces are part of the same smoothing group, the edge between them is smooth (vertices share normals). This way you can reconstruct the neccessary per-vertex normals.

like image 174
Christian Rau Avatar answered Sep 26 '22 08:09

Christian Rau