Sign in to follow this  
jacquesr

Displaced Shadows

Recommended Posts

Hi guys,

I recently started with some visual fidelity stuff in my scene and I wanted to add shadows.

 

Now, I load a mesh that I exported from blender and I do this

 

BABYLON.SceneLoader.ImportMesh("", "lib/orteclbvis/themes/defaulttheme/models/","yard.babylon", this.scene, (newMeshes, ParticleSystem, skeletons ) =>
{ 

    newMeshes[0].rotate(BABYLON.Axis.Y, BABYLON.Tools.ToRadians(180), BABYLON.Space.LOCAL);
    newMeshes[0].position.y = this.getEnvironmentHeight();
    newMeshes[0].position.z = 0; 
    newMeshes[0].position.x = 30000; 

    if(this.sceneObjects.sunLight)
    {
        var shadowGenerator = new BABYLON.ShadowGenerator(1024*16, this.sceneObjects.sunLight);                                        
        shadowGenerator.setDarkness(.3);
        SceneManagerHelper.enableMeshShadowsRecursively(
            <BABYLON.Mesh[]>newMeshes, 
            shadowGenerator);
    }
 });



// recursive shadow enabler method code:

static enableMeshShadowsRecursively(meshes : BABYLON.Mesh[], shadowGenerator : BABYLON.ShadowGenerator)
{
    for(var i = 0; i < meshes.length; i++)
    {
        var m = meshes[i];
        shadowGenerator.getShadowMap().renderList.push(m);                
        m.receiveShadows = true;
        var childs = m.getChildMeshes();
        if(childs && childs.length > 0)
        {
            this.enableMeshShadowsRecursively(<BABYLON.Mesh[]>childs, shadowGenerator);
            }
        }
    }
}

 

And my shadows are weirdly offset. See attached images.

 

Any idea how that can happen?

 

My scene scale is quiet big (1 babylon unit = 1mm)

 

 

shadows_1.jpg

shadows_2.jpg

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.