Jump to content


Quick Clarification (lighting/normals)


2 replies to this topic

#1 bsharrow4

    New Member

  • Members
  • PipPip
  • 12 posts

Posted 09 August 2009 - 02:00 AM

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).

Posted Image

Posted Image

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 Reedbeta

    DevMaster Staff

  • Administrators
  • 5306 posts
  • LocationBellevue, WA

Posted 09 August 2009 - 04:23 AM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 bsharrow4

    New Member

  • Members
  • PipPip
  • 12 posts

Posted 09 August 2009 - 06:26 AM

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.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users