Jump to content
  • Advertisement
Sign in to follow this  
1Bad

Using UV's to access texture array

This topic is 3754 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, I am trying to height map the sphere I just created. I have the UV's all correct for texturing the sphere, so now I want to height map it. My code looks something like... for(int i = 0; i < vert_qty; i++) { mapcoordx = vert.u * texturewidth*4; mapcoordy = vert.v * textureheight*4; red = texture[mapcoordx+mapcoordy+0] * .30; green = texture[mapcoordx+mapcoordy+1] * .59; blue = texture[mapcoordx+mapcoordy+2] * .11; vert.x *= red+green+blue; vert.y *= red+green+blue; vert.z *= red+green+blue; //ignore alpha } however, I am not getting the correct mapping out of this loop. My the resulting vertex changes are waaaay off and dont even resemeble what should be occuring. Any suggestions as to what could be going on?

Share this post


Link to post
Share on other sites
Advertisement
The biggest issue is is probably that the displace should typically go on vertex normal, and not its position.
coord = coord + (normal * influence) // obviously vectors 


Additionally, displacing to center isn't likely to be useful and wastes a ton of precision in case you're using 8bit maps. Defining a displacement range is going to be useful.
Additionally, make sure the displacement is meaningful in the coordinate system you're using.
I suppose that's why there are ugly literal-constants here. That's BAD. Implement a ranged displacement instead and use const.

Share this post


Link to post
Share on other sites
It seems my problem is more that I seem to be getting bogus values. After applying the heightmap function my terrain looks totally random and nothing like the height map. Is there something I need to consider when trying to turn UV coords into array indices that I am missing?

Share this post


Link to post
Share on other sites
Post a picture.
Is your terrain a sphere then?
If it is a sphere, then the vertex should displace by: heightmap.value*vertex.normal.

Share this post


Link to post
Share on other sites
I figured it out.
It was a problem in how I found the texture index in an array.

the correct way to find the index in the array is actually

(mapcoordy*texturewidth) + mapcoordx

So to get to the ycoord u need to pass over y*the width of the texture to get to the correct row.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!