Sign in to follow this  
1Bad

Using UV's to access texture array

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this