Jump to content
• Advertisement

# spherical clipmaps and texture / world coords

This topic is 3787 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I've been reading the Spherical Clipmaps for Terrain Rendering paper, and trying to implement it. However, I'm having trouble understanding section 3.3, which is the really the key point. The basic idea is to create a static geometry hemisphere (parametized by phi (longitude) and theta (latitude)) in view space, with the viewer located at the pole (theta == 0). The hemisphere is composed of several rings, the rendering of which depends on visibility and distance from the surface. A circular patch (the most detailed area) is used to cover the hole in the middle. This breaks down into something like this:
	for (int i = 1; i != maxLodLevels; ++i) {
theta = std::pow(2.0, -i) * cml::constantsd::pi();

for (int j = 0; j != lodSubLevels; ++j) {
double subtheta = theta * pow(2.0, -j/static_cast<double>(lodSubLevels));

for (double phi = 0.0; phi < phiMax; phi += phiStep) {
vertices.push_back( cml::vector3f(
cos(cml::rad(phi)) * sin(subtheta),
sin(cml::rad(phi)) * sin(subtheta),
cos(subtheta)) );
}
}
}
// set up vbo.
// create center patch.


I'm passing this in as a vertex in the vbo. And, so far so good: The next stage is the one that's causing me problems: finding of the world space coordinates of the vertices, and then the texture coordinates for the vertex (and fragment) texture look up. The paper gives the position of the vertex in world (or model I suppose) space, and then the calculation of phi and theta like so (translated into glsl):
uniform float Thetav;

//...
modelPosition.x = cos(Thetav)*gl_Vertex.x - sin(Thetav)*gl_Vertex.z;
modelPosition.y = gl_Vertex.y;
modelPosition.z = -sin(Thetav)*gl_Vertex.x + cos(Thetav)*gl_Vertex.z;

float phi = atan(modelPosition.y, modelPosition.x);
float theta = acos(modelPosition.z) - Thetav;


I'm calculating Thetav (the viewer world space latitude) like so:
	// cp is the world space camera position.
// pos is the position of the center of the sphere.
cml::vector3f vp = cp - pos;
thetav = cml::constantsd::pi() - (cml::asin_safe(vp[1] / vp.length()) + 0.5 * cml::constantsd::pi());
// thetav ranges from 0 at the north pole to pi at the south,
// as seems to be indicated in the paper.


... and then passing it to the vertex shader. This, however, seems to causes my hemisphere to distort oddly when I move the camera position north or south of the equator. It also seems odd that I'm not using phiv (the viewer world space longitude) anywhere. Looking at the paper I'm not even sure that p (modelPosition above) is actually meant to be the world space coordinate... I tried a completely different tactic using billboarding to orient the hemisphere towards the viewer, but this caused problems when the viewer approached the poles. Can anyone explain this part of the paper, or have any suggestions as to how to get from the local coordinates to world space and texture coords? Thanks! sprite.

#### Share this post

##### Share on other sites
Advertisement
Bump!

(Could a mod maybe move this to the math and physics forum... might have more luck there. Thanks).

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
3. 3
Rutin
14
4. 4
5. 5
• Advertisement

• 10
• 11
• 14
• 10
• 25
• ### Forum Statistics

• Total Topics
632652
• Total Posts
3007660
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!