Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

directionalLight shadow incorrect

2011-11-21
2013-06-12
  • Phil Biesbrock
    Phil Biesbrock
    2011-11-21

    Hi X3Dom-Team,

    I'm currently implementing a shadow planner with X3Dom, Javascript / JQuery and HTML.
    The user is able to insert the date, time of the day and longitude / latitude of his house. He then sees the sun effect how the shadow is casted upon the marquee of his house.
    To implement this I'm using the X3Dom <directionalLight> - tag.

    My problem is, that the shadow is not projected correctly: right underneath the marquee (red, try code below) no shadow is displayed on the wall of the house (white).
    In contrast to real life, there is also no connection between the shadow on the ground (green) an the one on the wall (white).

    The following piece of code illustrates the problem (with copy and paste you should be easily able to run the code on your computer):

    <!DOCTYPE html>
    <html>
      <head>
        <title>Shadow Designer</title>
        <link rel="stylesheet" type="text/css" href="http://x3dom.org/x3dom/release/x3dom.css"></link>
        <script type="text/javascript" src="http://x3dom.org/x3dom/release/x3dom.js"></script>
      </head>
      <body>    
      <x3d width="800px" height="600px">
      <scene>
    
        <Transform translation="0 1.5 0">
            <Transform DEF="house" translation="0 0 -2">
                <shape>
                <appearance>
                    <material diffuseColor='white' specularColor='0 0 0'></material>  
                </appearance>
                <box size="4 3 4"></box>
                </shape>
            </Transform> 
            <Transform DEF="marquee" translation="0 1 0">
                <Shape>
                <Appearance>
                    <Material diffuseColor="red" specularColor="1 1 1"></Material>
                </Appearance> 
                <IndexedFaceSet DEF='node' coordIndex='3 2 1 0 -1' solid='false'>
                    <Coordinate point='-1.2 0 0, 1.2 0 0, 1.2 0 2, -1.2 0 2'/>
                </IndexedFaceSet>
                </Shape>
            </Transform>
        </Transform>
    
        <Transform translation="0 0 0" DEF="floor">
            <Shape>
            <Appearance>
                <Material diffuseColor="green" specularColor=".5 .5 .5"></Material>
            </Appearance>
            <IndexedFaceSet DEF='node' coordIndex='3 2 1 0 -1' solid='false'>
                <Coordinate point='-8 0 -4, 8 0 -4, 8 0 4, -8 0 4'/>
            </IndexedFaceSet> 
            </Shape>
        </Transform>
    
        <directionalLight DEF='the-light' intensity="1" shadowIntensity='0.7' direction='-0.785 -0.789 -0.619' id="the-light" global="true"></directionalLight>
        <Background skyColor='0.5 0.5 0.5'></Background>
      </scene>
      </x3d>
      </body>
    </html>
    

    I've looked through the Internet, trying to find a solution for the problem, but couldn't find one.
    I also checked the reference for the <directionalLight> - Tag (http://www.web3d.org/x3d/specifications/ISO-IEC-19775-1.2-X3D-AbstractSpecification/Part01/components/lighting.html#DirectionalLight)
    It gave me the hint, that "the accumulated transformations of the parent nodes affect the light".
    I think my problem has got something to do with this Transformation Hierarchy.
    But I can't solve it. So I'm asking you guys now, hoping it helps.

    I'm using Windows XP, Mozilla Firefox 8.0, the graphics board is: NVIDIA GeForce 7600 GS

    It would be really great, if you could help me!

    kind regards

    philvanb

     


  • 2011-11-21

    Hi,

    thanks for your report and providing a test case. I've created an issue at github. You can track progress here:

    https://github.com/x3dom/x3dom/issues/55

    Best regards,
    Andreas

     
  • Phil Biesbrock
    Phil Biesbrock
    2011-11-22

    Hi,

    Thanks a lot for your quick answer and help. Let me ask one last question real quick: Does that mean it's a kind of bug with the IndexedFaceSet? The IndexedFaceSet doesn't allow a correct shadow projection?

    Or is there more likely a mistake in my code?

    It would be great if you could tell me.

    kind regards,

    philvanb

     
  • Yvonne Jung
    Yvonne Jung
    2011-11-22

    Hi, generally, IFS's are supported, but shadows still are sort of a big building site…
    However, as a first workaround you can try playing around with the Viewpoint node's zNear and zFar fields (e.g.zNear 1 and zFar 1000) to allow for a better depth buffer precision.