Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

classic Classic list List threaded Threaded
13 messages Options
marlinrowley marlinrowley
Reply | Threaded
Open this post in threaded view
|

Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

Hello,

We are having a difficult time trying to convert our old shadow map class that inherited from the StandardShadowMap class into the new ViewDependentShadowMap class (which uses a completely new interface).  The difficulty is trying to instantiate such a class with the new ViewData structure as well as how to feed this new class the information that we used to feed it.

Example:

ViewshedOSGShadowMap::ViewshedOSGShadowMap()
                                                : mViewShedGroup(new osg::Group)
                                                , mUp(0.0, 0.0, 1.0)
        {
                Reset();

                mFrustumPositionAttitudeTransform = new osg::PositionAttitudeTransform();
                osg::ref_ptr<osg::Geode> frustumGeode = new osg::Geode;
                mFrustumGeometry = new osg::Geometry;
                mFrustumGeometry->setName("tsSGE::ViewShedOSGShadowMap Frustum Geometry");
                mFrustumGeometry->setDataVariance(osg::Object::DYNAMIC);
                mFrustumGeometry->setUseDisplayList(false);
                mFrustumGeometry->setSupportsDisplayList(false);
                frustumGeode->addDrawable(mFrustumGeometry);

                osg::ref_ptr<osg::StateSet> stateset = new osg::StateSet;
                stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
                stateset->setTextureMode(SHADOW_MAP_UNIT, GL_TEXTURE_2D, osg::StateAttribute::OFF);
                stateset->setMode(GL_BLEND, osg::StateAttribute::ON);
                stateset->setMode(GL_CULL_FACE, osg::StateAttribute::OFF);
                stateset->setAttribute(new osg::Program());
                stateset->setAttributeAndModes(new osg::Depth(osg::Depth::LEQUAL, 0, 1, false));
                frustumGeode->setStateSet(stateset);
                mFrustumPositionAttitudeTransform->addChild(frustumGeode);

                mViewShedGroup->setName("tsSGE::ViewShedOSGShadowMap ViewShed Group");
                mViewShedGroup->addChild(mFrustumPositionAttitudeTransform);

                // create the view data for the shadow map
                //mViewData = createViewDependentData(mViewShedGroup)
        }

In the code above for our constructor, calling createViewDependentData and passing a osg::Group class yields a compile error since it's looking for a CullVisitor*.  Does this need to be dynamically cast?  It would be great if createViewDependentData() had several overloaded functions that took in various types to avoid casting.

Any help would be appreciated.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

Marlin,

ViewDependentShadowMap is an OpenSceneGraph class (not osgEarth) do you might have better luck getting help on the osg-users mailing list.

(By the way, the OSG shadow classes don't work with osgEarth because of osgEarth's shader composition framework so you would need to port them. osgEarth has its own [rudimentary] shadowing class called osgEarth::Util::ShadowCaster you can analyze to see if it fits your needs.)

Hope this helps. -gw
Glenn Waldron / Pelican Mapping
marlinrowley marlinrowley
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

I will look at the ShadowCaster class.

-M
marlinrowley marlinrowley
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

In reply to this post by gwaldron
Is there an example where I can create a ShadowCaster object, and render it's frustrum to the screen as geometry?
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

No but you can look at ExampleResources.cpp to see how to install a ShadowCaster on the MapNode.

https://github.com/gwaldron/osgearth/blob/master/src/osgEarthUtil/ExampleResources.cpp#L649

Glenn Waldron / Pelican Mapping
marlinrowley marlinrowley
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

So I created a small program that uses the map node and sets the shadow parameter.  I'm using the following line for parameters passed into my program:

--monitor --shadows default.earth

I get a render of the earth's globe with a default world map from the /data folder.

What exactly am I looking for in this scene with the shadows option enabled?  I was expecting a semi-transparent frustum object.  Am I missing something?
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

You also need a light source to cast shadows. You can use --sky to add a default sky model / light source (in osgearth_viewer anyway)

Why are you expecting a semi-transparent frustum object?
Glenn Waldron / Pelican Mapping
marlinrowley marlinrowley
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

Of course a light source is required for casting shadows.  But internally, a light source is just a position or direction (assuming no environment lighting or complex light models) with intensity.

We are trying to create a shadow frustum that represents an object that is the light blocker geometry.  Instead of say, a plane that's blocking the light from hitting the terrain, we define an frustum that represents the geometry.  Why are we doing this?  Because we don't need an actual shadow on the terrain but a projection of a view plane onto the terrain that we can control just like a second view (i.e, how wide the FOV is, etc..)

Basically creating a viewshed.

So the question is how can we create a shadow caster (that takes all this information), pass an implicit geometric frustum to the renderer to actually draw the 6-planes at the location a user specifies?  We want it semi-transparent so that we can see the object overlapped over the terrain.
marlinrowley marlinrowley
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

Now that I think about this more, I feel like we are over complicating the issue.  I'm going to bypass the shadow functionality all together and come up with a camera frustum that will project it's plane onto the terrain.

I'll let you know how that pans out.

-M
marlinrowley marlinrowley
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

In reply to this post by marlinrowley
I found an example on one of the osg forums about using a shadow map on the osgEarth terrain and when I tried to compile it, it would fail.

//shadowedScene->setCastsShadowTraversalMask(~terrainOptions.secondaryTraversalMask().value());

The TerrainOptions class has a private member using the secondaryTraversalMask but no 'getter' function to retrieve it.

// Enables shadowing on an osgEarth map node
//ShadowUtils::setUpShadows(shadowedScene, mapNode);

There is no shadowutils class anymore?  Is there an equivalent to call the setUpShadows() function?
marlinrowley marlinrowley
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

In reply to this post by marlinrowley
I got a frustum 3d representation by using the buildGeometry() function based on a camera values (i.e. FOV, up, direction, etc..) and it renders now.
gwaldron gwaldron
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

In reply to this post by marlinrowley
ShadowUtils is long gone. You need to use ShadowCaster to cast shadows.
Glenn Waldron / Pelican Mapping
marlinrowley marlinrowley
Reply | Threaded
Open this post in threaded view
|

Re: Converting a StandardShadowMap child to osgEarth's new ViewDependentShadowMap

An example using the shadow caster class would be very helpful!