Placing osgearth inside a group with bigger bounding sphere

classic Classic list List threaded Threaded
3 messages Options
Ivo Kachaunoff Ivo Kachaunoff
Reply | Threaded
Open this post in threaded view
|

Placing osgearth inside a group with bigger bounding sphere

Hi all,

First of all osgEarth is great.
But I have the following problem: I need to add starfield and a skydome arround my earth model.
I added a starfield successfully by taking the StarField class from osgEphemeris directly. It is a geometry with points, where each point represents a single star.
So I added the StarField into the root group and then added the loaded osgearth model into the same group too. It looks great. I need to disable the zooming out after a specified distance. Otherwise if the user zooms out very much they will see the stars arround the earth as a sphere, but this is not the main problem.
The problem appears when I soom in too close. The earth dissapears at a very high height value. If I don't add the starfield I can zoom in very close and the earth tiles would dissapear at very small height as expected.
So can someone please help me with the earth dissapearing when I use the big starfield arround the earth? Thanks in advance.

Best Regards,
Ivo
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Placing osgearth inside a group with bigger bounding sphere

Ivo,

I suspect you are running afoul of OSG's automatic clip plane calculation. Each frame, OSG looks at all the visible geometry in your scene and tries to automatically determine suitable near and far clip planes. Since your star field is very far away, it is pushing out the near clip plane and obscuring the ground geometry that's close to your camera.

You can disable auto-clip planes by calling
camera->setComputeNearFar(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);

and then setting the clip planes manually. But that might cause other problems like bad Z precision since your star field is go far out.

This thread addresses the issue with a suggestion to use multiple camera passes:
http://forum.openscenegraph.org/viewtopic.php?t=2314

Let me know where you get with this. Someday I would like to add some kind of star/sky field support to osgEarthUtil itself.

Glenn
Pelican Mapping
Glenn Waldron / Pelican Mapping
Ivo K. Ivo K.
Reply | Threaded
Open this post in threaded view
|

Re: Placing osgearth inside a group with bigger bounding sphere

Hi Glenn,

Thanks for the quick reply. I thought it was a clipping calculation problem too.
As you said setting:
camera->setComputeNearFar(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);  
and specifying my own clip planes could lead to z precision problems, so I found another approach, inspired by osgearth_clouds application.
You can reproduce the same problem there if you set the scale of the clouds layer to 10 and maxRange to 0 (so it is always shown).

So in my app I put the starfield into a LOD and set the maximum range like this:
osg::ref_ptr<StarField> starfield = new StarField;
osg::ref_ptr<osg::LOD> lodSF = new LOD;
lodSF->addChild(starfield, osg::WGS_84_RADIUS_EQUATOR * 1.1, FLT_MAX);
m_root->addChild(lodSF.get());

It works great, but I'm not sure if this is a nice solution. The stars simply dissapear at zoom distance of osg::WGS_84_RADIUS_EQUATOR * 1.1 and there are no problems any more.
But when I tilt the earth (I use EarthManipulator of course) I can only see the stars appear at specific zoom distance. I.e. they appear suddenly when I zoom out. This is not a big problem for my app if I manage to put a skydome hemisphere arround the earth that will hide the stars anyway, but I still haven't tested it. Wil llet you know when i have some progress.
By the way I want to replicate Google Earth as closely as possible, i.e. horizon, gloom etc. I plan to add some lens flare effects later too.

Best Regards,
Ivo