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

5 Replies

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

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

0
101 Nov 05, 2012 at 00:33

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

0
168 Nov 05, 2012 at 03:37

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

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