Spherical World and HeightMaps

5 replies to this topic

#1juglarx

New Member

• Members
• 2 posts

Posted 04 November 2012 - 08:13 PM

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

#2Reedbeta

DevMaster Staff

• 5307 posts
• LocationBellevue, WA

Posted 04 November 2012 - 08:54 PM

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.
reedbeta.com - developer blog, OpenGL demos, and other projects

#3Stainless

Member

• Members
• 581 posts
• LocationSouthampton

Posted 04 November 2012 - 11:30 PM

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

#4juglarx

New Member

• Members
• 2 posts

Posted 05 November 2012 - 12:33 AM

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

#5Reedbeta

DevMaster Staff

• 5307 posts
• LocationBellevue, WA

Posted 05 November 2012 - 03:37 AM

https://en.wikipedia...ian_coordinates
reedbeta.com - developer blog, OpenGL demos, and other projects

#6Stainless

Member

• Members
• 581 posts
• LocationSouthampton

Posted 05 November 2012 - 09:38 AM

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"

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users