Skip to main content
gamedev.net
🔒 Locked

Using UV's to access texture array

Started by 1Bad 3 replies 1k views
Original Post
1Bad
1Bad
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?
Krohm
Krohm
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.
Previously "Krohm"
1Bad
1Bad
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?
dpadam450
dpadam450
Post a picture.
Is your terrain a sphere then?
If it is a sphere, then the vertex should displace by: heightmap.value*vertex.normal.
NBA2K, Madden, Maneater, Killing Floor, Sims 
1Bad
1Bad
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.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.