Using UV's to access texture array
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?
The biggest issue is is probably that the displace should typically go on vertex normal, and not its position.
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.
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.
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?
Post a picture.
Is your terrain a sphere then?
If it is a sphere, then the vertex should displace by: heightmap.value*vertex.normal.
Is your terrain a sphere then?
If it is a sphere, then the vertex should displace by: heightmap.value*vertex.normal.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement