Quick Clarification (lighting/normals)

D66797a163a6722581ca6eb3d9d4b327
0
bsharrow4 101 Aug 09, 2009 at 02:00

I’ve been debugging through a problem I’ve had the past couple days with lighting my terrain engine. Below are the before/after pics of the lighting problem and the same picture of it after the problem was fixed (notice the odd striping effect on the first pic).

terrain\_shading\_normBuf2nd.jpg

terrain\_shading\_normBuf1st.jpg

This is the code now:

normalBuffer.put(i, normalMap.get(yPos, xPos).getX());
normalBuffer.put((i+1), normalMap.get(yPos, xPos).getY());
normalBuffer.put((i+2), normalMap.get(yPos, xPos).getZ());
            
vertexBuffer.put(i, xPos);
i++;
vertexBuffer.put(i, heightVal);
i++;
vertexBuffer.put(i, yPos);
i++;

These are vertex and normal arrays (I’m not using VBOs). The problem was I had the normalBuffer code above being placed after the vertexBuffer code. Now I realize in immediate mode that all the attributes of the vertex should be called before the glVertex draw code, but this is just populating the arrays for rendering later, so it is confusing me that this was the issue. Just wanting to know if anyone has some input on this.

2 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 167 Aug 09, 2009 at 04:23

Well, the vertexbuffer section has a bunch of i++’s in it, so having the normalbuffer code underneath that would presumably store the normals to the wrong spot in the buffer.

D66797a163a6722581ca6eb3d9d4b327
0
bsharrow4 101 Aug 09, 2009 at 06:26

Well I had

vertexBuffer.put(i, xPos);
i++;
vertexBuffer.put(i, heightVal);
i++;
vertexBuffer.put(i, yPos);
i++;

normalBuffer.put(i-2, normalMap.get(yPos, xPos).getX());
normalBuffer.put(i-1, normalMap.get(yPos, xPos).getY());
normalBuffer.put(i, normalMap.get(yPos, xPos).getZ());

So I just realized my mistake there. Sighhh… always the minor issues.