ozRocker

Struggling with shadows from high-poly mesh

Recommended Posts

I'm trying to add shadows and its not coming out too well.  I think the high-poly count (100k) and lack of soft shadowing is producing some weird affects.  This is the result from Babylon.js http://www.punkoffice.com/babylon/luke.html


 


What I'm trying to do is find out if Babylon.js is suitable for animated photogrammetry-made humans.  The only framework that I've gotten this working with so far is Unity 5, which you can see here http://www.punkoffice.com/luke/


 


My shadows are set up like this



var shadowGenerator = new BABYLON.ShadowGenerator(4096, light);
var mesh = newScene.meshes[0];
shadowGenerator.getShadowMap().renderList.push(mesh);
shadowGenerator.useVarianceShadowMap = true;
shadowGenerator.usePoissonSampling = true;
mesh.receiveShadows = true;
ground.receiveShadows = true;

(using directional light as light source)


 


Is there any way to make the Babylon.js shadow look like the Unity 5 one?


 

Share this post


Link to post
Share on other sites

Those holes in the Babylon.js version is the result of shadows on the person's skin.  If I prevent the person from receiving shadows he doesn't get those holes, but I need him to receive shadows somehow.

Share this post


Link to post
Share on other sites

The ground and person both need to receive shadows.  If you check out the Unity demo you can see that the head will cast shadows on the back, neck and shoulders.  Also the arms will cast shadows on the torso when he is doing sit-ups.

Share this post


Link to post
Share on other sites

Ok, I did not watch your demo. and indeed, it looks like a bug I'd say. Looks like the shadow projected on the character comes from the ground. I have the impression that an object can not be projected to the shadow itself.

 

But I also feel that your model is transparent in part. I've had this problem by exporting with 3ds max. Face mask must be activated in the model options.

 

Try delete : shadowGenerator.useVarianceShadowMap = true;

I think that using 2 filters can create this problem (maybe)

Share this post


Link to post
Share on other sites

ok, thanks guys! I've removed the line  shadowGenerator.useVarianceShadowMap = true;

 

I've also removed all textures in the scene.  Unfortunately it hasn't changed the appearance of the shadows.

Share this post


Link to post
Share on other sites

the babylon.max.js file seemed to really screw up the mesh.  The output is really different to the original babylon.js file that I was using.  I will decimate my guy down to a low poly count and see how that turns out

Share this post


Link to post
Share on other sites

I forgot to mention that I'm using Blender to export the mesh.  The mesh itself comes out as expected but when I add shadows it adds strange patterns to the material (regardless of whether there is texture or not).  The mesh only screws up when I'm linking to babylon.max.js 

Share this post


Link to post
Share on other sites

ok, I installed the latest exporter for Blender.  The link using babylon.max.js still looks the same (http://www.punkoffice.com/babylon/luke_new.html)

 

However, the link using the original babylon.js (http://www.punkoffice.com/babylon/luke.html) doesn't cast shadows onto the ground, even though it was before (ground is still set to receive shadows)

Share this post


Link to post
Share on other sites

Ok, I have a link here http://www.punkoffice.com/babylon/test.html

I'm using babylon.2.0-beta.debug.js and the latest Blender exporter.  I created a sphere which has 960 faces.  It is creating shadows.  The ground is created in Babylon HTML code.  Only the ground is receiving shadows.  The sphere creates a shadow with a sharp angle which seems odd.

Share this post


Link to post
Share on other sites

ok, I've moved the light further away.  its now at

light.position = new BABYLON.Vector3(-5, 30, 15);

That made it worse.  Just wondering, has anyone successfully gotten shadows to work with hi-poly meshes?  All the working examples I've seen are of cubes

Share this post


Link to post
Share on other sites

So a quick look at your code:

 

  • no object is in the render list, so of course no shadows will be generated.
  • Light's direction should be normalized (well, not a must since its done at the engine anyhow, but it is a direction :-) ) 
  • The light's position doesn't correlate to the direction. They have to fit (at a certain level) otherwise this won't work.

So, here are some offered changes to start with:

var light = new BABYLON.DirectionalLight("dir", new BABYLON.Vector3(-1, -1, -2).normalize(), newScene);//make sure light's position is correctlight.position = new BABYLON.Vector3(-1, 30, 15);//orlight.position = new BABYLON.Vector3(0, 30, 100);//orlight.position = new BABYLON.Vector3(5, 20, 10);/// A few lines later//Add the mesh to be "shadowed".shadowGenerator.getShadowMap().renderList.push(newScene.meshes[0])

And... Tada :-)

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.