I know that the Panda polygons are generally flat shaded, but is there a way to enable Gouraud shading for per-vertex lighting? I’d like to avoid resorting to something like a Phong shader, since I can’t guarantee that all of my target systems would support that.
If you specify a per-vertex normal in your egg file, rather than a per-polygon normal, your models will be Gouraud-shaded.
I am already setting the normal per vertex. When creating an EggModel from scratch, I first create the vertex array, with a position, normal, and uv assigned to each vertex. Then I create quads from four adjacent vertices.
In my current usage, the problem is actually most noticeable on flat ground surfaces reated in this manner. Obviously, a flat surface has the same normal value across the entire thing, regardless of whether I set the normal per vertex or per face. But the shading is very plainly applied per face, and is most noticeable near my point light, where the falloff affects the most. Any clues? My mesh generation code is effectively very similar to the example I posted in a previous topic: https://discourse.panda3d.org/viewtopic.php?t=1555
Am I correct to assume that generating triangles will have no different result from letting Panda generate them from my quads? I am using counter-clockwise winding, in case that matters.
Current graphics hardware calculates the lighting at each vertex, and then interpolates the color between vertices; the lighting is not computed per-pixel. Usually this looks fine, but when the lighting is changing rapidly between vertices–as when you have a point light very near a large plane with few vertices–it looks terrible.
The solution is to subdivide your plane into many more, smaller, quads.
I’m aware of the difference between per-vertex and per-pixel lighting, but this screenshot does not seem to be either one. I can’t imagine that proper per-vertex lighting ends up this terrible. Tesselating further does help a little, but each tesselation step causes an exponential increase in the number of polygons.
Hmm. You’re right, that does seem broken. Are you using the most recent version of Panda? We used to have a bug wherein the shading would be incorrectly treated as flat (per-polygon) shading on a plane in which all normals were exactly identical, but I’d thought that bug had been eliminated. It may be that it’s crept back in recently.
If this is the case, you can work around the problem by very slightly perturbing the normals on your plane.
Ahh, much better. The newer version does fix the problem. I’ll have to switch my app over to that. Thanks David.