triangulation shading problems

Hi guys,

I’ve built an app that’ll import .obj files into jogl. For whatever reason (and i’m not sure why) when i export from my modelling program of choice (3ds max) to the obj sometimes, the mesh gets converted into tri’s. So far, it’s happened when spline modelling, and sometimes it doesn’t appear to happen at all (standard primitive teapots come out just fine, and when rendered in LINES looks the same as teh in-max mesh).

The problem is, on my objects where the mesh is in tri’s, i’m getting bad shading over the mesh. The tris are interpolating between themselves, presumably, but not the tri’s next to them. You can see the problem here http://img98.imageshack.us/my.php?image=connect4lightingre6.jpg

I don’t think this is a normals problem, and i’ve got SMOOTH shading set obviously. Is there any way of changing the shading angle? Or any other ideas?

Looks like you’ve got lots of long, thin triangles - since regular lighting is only calculated per-vertex and interpolated that’s going to cause artifacts like what you’ve got there. Either change your triangulation to split things up into roughly uniform sized triangles, or switch to using per-pixel lighting.

The triangles in most cases don’t seem exceptionally long, and changing the triangulation presents kind of a problem, because i can’t expect people using the loader to try this to get it lit properly.

How would i go about doing per pixel lighting?

Thanks

They’re long relative to the change in normal from one vertex to another. For example in the center circle you’ve got triangles with vertices on both the top and bottom edges, which will have normals pointing in completely different directions. Which means that when you linearly interpolate the lighting result it causes the irregularities.

For per-pixel lighting, the easiest is probably to write a GLSL vertex and pixel shader and just do the lighting calculation in the pixel shader rather than per-vertex like you have now.

That’s probably beyond me for the time being unfortunately.

In regard to the triangulation, wouldn’t that kind of indicate that if the triangulation was denser, the problem would lessen? Only the reverse seems to be happening when i use less verts, the lighting becomes more even.