Opengl Es20 - Light A Cube, How To Get Normals?
Solution 1:
The issue you are facing is that you share vertices between cube faces. The normal is a vector that points othogonal to the plane of the surface.
Consider the top/right/front vertex as an example (that you share with the front, right and top faces).
When used on the front face, the normal needs to point towards you as 0, 0, 1 When used on the right face, the normal needs to point to the right as 1, 0, 0 When used on the top face, the normal needs to point up as 0, 1, 0
So how to reconcile that? You could set the normal for the vertex to point out from the corner, e.g. as 0.707, 0.707, 0.707. That'll most likely give you an interesting lighting effect on the corner but is probably not what you're after.
The other solution is not to re-use the vertices between faces. So you'll need 24 (4 per side) instead of 8. You'll then have 3 versions of each vertex but each one of those now belongs to just one face, hence you can set the normal vector as perpendicular to that face. You'll also be able to set the color for just that face as well since you'll no longer be sharing the vertex with other faces.
Post a Comment for "Opengl Es20 - Light A Cube, How To Get Normals?"