Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Normal map from heightmap?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 Waaayoff   Members   -  Reputation: 781

Like
0Likes
Like

Posted 29 July 2012 - 08:04 AM

I think i read somewhere that if you generate a normal map from the heightmap you don't need normal, binormal and tangent vectors per vertex to transform into object space? I'm not sure but i want to use normal maps to do lighting in my terrain.
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "

Sponsor:

#2 gnomgrol   Members   -  Reputation: 589

Like
1Likes
Like

Posted 29 July 2012 - 12:16 PM

Here is the code I use to to this:

for(int z = 0; z<terrainHeight; z++){   
	   for(int x = 0; x<terrainWidth; x++){
    indexNm = z*terrainWidth+x;

    if(z > terrainHeight-1){ //aboth
	   nmOffset = terrainWidth;
    }else{
    nmOffset = 0;
    }
    D3DXVECTOR3 N1 = D3DXVECTOR3(x, heightMap[indexNm+nmOffset],z+1);

    if(x > 0){ //left
	   nmOffset = -1;
    }else{
    nmOffset = 0;
    }
    D3DXVECTOR3 N2 = D3DXVECTOR3(x-1, heightMap[indexNm+nmOffset],z);

    if(x > terrainWidth-1){ //right
	   nmOffset = 1;
    }else{
    nmOffset = 0;
    }
    D3DXVECTOR3 N3 = D3DXVECTOR3(x+1, heightMap[indexNm+nmOffset],z);

    if(z > 0){//below
	   nmOffset = -terrainWidth;
    }else{
    nmOffset = 0;
    }
    D3DXVECTOR3 N4 = D3DXVECTOR3(x, heightMap[indexNm+nmOffset],z-1);
			 D3DXVec3Cross(&normalMap[indexNm], &(N2 - N3), &(N1 - N4)); // cross and done!
    D3DXVec3Normalize(&normalMap[indexNm], &normalMap[indexNm]);
    }
  }



#3 Waaayoff   Members   -  Reputation: 781

Like
0Likes
Like

Posted 29 July 2012 - 02:01 PM

Thanks, but do i have to use tangents/binormals?
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "

#4 gnomgrol   Members   -  Reputation: 589

Like
1Likes
Like

Posted 30 July 2012 - 02:39 AM

No, you don't. Just look up a terrain lightning tutorial. It's mostly the same like with any other object.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS