[osg-users] Shadows on two-sided polygons

Andreas Goebel a-goebel at gmx.de
Sun Nov 22 01:09:35 PST 2009


Hi Wojtek,

thanks a lot for your detailed answer. I will work through the example
within one of the next holydays, as I am not a professional programmer
(I´m a math teacher) and will need some quiet time for a demanding task
like this. My software is a math-software to illustrate vector geometry,
and thus displays planes and so on simply as polygons. That´s the reason
I need two-sided materials (or at least I decided to do so, the
alternative would have been to use more massive planes).
For the time being it is a comfort for me that I didn´t make a simple
mistake and that it is quite some work to adjust the StandardShadowMap
to two-sided polygons.

Who maintains ShadowMap? I´d like the maintainer to do some tests with
my shader. If you think it´s better than the standard one, I´ll refactor
it into the Shadow-Map code. For a first impression, see the images in
the last mail.

Regards & thanks for the example,

Andreas

Wojciech Lewandowski schrieb:
> Hi Andreas,
>
> If you want  to use dual sided materials I believe you will have to
> review
> and probably modify the shaders  in StandardShadowMap.cpp.  I am certain
> Vertex shader computes ligthing using front lighting and assigns the same
> colors to backfacing polygons.
> Another issue would be usage of back faces for shadow map rendering. I
> guess if you want to use dual face materials  you will need to
> override this.
> So many people have so many varying requests for shadows that my
> recomendation for them would be to create their own ShadowTechnique
> class based on one of LispSM or MinimalShadowMap  or even
> StandardShadowMap. But comparing results, this last one does not
> really differ that much from ShadowMap which is much easier to override.
> When overriding any of above classes its important  to override inner
> ViewData class which provides View related resources storage and
> management. By overriding ViewData::init method you get access to all
> statesets used by base classes and you can easily override all state
> attributes.
> I have prepared an example class (MyViewDependentShadowMap) which
> shows how to override any of classes stemming from
> ViewDepenedentShadowTechnique. This class illustrate how to add soft
> shadows to MinimalDrawBoundsShadowMap class (should be appropriate for
> you).  Have a look at it and modify to your needs.
>
> HTH,
> Wojtek Lewandowski
>
> --------------------------------------------------
> From: "Andreas Goebel" <a-goebel at gmx.de>
> Sent: Saturday, November 21, 2009 1:57 PM
> To: "OpenSceneGraph Users" <osg-users at lists.openscenegraph.org>
> Subject: Re: [osg-users] Shadows on two-sided polygons
>
>> Hi Jean-Sébastien,
>>
>>>> I have turned off those things, and now it works good for me. Should I
>>>> refactor that in a way that the application programmer can choose the
>>>> behaviour and submit that?
>>>
>>> You could, but I think setting those things via overridden state is
>>> also acceptable, since if you need that you'll probably know what to
>>> set...
>>>
>> You mean by setting the StateAttribute CullFaces to off and override for
>> my shadowed scene? This would probably work (even though it is set with
>> override in the ShadowMap? Which will override which?), but not for the
>> polygon-offset, as this is not controlled with state. I mean this line:
>>
>> // negative polygonoffset - move the backface nearer to the eye point so
>> that backfaces
>>        // shadow themselves
>>        float factor = _polyOffset[0];
>>        float units =  _polyOffset[1];
>>
>>>> Another thing: I have written a vertex and a fragment shader that work
>>>> together in a way that allows the shadows to be rendered exactly in
>>>> the
>>>> ambient color. This means that shadowed surfaces look the same as
>>>> surfaces that face away from the light. This gives a much more natural
>>>> feeling, and you don´t get false shadows on the backs of polygons. I
>>>> needed the vertex shader to get the correct ambient color, I think
>>>> it is
>>>> not possible to do this with a fragment shader alone.
>>>
>>> I assume you're talking about osgShadow::ShadowMap? The shaders used
>>> for the ViewDependentShadow classes (LightSpacePerspectiveShadowMapDB,
>>> CB, VB) already do this. Note that osgShadow::StandardShadowMap is the
>>> equivalent of osgShadow::ShadowMap but under the ViewDependentShadow
>>> architecture, so you could have used that and you would have gotten
>>> the right shadow ambient color.
>>>
>> It´s great to hear that, I haven´t used the new classes yet, as they are
>> not (at least in 2.8.2) part of the shadow-Example and I could not
>> easily play with them. However, I have made an option in my program to
>> use the StandardShadowMap, and it does not work for me (yet). Here are
>> the problems:
>>
>> - the side facing away from a light is not dark, example:
>> http://raumgeometrie.de/NeueBilder/testbilder/IncorrectBack.png
>>
>> - the backside of a shadowed plane shows the shadow, too:
>>
>> http://raumgeometrie.de/NeueBilder/testbilder/IncorrectShadowOnBack.png
>>
>> The correct images (with my shaders) look like this:
>>
>> http://raumgeometrie.de/NeueBilder/testbilder/CorrectBack.png
>>
>> And this:
>>
>> http://raumgeometrie.de/NeueBilder/testbilder/NoShadowOnBackOfPlane.png
>>
>> Is it possible to render a more correct shadow for models like mine with
>> StandardShadowMap? It seems a promising technology to me, I would like
>> to use it, and the results (where they are correct) look really good.
>>
>> Regards,
>>
>> Andreas
>>> You can always submit those shaders (as part of modified ShadowMap.cpp
>>> files so that they work by default), I'm sure anyone still using
>>> osgShadow::ShadowMap will be glad you do.
>> I think it´s nicer to have the shaders as separate files, one can easily
>> load them and use them, no need to modify the source.
>>>
>>> J-S
>>
>> _______________________________________________
>> osg-users mailing list
>> osg-users at lists.openscenegraph.org
>> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> osg-users mailing list
> osg-users at lists.openscenegraph.org
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>   



More information about the osg-users mailing list