math & physics
So, i'm working on a project of procedural planet, my problem now is how to map from a spherical coodinate (xyx from my planet) to a qad coordinate (xy form my hightmap grayscale texture). basicaly what i have right now is
// here is all the grayscale data
float hm = heightmap.getHeightMap();
// this is the append on the OpenGL Buffer for all the points on the sphere
posBuf.put( hm[ CALCULATE_FROM_SPHERICAL_COORD] );
any clue on that, are my approach correct or to do it i need another techniques ??
thanks in advance!!
I can't see from the code you posted what you're actually doing, but if you mean you're using spherical coordinates, that's probably a reasonable way to go. For each point in the heightmap you'd set the longitude and latitude to the heightmap x and y, and set the radius to a base radius plus the value stored in the heightmap, then convert to Cartesian coordinates.
You'll get "pinching" at the poles that way, of course, but that might be ok if you don't care too much about the terrain at the poles.
Another way to store the height data would be as a cubemap or a dual-paraboloid map.
I have used two techniques.
1) distorted cube.
This is the most common technique these days as it fits really well with lots of CLOD techniques.
The planet actually is 6 flat quads, like a sky cube, but in the shader you calculate the base height using the equation of a sphere.
2) map projection
You actually feed latitude and longitude into the shader. Then calculate the x,y,z coords from that. This has the advantage that you don't get distortion at the poles.
I actually have some videos of the second in use somewhere......
thanks for your helps!
@Reedbeta, what i realy need to calculate the "CALCULATE_FROM_SPHERICAL_COORD" this what i can't calculate 'couse i don't know how can you explain me better?
@Stainless, do you get any tutorial on this 2 techniques ?
I didn't write a tutorial as the technique has a load of problems.
Basically you create a standard heightmap, and feed in the ships position as latitude and longitude.
In the vertex shader you add the latitude and longitude supplied to the verts tex coord to produce the latitude and longitude of the vert.
(There is a scale factor here as well, you multiply the tex coords by the scale factor. This allows you to change the altitude of the camera)
Then you feed the latitude and longitude into the noise function to get the height of the vert.
The trouble is it only works when the distance between verts is much bigger than the wavelength of the noise function.
If the wavelength is too big verts "wobble"