2

I'm currently experimenting with OpenGL ES 1.1 on the iPhone and trying to get my head around some of the basics. So far I've managed to draw a grid of objects which are lit with one GL_LIGHT. Here is a screenshot of the current output (question to follow)...

enter image description here

So you can see that my test consists of a grid of about 140 cubes - some slightly elevated so I can see how the shaded areas work. Each cube consists of this model (from Blender) and have normals / texture coordinates...

enter image description here

What's puzzling me, is why I don't get a 'uniform' lighting across the entire surface. Each cube seems to be lit individually and I can kind of understand why that would be... but is it not possible to have the light transition 'normally' like it would if you arranged this model out of blocks and shone a light across it. I'd expect to not see a dark edge on each individual cube, but rather a smooth transition across the whole area.

(I'm still inwardly chuffed that I managed to get this far!)

Any help or explanations would be awesome. Thanks, Simon

Simon
  • 8,981
  • 2
  • 26
  • 32

1 Answers1

2

The reason why you don't get 'uniform' lighting is because I presume you are using per vertex lighting. That is the lighting is calculated per vertex and interpolated over each triangle making up the model. Since your cube has a pretty low polygon count the transition of light across the model won't look smooth.

Using OpenGL ES 1.1 there are two solutions to this. You can use higher polygon count models or implement per-pixel (DOT3) lighting. I've not implemented this myself but have come across this problem before (my solution was to switch to OpenGL ES 2.0 and use shaders to perform per-pixel lighting).

Here is a link, which may be of use: What is DOT3 lighting?

All the best!

Community
  • 1
  • 1
Brett
  • 2,635
  • 22
  • 35
  • Thanks for the explanation. It makes sense really. OpenGL can't possibly know about my intent, so it does what it can given the parameters I feed it. I'd already thought that the polygon count would help, having already tried an even lower poly model before (where OpenGL only lights the corner!). – Simon Sep 28 '11 at 19:54
  • Just to confirm for others having this 'issue', DOT3 lighting does indeed smoothen it out a bit but I expect higher poly count will be a better option in combination. – Simon Sep 28 '11 at 19:57