I have taken the code I think I need from the osgShadow example and tried to add shadows to my existing application. The problem is that the shadow map displayed in the debug window is just a gray-ish circle centered on a white-ish background, nothing at all what I expected and no details that look anything like the objects in my scene. This remains the same regardless of whare I put my light source. Any suggestions?
My code is as follows:
W
osgViewer::CompositeViewer viewer;
osgViewer::View* view = new osgViewer::View;
viewer.addView(view);
view->setUpViewInWindow(50, 50, currentWidth, currentHeight, 0);
osg::ref_ptr<osgShadow::ShadowedScene> shadowedScene = new osgShadow::ShadowedScene;
shadowedScene->setReceivesShadowTraversalMask(ReceivesShadowTraversalMask);
shadowedScene->setCastsShadowTraversalMask(CastsShadowTraversalMask);
osg::ref_ptr<osgShadow::ShadowMap> sm = new osgShadow::ShadowMap;
shadowedScene->setShadowTechnique(sm.get());
int mapres = 1024;
sm->setTextureSize(osg::Vec2s(mapres,mapres));
m_World = new osg::Group;
// add some things to m_World…. Removed for brevity sake
// get the bounds of the model.
osg::ComputeBoundsVisitor cbbv;
m_World->accept(cbbv);
osg::BoundingBox bb = cbbv.getBoundingBox();
osg::Vec4 lightpos;
viewer.getView(0)->getEventHandlers().push_front(new osgViewer::StatsHandler);
viewer.getView(0)->getEventHandlers().push_front(mykey);
std::vector<osg::Camera*> cameras;
viewer.getCameras(cameras);
cameras[0]->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR);
cameras[0]->setProjectionMatrixAsPerspective(40.0, 1.333333333, 1.0, SKYDOME_RANGE*1.1f);
bool postionalLight = true;
if (postionalLight)
{
lightpos.set(bb.center().x(), bb.center().y(), bb.zMax() + bb.radius()*2.0f ,1.0f);
}
else
{
lightpos.set(0.5f,0.25f,0.8f,0.0f);
}
osg::ref_ptr<osg::LightSource> ls = new osg::LightSource;
ls->getLight()->setPosition(lightpos);
shadowedScene->addChild((osg::Node*)m_World);
shadowedScene->addChild(ls.get());
bool updateLightPosition = true;
viewer.realize();
viewer.getView(0)->setSceneData(shadowedScene.get());
bool debugHUD = true;
if(debugHUD)
{
osgViewer::Viewer::Windows windows;
viewer.getWindows(windows);
if (windows.empty()) return 1;
osgShadow::ShadowMap* sm = dynamic_cast<osgShadow::ShadowMap*>(shadowedScene->getShadowTechnique());
if( sm ) {
osg::ref_ptr<osg::Camera> hudCamera = sm->makeDebugHUD();
// set up cameras to rendering on the first window available.
hudCamera->setGraphicsContext(windows[0]);
hudCamera->setViewport(0,0,windows[0]->getTraits()->width, windows[0]->getTraits()->height);
viewer.getView(0)->addSlave(hudCamera.get(), false);
}
}
// display the help
key->showHelp();
while( !viewer.done() )
{
cameras[0]->setViewMatrix(key->getViewMat());
if (updateLightPosition)
{
float t = viewer.getFrameStamp()->getSimulationTime();
if (postionalLight)
{
lightpos.set(bb.center().x()+sinf(t)*bb.radius(), bb.center().y() + cosf(t)*bb.radius(), bb.zMax() + bb.radius()*3.0f ,1.0f);
}
else
{
lightpos.set(sinf(t),cosf(t),1.0f,0.0f);
}
ls->getLight()->setPosition(lightpos);
osg::Vec3f lightDir(-lightpos.x(),-lightpos.y(),-lightpos.z());
lightDir.normalize();
ls->getLight()->setDirection(lightDir);
}
viewer.frame();
}
I also must add that I am using my own shaders and have reproduced the shadowmap shader code as follows:
uniform sampler2D osgShadow_baseTexture;
uniform sampler2DShadow osgShadow_shadowTexture;
uniform vec2 osgShadow_ambientBias;
vec4 myCalculations()
{
// Details Omitted;
}
void main (void)
{
// My shader code details omitted
// shadow mapping
vec4 color = gl_Color * texture2D( osgShadow_baseTexture, gl_TexCoord[0].xy );
gl_FragColor = color * (osgShadow_ambientBias.x + shadow2DProj( osgShadow_shadowTexture, gl_TexCoord[1] ) * osgShadow_ambientBias.y);
}
> Any suggestions?
I haven't tried your code, but I don't see you calling
ShadowMap::setLight() anywhere... Try to add this once your light source
is initialized:
sm->setLight(ls->getLight());
Other than that, at first glance your code seems OK.
Hope this helps,
J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> Thanks, That seem to make some change, instead of a grayish circle, I now
> see a moving roundish object...
Sounds familiar...
Han Solo: [flying across the deserts of Tatooine] I think my eyes are
getting better. Instead of a big dark blur, I see a big bright blur.
http://www.imdb.com/character/ch0000002/quotes
</goofing off>
Give me a minute, I'll try it out and see.
Just have to ask, if you try with only one object and a ground plane (a
really simple scene) do you get the same results?
-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of
Jean-Sébastien Guay
Sent: Tuesday, November 10, 2009 2:11 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] ShadowMap problem...
> Just have to ask, if you try with only one object and a ground plane (a
> really simple scene) do you get the same results?
I just tested, and your code seems to work. I've attached a source file
which is the osgshadow example, with the main() commented out and your
code in its place. Have a look, the only changes were to put the
ModelThree scene as child of your m_World group and to make sure I had a
manipulator, and make everything compile...
You seem to be using a skydome (based on a variable called SKYDOME_RANGE
in the code). You did set your skydome's node mask to ~cast right?
Otherwise what you're seeing is probably your skydome's shadow being
cast over everything... That's one thing about using osgShadow, you need
to make sure things that you don't want to cast shadows don't have the
cast shadow bit in their node mask. Also HUDs should be set that way.
Keep an iron grip on your node masks or you'll have unpleasant
surprises... :-)
The receive shadow node mask is not used for ShadowMap classes, but you
can implement a node that doesn't receive shadows by adding a case in
your shader (a test on a boolean uniform that skips the shadow test) and
set that uniform to true at your scene's root and false for each node
that you don't want to receive shadows.
And btw, osgShadow::ShadowMap is not really designed for positional
lights, because they're omnidirectional and would need 6 full-scene RTT
passes (like a cube map) to be totally accurate. I think (IIRC)
osgShadow::ShadowMap and the ViewDependentShadow classes try to
approximate a directional in that case, but the approximation breaks
down if the light source is positioned inside the bounding box of the
scene... You're better off either approximating the sun with a
directional, or using a spot light for an interior scene.
Hope this helps,
When I have one or two objects, say the size of a car, or truck, only. The
shadow map looks correct. But when I add my terrain which is approximately x
= 5100 by y = 5100, I no longer see the car/truck shadows on the shadow map.
Similarly, if I increase the length and width of the bottom box in the
osgShadow example, I no longer see the other objects in the shadow map.
I assume I am running into some shadow map texture resolution limit or
something. What is going on?
Tnanks,
W
-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of
Jean-Sébastien Guay
Sent: Tuesday, November 10, 2009 3:08 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] ShadowMap problem...
Hi Wyatt,
Hope this helps,
_______________________________________________
W
-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of
Jean-Sébastien Guay
Sent: Tuesday, November 10, 2009 3:08 PM
To: OpenSceneGraph Users
Subject: Re: [osg-users] ShadowMap problem...
Hi Wyatt,
Hope this helps,
_______________________________________________
> When I have one or two objects, say the size of a car, or truck, only. The
> shadow map looks correct. But when I add my terrain which is approximately x
> = 5100 by y = 5100, I no longer see the car/truck shadows on the shadow map.
>
> Similarly, if I increase the length and width of the bottom box in the
> osgShadow example, I no longer see the other objects in the shadow map.
>
> I assume I am running into some shadow map texture resolution limit or
> something. What is going on?
Yep, Most probable. osgShadow::ShadowMap can't help you there, but there
are a few things you can do to mitigate the problem.
* First, don't set your terrain to cast shadow (if it's mostly flat
you'd never see its shadow anyways)
* Second, make sure all the objects you set to cast shadow are in a
small area. If an object leaves the area of focus, remove its cast
shadow bit from its node mask.
* Third, increase the shadow map resolution as much as you can (on some
cards, 4096x4096 is the biggest you can go, on some others it's 2048x2048)
But if you want better results, switch to one of the ViewDependentShadow
techniques that are in OSG 2.8+ (for example
osgShadow::LightSpacePerspectiveShadowMap). These will consider the
camera's view volume and only calculate shadows for this area
automatically, so if you're looking at a relatively small portion of
your scene it will give much better results. Though they have some
artifacts in some situations too... Nothing is perfect, it's always a
trade-off.
> My shadow map is looking mostly correct now after making changes to light
> type, position etc. However shadows are not appearing in the final
> rendering. The app I am trying to add shadow mapping to uses textures bound
> to tex units 0-3. I noticed in the ShadowMap class there were methods for
> setting the texture unit and wondered if this possibly why I am not seeing
> the shadows. That is, is my use of tex units 0-3 conflicting with
> ShadowMaps use of texture units and should I reassign one or the others
> texture units?
Most probably, ShadowMap uses texture unit 1 by default for the shadow
map. Call osgShadow::ShadowMap::setTextureUnit() to set the texture unit
you want the shadow map to use (for example 4, or 7 to give yourself
some breathing room), and use that same texture unit in your shadow
shaders when you get to the point of generating texture coordinates and
doing the shadow lookup too. There's a similar method in
osgShadow::LightSpacePerspectiveShadowMap.
-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of
Jean-Sébastien Guay
Sent: Wednesday, November 11, 2009 8:04 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] ShadowMap problem...
1. Is there a way I can query the number of texture units available on my
GPU via an OSG call?
2. Is there a list, other than the osgShadow programming guide of shadowmap
techniques, specifically ViewDependentShadow techniques?
W
-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of
Jean-Sébastien Guay
Sent: Wednesday, November 11, 2009 8:04 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] ShadowMap problem...
> 1. Is there a way I can query the number of texture units available on my
> GPU via an OSG call?
A Google search turned up glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB). Also
searching the OSG headers, I found
osg::Texture::Extensions::numTextureUnits() which returns a GLint (int).
Look at the source to find out where the value will be initialized or
how to initialize it yourself.
I generally don't bother to query and use 8 (0-7) as a number that's
supported pretty much everywhere.
> 2. Is there a list, other than the osgShadow programming guide of shadowmap
> techniques, specifically ViewDependentShadow techniques?
The source/headers... And the mailing list archives.
The three usable types are:
class LightSpacePerspectiveShadowMapDB /*...*/ {};
class LightSpacePerspectiveShadowMapCB /*...*/ {};
class LightSpacePerspectiveShadowMapVB /*...*/ {};
And LightSpacePerspectiveShadowMap is an alias for
LightSpacePerspectiveShadowMapDB :
typedef LightSpacePerspectiveShadowMapDB LightSpacePerspectiveShadowMap;
And also StandardShadowMap is usable, but it's not view-dependent, so
it's pretty much a direct replacement for osgShadow::ShadowMap but in
the same class hierarchy as the LightSpace* classes.
W
-----Original Message-----
From: osg-user...@lists.openscenegraph.org
[mailto:osg-user...@lists.openscenegraph.org] On Behalf Of
Jean-Sébastien Guay
Sent: Wednesday, November 11, 2009 8:04 AM
To: OpenSceneGraph Users
Subject: Re: [osg-users] ShadowMap problem...
> I have changed to a LISPSM shadow technique.
OK.
> I have removed the cast bit from my terrain.
> The only two objects I have set cast shadow are close together.
This should not need to be done when using LISPSM. It's view-dependent,
so you don't need to make sure that the shadow map is applied to a small
part of the scene as you did with the normal ShadowMap. Still, it
doesn't hurt if you don't need shadows cast by your terrain anyways.
> My texture size is 2048 x 2048.
> Not seeing shadows on the terrain from my objects.
Did you check the debugHUD (with LISPSM it's as easy as
shadowTechnique->setDebugDraw(true) )? Does it show something that looks
valid?
Note that LISPSM's shaders are different than ShadowMap's shaders that
your used before. It uses a different name for the shadow map sampler,
and by default it separates the shaders into main and shadow parts,
though you can still disable the shaders that LISPSM adds and use your
own (make sure to use the right sampler and uniform names in your
shader). Check the source in StandardShadowMap.cpp to see what the
shaders look like.
> Changed shadowTexture unit to 7.
> Should basetexture be 0 still?
The base texture unit is just used by the shaders that LISPSM sets by
default. If you're disabling those and using your own (which you surely
do if you're using units 0-3 for some effects), then don't worry about it.
MinimalShadowMap
MinimalCullBoundsShadowMap
MinimalDrawBoundsShadowMap
could be useful too sometimes, they take advantage of the same shadow volume
optimization methods as LispSM flavours, but not use skewed projection like
LispSM. This skewed projection is sometimes a problem when used with non
directional lights. It may also bring trouble when one wants to mix smooth
shadows with ViewDependentShadowMap techniques. So in the end all the
techniques stemming from ViewDependentShadowTechnique have their advantages
and are definitely not abstract (excluding maybe DebugShadowMap which
provides a bottom layer with debuging methods).
Cheers,
Wojtek Lewandowski
--------------------------------------------------
From: "Jean-Sébastien Guay" <jean-seba...@cm-labs.com>
Sent: Wednesday, November 11, 2009 5:26 PM
To: "OpenSceneGraph Users" <osg-...@lists.openscenegraph.org>
Subject: Re: [osg-users] ShadowMap problem...
> Hi Wyatt,
I am not sure... With the debugHUD in the ShadowMap example, there was just
a window which appeared to display the shadow map in gray-scale, but in the
LISPSM example, there appears to be two sub-windows in the debughud window
(not in gray-scale). What are these displaying?
>
> Note that LISPSM's shaders are different than ShadowMap's shaders that
> your used before. It uses a different name for the shadow map sampler,
> and by default it separates the shaders into main and shadow parts,
> though you can still disable the shaders that LISPSM adds and use your
> own (make sure to use the right sampler and uniform names in your
> shader). Check the source in StandardShadowMap.cpp to see what the
> shaders look like.
I found the shader source, in StandardShadowMap::StandardShadowMap. I am a
bit confused about how to use the osgShadow in my app if I already have
shaders in my app.
The osgShadow programmers guide says
" What if my objects already have a shader applied to them?
* That shader also needs to implement shadow mapping. See the top of
src/osgShadow/ShadowMap.cpp for the basic shader, and use that in your
shader (keep the same names for the variables too)."
Am I supposed to, basically, copy the shader code from StandardShader map
and add it to my shaders and turn off the LISPSM shaders?
W
>> Did you check the debugHUD (with LISPSM it's as easy as
>> shadowTechnique->setDebugDraw(true) )? Does it show something that
>> looks valid?
>
> I am not sure... With the debugHUD in the ShadowMap example, there was
> just
> a window which appeared to display the shadow map in gray-scale, but in
> the
> LISPSM example, there appears to be two sub-windows in the debughud window
> (not in gray-scale). What are these displaying?
First square displays shadow map using pseudo coloring (if you interested
why see the comment above the shader in DebugShadowMap.cpp) second square
contains dump from predraw of you scene to very small depth texture, this
extra pre render step is used to compute visible part of scene and optimize
shadow volume. This second square is only drawn for LispsmDB &
MinimalDrawBoundsShadowMap.
>>
>> Note that LISPSM's shaders are different than ShadowMap's shaders that
>> your used before. It uses a different name for the shadow map sampler,
>> and by default it separates the shaders into main and shadow parts,
>> though you can still disable the shaders that LISPSM adds and use your
>> own (make sure to use the right sampler and uniform names in your
>> shader). Check the source in StandardShadowMap.cpp to see what the
>> shaders look like.
>
> [..]
>
> Am I supposed to, basically, copy the shader code from StandardShader map
> and add it to my shaders and turn off the LISPSM shaders?
Generally yes, But don't turn them off but rather alter them with your
modified shaders.
WL
> With the debugHUD in the ShadowMap example, there was just
> a window which appeared to display the shadow map in gray-scale, but in the
> LISPSM example, there appears to be two sub-windows in the debughud window
> (not in gray-scale). What are these displaying?
The left side is the shadow map itself, and the right side is a render
of the bounds analysis render pass (the LightSpacePerspectiveShadowMapDB
technique - Draw Bounds - makes a 64x64 render pass before the actual
shadow pass to see if the shadow map bounds can be further reduced -
Wojtek can tell you more about it, or search the archives for details).
> Am I supposed to, basically, copy the shader code from StandardShader map
> and add it to my shaders and turn off the LISPSM shaders?
You only need to use some parts, those that relate to the shadow test.
The rest of your shader can be what you want - most of the shader code
in StandardShadowMap.cpp is just standard lighting, which you might be
doing differently. You should copy the DynamicShadow function for both
vertex and fragment shader (whether you want to keep it in a function or
not, up to you) and then look at the place where it's used and do
something similar.
Read the shaders, you should understand.
J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/
> Generally yes, But don't turn them off but rather alter them with your
> modified shaders.
That's useful when the ShadowedScene is the root of the scene, and your
entire scene can be rendered with a single shader (or uber-shader with
uniforms to select different code paths). But in some cases that might
not be the case.
I find it more convenient to disable the ShadowTechnique's shaders and
just place my own shaders at the root of the scene. Also others may
customize the way their shaders are applied to individual nodes.
Eventually I intend to start using VirtualProgram too... :-)
J-S
--
______________________________________________________
Jean-Sebastien Guay jean-seba...@cm-labs.com
http://www.cm-labs.com/
http://whitestar02.webhop.org/
I see, that would work too.
> I find it more convenient to disable the ShadowTechnique's shaders and
> just place my own shaders at the root of the scene. Also others may
> customize the way their shaders are applied to individual nodes.
> Eventually I intend to start using VirtualProgram too... :-)
I really recommend it. We developed VirtualProgram for this particular
purpose ie to free user from creating all in one shader.
Wojtek
I have implemented the LiSPPSM shadow code in my app. My scene consists of
two vehicles and a terrain. If I don't add the terrain, I can see the
shadows on the base test geometry and it looks pretty good. The base
geometry just happens to be sitting below my two vehicles. If I do add the
terrain, most of the terrain is covered by a big black square, and I no
longer see the shadows on the base geometry (I can descend below the
geometry of the terrain and see the base geometry). Is something possibly
casting a large shadow on the terrain to cause the big black square? I am
not sure what it could be since I only have the terrain, two vehicles and
the base geometry. Any suggestions?
Thx
W
> -----Original Message-----
> From: osg-user...@lists.openscenegraph.org [mailto:osg-users-
> bou...@lists.openscenegraph.org] On Behalf Of Jean-Sébastien Guay
> Sent: Wednesday, November 11, 2009 2:33 PM
> To: OpenSceneGraph Users
> Subject: Re: [osg-users] ShadowMap problem...
>
W
> > http://www.cm-labs.com/
> > http://whitestar02.webhop.org/
> > _______________________________________________
> > osg-users mailing list
> >
> > http://lists.openscenegraph.org/listinfo.cgi/osg-users-
> > openscenegraph.org
> >
>
> _______________________________________________
> osg-users mailing list
>
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> ------------------
> Post generated by Mail2Forum
------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=19582#19582
> Any suggestions?
Not really. At this point you'll probably have to trace into OSG to make
sure the shadow map traversal is getting to the right objects (i.e. your
masks are set correctly), and check your shaders (perhaps even try with
the basic shaders that LISPSM uses by default for starters). Also, try
to start with the osgShadow example, and work up progressively to
something similar to what you have in your app, and perhaps in the
process you'll find out what's not working. If not, then at least you'll
have a small app that can demonstrate the problem, which we might be
able to help with.
Hope this helps,
Wojtek
--------------------------------------------------
From: "Jean-Sébastien Guay" <jean-seba...@cm-labs.com>
Sent: Thursday, November 12, 2009 8:45 PM
To: "OpenSceneGraph Users" <osg-...@lists.openscenegraph.org>
Subject: Re: [osg-users] ShadowMap problem...
> Hi Wyatt,
Ok... so I did what you suggested mostly... I took the osgshadow example, add my geometry and it worked. I added another shader on the root node of the scenegraph, because in my app, I do that. I took the shaders from ShadowMap.cpp and put them into vert/frag files and loaded them into their respective shaders. That worked too.
In my application, when I load those shaders from ShadowMap.cpp and use them, I see a change in the lighting but it isn’t what I expect. Rather than the objects casting shadows on the terrain, it looks like a shdow is being cast over the objects, but it isnt'being cast on the terrain. The best way I can describe it is that it looks like the objects are in the sun then a cloud floats between the sun and the object... I don’t think a picture will show what I mean, but here are 3 pictures with the shadow moving progressively to the left over the object... note the white building in the front gets darker. But now shadows on the terrain.
W
> -----Original Message-----
> From: osg-user...@lists.openscenegraph.org [mailto:osg-users-
> bou...@lists.openscenegraph.org] On Behalf Of Jean-Sébastien Guay
> Sent: Thursday, November 12, 2009 1:45 PM
> To: OpenSceneGraph Users
> Subject: Re: [osg-users] ShadowMap problem...
>
> Hi Wyatt,
Is this what you meant?
Thanks,
W
From: Wyatt EarpSent: Friday, November 20, 2009 6:03 AMSubject: RE: [osg-users] ShadowMap problem...
Is this what you meant?
Thanks,
W
Thanks for the suggestions. I’ll go through the steps you suggested… A bit more information…
I use texture units 0-3 for my texturing.
I set the base texture unit for the shadows to 0 and the shadow texture unit to 7.
Background… Trying to add light perspective shadow map shadows to my app.
My app already has shaders enabled. I have two sets of shaders, each one being run for a given “mode’. Either shadersA or shadersB runs, but not both at the same time.
I replace shadersB with the shaders from StandardShadowMap.cpp.
These shaders, from StandardShadowMap.cpp produce shadows IF and ONLY IF I disable shadersA. Otherwise, the result is what is shown in the image(s) included in one the previous emails.
shadersA uses texture units 0-6 inclusive, and TexCoord0-6.
shadersB, the ones from StandardShadowMap.cpp, uses, well, whatever it uses when I set the tex units:
unsigned int baseTexUnit = 0;
unsigned int shadowTexUnit = 8;
sm->setShadowTextureCoordIndex( shadowTexUnit );
sm->setShadowTextureUnit( shadowTexUnit );
sm->setBaseTextureCoordIndex( baseTexUnit );
sm->setBaseTextureUnit( baseTexUnit );
I see that in the shadow shaders, and in my shaders, both gl_MultiTexCoord0/1 are used. Could that be one of the problems?
Assuming I want to keep all my shaders the same, would I need to change anything in osgShadow node kit to resolvetheconflict or would all the changes be in the shadow shaders?
W
From: osg-user...@lists.openscenegraph.org [mailto:osg-user...@lists.openscenegraph.org] On Behalf Of Wojciech Lewandowski
Sent: Friday, November 20, 2009 3:58 AM
Ok… Now I am getting confused. What are my options on using the shadow shaders in my app?
1. If my shaders use 0-6, do I need to call
sm->setBaseTextureCoordIndex( baseTexUnit );
sm->setBaseTextureUnit( baseTexUnit );
to change the base texture unit to something other than 0, since I am using it in my shaders?
2. According to the osgShadow programming guide:
“What if my objects already have a shader applied to them?
But according to the info below I shouldn’t just manually copy them and use them. Eventually, what I want to do is incorporate the shader code I need to apply the shadows into my own shaders. Is this possible? Or can I simply add a shader to my objects nodes to be applied after my shaders are applied?
3. Not a shadow question, but in what order would shaders be applied if I have a shader on the root node of a scenegraph, and one on a child node?
Thx
> 3. Not a shadow question, but in what order would shaders be applied if I have a shader on the root node of a scenegraph, and one on a child node?
> sm->setBaseTextureUnit( baseTexUnit );
> to change the base texture unit to something other than 0, since I am using it in my shaders?
> 2. According to the osgShadow programming guide:
> “What if my objects already have a shader applied to them?
> But according to the info below I shouldn’t just manually copy them and use them. Eventually, what I want to do is incorporate the shader code I need to apply the shadows into my own shaders. Is this possible? Or can I simply add a shader to my objects nodes to be applied after my shaders are applied?
As I said before, you have to rewrite your shaders incorporating shadow term calculation from ShadowShaders. There is no other option for you. You may only use one set of shaders compiled and linked into one Program.
Wojtek
PS. Sorry, if this may be little harsh for you: This whole LispSM is highly advanced stuff. If you want to modify it, you really have to be able to read and understand OSG source code. If last requirement is too much, then consider posting your code asking for help, because it would be much simpler to modify the source, than explain eveything bit by bit.
Ok.. Thanks for the further explanations… I think I understand better now, what I need to do.
It isn’t that I don’t want to post code… I am not sure that I am allowed to due to company restrictions.
Is “Light Space Perspective Shadow Maps” by Wimmer et. al. Eurographics Symposium on Rendering (2004) what OSG LispSM is based on?
Perhaps using ShadowTexture might be more in line with my skills since it does not use a shader?
> Is “Light Space Perspective Shadow Maps” by Wimmer et. al. Eurographics Symposium on Rendering (2004) what OSG LispSM is based on?
Yes. However, LispSM algorithm differes from traditional shadow maping only by a method of computing shadow map projection. So all the wiring (uniforms, state attributes, textures) is the same as for StandardShadowMap. Only contents of shadow map projection and texgen matrices differ.
>Perhaps using ShadowTexture might be more in line with my skills since it does not use a shader?
It really depends on what you are trying to accomplish. The outdoor example pictures you posted do look like your app is a right candidate for LispSM.
Wojtek