Rendering with smooth normals

In sample6, the mesh rendered is rendered in a faceted way, as if the normals aren’t smoothed across the surface. How could I go about changing that, so it renders in a smooth way?


Smoothing is done with vertex normals. If you look in the .obj file that specifies the cow in Sample 6, you will see that it does not contain any vertex normal data. You can replace cow.obj with a different .obj file that has vertex normal data, and you will see a smooth shape.

You can also edit the program to create your own vertex normals. This won’t look perfect, but you can get close by making each vertex normal be the average of the normals of the adjacent faces.

ok, I actually hadn’t checked if the obj file contained normals. I just assumed it did. However, my question still stands. I now created an obj file of a sphere with normals, which when rendered in sample6 looks faceted and in Maya it looks smooth. So, I still wonder what the difference is?

Looking into the code, that would be a bug in the mesh loader for the OBJ format.
The OptiX mesh loader doesn’t handle faces with relative (negative) indices for texture coordinates and normals corectly, only for vertex indices. The assigned intersection program in uses the geometric normal if no normals are given or if any of the normal indices is negative.
The rendering looks smooth with models where all indices are given as absolute indices (positive one-based) into the resp. pools.
Some facetting will be visible at the border between lit and shadowed polygons on low resolution meshes with singular lights.

You should be able to fix that yourself locally as well. In sutil/MeshBase.cpp three lines inside the function void MeshBase::loadDataFromObj( const std::string& filename ) need to be changed in the case ‘f’:
Look for if (uses_normals) and change the code using the NEWEST_INDEX macro to look similar to code in the if (uses_vertices) directly above each of them, just using n and normals_index. That should do it.

Awesome :-)

I changed it and now it works. Thanks.