Spherical World and HeightMaps

Fa67680e04c99167e5671f54ddf74a47
0
juglarx 101 Nov 04, 2012 at 20:13

Hi everyone!

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(dotX);

                posBuf.put( hm[ CALCULATE_FROM_SPHERICAL_COORD] );

                posBuf.put(dotZ);

any clue on that, are my approach correct or to do it i need another techniques ??
thanks in advance!!

5 Replies

Please log in or register to post a reply.

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 168 Nov 04, 2012 at 20:54

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.

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 Nov 04, 2012 at 23:30

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

http://www.youtube.com/watch?v=MKu4IYb0_Zs&list=UUMXlA3iHipiXiDjYica_wDg&index=54&feature=plcp

Fa67680e04c99167e5671f54ddf74a47
0
juglarx 101 Nov 05, 2012 at 00:33

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 ?

thanks!

A8433b04cb41dd57113740b779f61acb
0
Reedbeta 168 Nov 05, 2012 at 03:37

https://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates

B5262118b588a5a420230bfbef4a2cdf
0
Stainless 151 Nov 05, 2012 at 09:38

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”