satguru

shadow casted by mesh with skeleton not proper

Recommended Posts

I am loading a mesh from a babylon file

The mesh has a skeleton.

The shadow casted by it is not proper.

See file "with_skel.jpg" to check the shadow casted.

Now if i remove the skeleton by doing

mesh.skeleton=null;

The shadow is proper.

See file "without_skel.jpg"

I was able to reproduce the issue in playground but wasn't able to save the  code. I got the error message "file too big" when trying to save.
The code is a little large as it has an embedded scene file.

So I have attached the code here. See file "playground_code,txt" 
Copy the code to playground to check.

comment on/off line 44 to see the issue

 

 

with_skel.jpg

without_skel.jpg

playground_code.txt

Share this post


Link to post
Share on other sites

Do you have the .max version? it could be great to do a diff.

So far if I cancel bones in the shader it works so I was first thinking about an issue with the bones data (and it works for the dude: https://www.babylonjs-playground.com/#07IG98#0)

Edit: Ok this is a precision issue due to the fact we are now using half float :) Add this in your code should work:  shadowGenerator.bias = -0.3;

Share this post


Link to post
Share on other sites

@Deltakosh

Yes  " shadowGenerator.bias = -0.3;" works.

is setting  shadowGenerator.bias  to a negative value "normal" ?
or is this a workaround?

what is it  in the skeleton which results in this? Can I set the bones differently?

 

Share this post


Link to post
Share on other sites

@Deltakosh and @satguru : as I don't have any experience with using shadows with animated figures, the only thought I have is about the figure. Is it a single mesh or multiple separate meshes attached to the skeleton?

cheers, gryff :)

Share this post


Link to post
Share on other sites
On 2017-07-24 at 6:14 PM, Deltakosh said:

I don't know regarding Blender. Perhaps @gryff can help providing guidance on this topic

Well @satguru and @Deltakosh : I took a look at your Vincent character and export from Blender. I made two basic changes to the file:

1. changed the point tlight to a directional light (Sun) and  moved the lamp directly behind the figure.
2. added a ground plane set to receive shadows.

Then exported to a .babylon file with various shadow generating options for the lamp that were default option settings (apart from the shadow map size which I increased to 1024 px.)

Results in image below with the following shadow map setting:

1. Standard
2. Poisson
3. Blur ESM

All exports produced shadows as I expected - look closely and 3 is smoother that 1.

So I did not see the issues that you are having with the presence of the skeleton.And I did not change the bias setting from the default value of the exporter.

Not sure if that helps - but the export from Blender appears fine.

cheers, gryff :)


 

 

shadows1.png

Share this post


Link to post
Share on other sites

@satguru and @Deltakosh - hold up on the above post.

I have managed to produce weird shadows examples below - but first some details.

1. Vincent - Blender Exporter v5.4, BJS is "babylon.3.0.js" that i downloaded May 6th 2017.

2. Vincent - Blender Exporter v5.4, BJS is "babylon.3.0.js" that I downloaded today

Result with BJS 3.1-alpha is the same as 2. :o

So it looks like something happened to the BJS code between May 6th and today that is causing the issue.

Is it something in @JCPalmer 's Exporter (I just used the standard settings apart from Shadow Map size) or is it an issue with BJS ? I suspect the latter as @satguru 's code above appears to be adding the shadow stuff in code.

cheers, gryff :)

EDIT:Actually, I uploaded the wrong "Vincent" .babylon file - one made with Blender Exporter v5.3. I have uploaded the correct "Vincent" file now with the bias set to -.0.3. No shadows for either one. :( I also now see that @satguru says above that it worked for a version of BJS from 06/19/2017. - so mid June.

Code from the v5.4 of the exporter with the shadow info for the light

"producer":{"name":"Blender","version":"2.76 (sub 0)","exporter_version":"5.4.0","file":"vincent2.babylon"},

-----------

"lights":[{"name":"Lamp","id":"Lamp","type":1,"position":[0,5.9039,3.1566],
"direction":[-0.0029,-0.7947,-0.607],"intensity":1,"diffuse":[1,1,1],"specular":[1,1,1]}],
"shadowGenerators":[{"mapSize":1024,"lightId":"Lamp","bias":-0.02995,
"darkness":1,"useBlurExponentialShadowMap":true,"blurScale":2,"blurBoxOffset":0,
"renderList":["Vincent"]}]

 

Share this post


Link to post
Share on other sites

I recently made a scene with a mesh which cast shadows from Blender which also has a skeleton.  I exported in Javascript format, not .babylon though.  I also defaulted on bias, and used ShadowOnlyMaterial, code here.

Also because I had a light attached to the camera, and the camera moved, I use a separate light for shadows with intensity = 0.  I had the shadow Light, shadow generator, and ShadowOnlyMaterial outside of Blender.  Weird things happened during dev.  Think it was my code, not ToB.

Share this post


Link to post
Share on other sites

And just to add to the picture

3. Vincent Blender Exporter v5.3, "babylon.3.0.js" that i downloaded May 6th 2017.

4. Vincent Blender Exporter v5.3,  BJS is "babylon.3.0.js" that I downloaded today

Only options 1 and 3 work as I expected with 1 and 2 giving no shadows,  and 4 something like the results @satguru shows above. (see post below about "darkness")

{"producer":{"name":"Blender","version":"2.76 (sub 0)","exporter_version":"5.3-beta","file":"vincent2.babylon"},

-------

"lights":[{"name":"Lamp","id":"Lamp","type":1,"position":[0,5.9039,3.1566],"direction":[-0.0029,-0.7947,-0.607],"intensity":1,"diffuse":[1,1,1],"specular":[1,1,1]}],
"shadowGenerators":[{"mapSize":1024,"lightId":"Lamp","bias":0,
"useBlurExponentialShadowMap":true,"blurScale":2,
"blurBoxOffset":0,"renderList":["Vincent"]}]

 

Share this post


Link to post
Share on other sites

@gryff

Please  note I am only loading the mesh and skeleton from the file created by the Blender exporter.  I am using the "BABYLON.SceneLoader.ImportMesh(..)" function rather than "BABYLON.SceneLoader.Load(..)" or "BABYLON.SceneLoader.Append(..)". In other words I am ignoring lights, shadow setting etc in the file.  Light and shadows are being set in the code.

 

 

Share this post


Link to post
Share on other sites

@satguru Yes I noted that above

4 hours ago, gryff said:

I suspect the latter as @satguru 's code above appears to be adding the shadow stuff in code.

and it is not working properly with Blender exporter either. And I'm no coder, so it is best not to confuse the issue with any of my code !!:o

I figured out why examples 1 and 2 above throw no shadow - the darkness variable has to be set to 0. It then gives the same results as examples 3 and 4. To me, not a very intuitive way to assign a value to the amount of darkness:unsure: When I do that examples 1 and 2 give the same results as examples 3 and 4.

Options 1 and 3 work as expected - using a version of BJS v3.0 that is about a couple of months old. The latest stable version produces that weird shadow as does the current alpha version. and changing the bias value does not seem to help. Changing the bias value does help - I had changed it to -0.03 not 0.3 as @Deltakosh had suggested.

I have absolutely no idea what this parameter means - and how you might go about setting the correct value for a given situation :unsure:

cheers gryff :)

 

Share this post


Link to post
Share on other sites

@Deltakosh, Yes it works now. Thanks for the fix

@gryff, Thanks for the troubleshooting.

19 hours ago, JCPalmer said:

I recently made a scene with a mesh which cast shadows from Blender which also has a skeleton. 

@JCPalmer Impressive demo. Was  a bit hesitant to click on the link when I read it though, being in office and all. :) 

Share this post


Link to post
Share on other sites
12 hours ago, Deltakosh said:

It should be fixed now :)

Yes indeed :).  Good work @Deltakosh

And here is an up to date demo with looping animation of mesh and shadow.

Vincent

Exported from Blender ( Exporter v5.4) using BJS.3.1-alpha (downloaded this morning)

Blender settings from the default for the shadow export is in image below. Only changes from the default settings: Map Size:1024, Shadow Darkness 0.5 (gives a grey shadow but you can set it to 0 for black).

Hope my investigations did not appear too chaotic  - but two daughters and a grand-daughter and two dogs can make things a little crazy :o

cheers, gryff :)

 

shadows3.png

Share this post


Link to post
Share on other sites

@Deltakosh @gryff

 

we have another problem now.

during animation the mesh is distorted

See file "latest_anim.jpg" to see how the mesh looks in playground with the latest version of bablylonjs

See file "stable_anim.jpg" to see how the mesh looks in playground with the stable version of bablylonjs

The code is again "playground_code.txt"

The code is same as before except for the following new line at line number 46

mesh.skeleton.beginAnimation("walk",true);

 

 

latest_anim.jpg

stable_anim.jpg

playground_code.txt

Share this post


Link to post
Share on other sites

This kind of mesh deformation problem is often because all the mesh is not properly bind to the skeleton. If there is a point that is not taken into account, this create this problem that I regularly had and correct by adjusting this with 3ds max.

I have a character model with 40 animations or all points are well link to the skeleton and no deformation to notice. 

Share this post


Link to post
Share on other sites

I just tested my character that worked very well. But this is not working properly. (whith 3.1)

My character is completely distorted with the animations, which was not the case before.

5987a2d5c097d_2017-08-0701_14_07-Paramtres.jpg.4f9cf80c1280ea4b996d27489f1083e9.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


  • Recently Browsing   0 members

    No registered users viewing this page.