# Per fragment lighting with OpenGL 4.x tessellated model

I'm experienced with OpenGL 3+. I'm dabbling with tessellation shaders and have now got to a point where I have a nicely tessellated teapot/plane demo (quick look here)

As can be seen from the screenshots, the lighting is broken (though admittedly doesn't look too bad in the image)

I've tried to add a normal map to the equation but it still doesn't come out right, I can calculate the normals, tangents and binormals per triangle in the geometry shader but still looks wrong.

I think the question would be; How do I add per fragment lighting to a tessellated model?

The teapot is 32 16-point patches, the plane is one single 16 point patch.

The shaders are here, but they are a complete mess, so I don't blame anyone who cant make sense of them. But peruse at your leisure if you like.

Also, if this question is more suited to be somewhere else i.e. Stack Overflow or the Programming stack please let me know.

• "How do I add per fragment lighting to a tessellated model?" The same way you would for a non-tessellated model. You ought to be able to take the same fragment shader you use for a regular model and use it for a tessellated one (obviously, you need to match interfaces). If your bumpmapping is getting in the way, try it without bumpmapping. Nov 27 '12 at 21:50
• In order for me to utilize a standard fragment shading model I need smoothed normals, which are fine if I use a non tessellated model, the normals are passed as attributes to the vertex shader, then smoothed across to the fragment shader. The problem is that after tessellation, there are no normals for the new polygons. Calculating them in the geometry shader results in a faceted look, and I can't smooth them as I only have access to one triangle in the geometry shader. Nov 28 '12 at 13:01
• "The problem is that after tessellation, there are no normals for the new polygons." If you can calculate positions for the new triangles, you can calculate normals just fine too. And how are you calculating your texture coordinates? Nov 28 '12 at 15:05
• Of course I can calculate the normals, I said that already! What I cannot do is change the normal based on the surrounding normals, which results in facets (like this). texture coords come from glTessCoord, the built in variable in the tessellation evaluation shader. Nov 28 '12 at 16:30
• Are you talking about OpenGL 4.x's tessellation functionality or the old gluTess stuff? They're not at all the same, nor are they compatible. "What I cannot do is change the normal based on the surrounding normals" Then you're not calculating the vertex normals. That's what your Tessellation Evaluation Shader should be doing. Nov 28 '12 at 16:44