0

I'm working on an OpenGL project right now. I use per-vertex normals for my lighting calculations which causes them to be automatically smoothed (I think this is called gara-something shading). This beginning to work on some low-poly design using hardcoded models - but they look weird because of the auto-smoothing.

Blender has a mesh edge-split option that does exactly what I'm looking for. It turns models

from this

to this

Instead of having to rewrite my render system to allow for both per-vertex normal smooth lighting and per-face normal hard lighting, I was wondering if anyone knows how Blender's edge-split algorithm works so I can recreate it in my hardcoded models.

Using Blender I've compared normally exported .obj's with their edge-splitted counterparts and there's no way for me to fully understand the difference.

Many thanks.

haji beats
  • 11
  • 2

3 Answers3

0

That would be Gouraud shading. There's no geometry processing going on here by looks of things. It's simply a different shading model.

In OpenGL, for each triangle, you need to draw all three vertices with the same normal, this normal is the cross product of the two triangle edges. You will then see a mesh with the same flat-shading as your image.

If each vertex has its own normal, and these normals are not all equal in the triangle, OpenGL will interpolate the difference across the surface of the face producing a much smoother transition of the shading from vertex to vertex. This is smooth (gouraud shading).

So in summary, you can achieve this by changing how you draw the normals in relation to the triangles.

lfgtm
  • 1,037
  • 6
  • 19
0

I don't have enough points for a comment, so here goes an answer..

In general, I agree with lfgtm: if each vertex has 1 normal, but the vertex is shared (reused, i.e. indexed) by several triangles, then you cannot achieve a 'flat' look or have split edges because you miss the extra normals. You would have to duplicate the vertex.

But since you mention OBJ export, have you tried ticking the "Smooth groups" option in the OBJ export options:

enter image description here

This will create smoothing groups according to the edges you have marked sharp (In edit mode: Mesh -> Edges -> Mark sharp). If your engine supports these smoothing groups in the OBJ file, you will keep this sharp edge effect. You can preview these sharp edges in Blender using the Edge Split modifier (tick the "Sharp Edges" option):

enter image description here

mx1up
  • 724
  • 9
  • 15
0

Blender's edge split modifier achieves it's result by breaking the mesh, if you apply the edge split modifier you get a mesh with faces that are not connected.

What you want to look into is the difference between smooth and flat shading

shading sample

If you google "opengl flat shading" you will find several items like this one suggesting the use of glShadeModel(GL_FLAT);

Community
  • 1
  • 1
sambler
  • 6,917
  • 1
  • 16
  • 23