Jump to content

shadow casted by mesh with skeleton not proper


satguru
 Share

Recommended Posts

Thanks for helping and checking!

So the exporter is producing wrong matrices?
Or something changed while importing the skeleton?

I made a minimal blender file with skeleton animation and exported it. (attached)
I think there is nothing wrong with it. It cannot be simpler.

Here is the playground:
http://www.babylonjs-playground.com/#DCYRZX#5

So, I can set the bias to -1 and the shadows are working in the playground, but it's not a solution in my game.
I cannot set the bias to -1 everywhere, it just not works, everything is dark then (even the lit sides of the walls), I have to use a value like 0.00002.

I'm stuck with this :(
 

bias-1.jpg

wiggle.blend

Link to comment
Share on other sites

You were right, the wrong matrix weights caused the shadow problems. If sum of weights is not 1.0, the influencer matrix in the end will be bad.

I have re-written this cleaning function, it just distorted the weights. (I think, i really tried to understand...)

This new code normalizes the weights so the sum will be 1.0, no matter if it was less then 1.0 or more.
The result looks good with all meshes I tried - the only thing left is, part of my goblin mesh has zero on all weights. so no influence I think. That part of the mesh still looks bad and inverse, and I don't know how to correct it.

 

        private static _CleanMatricesWeights(matricesWeights: number[]): void {
            if (!SceneLoader.CleanBoneMatrixWeights) {
                return;
            }
            let size = matricesWeights.length;
            for (var i = 0; i < size; i += 4) {
                let weight = 0;
                for (var j = 0; j < 4; j++) {
                    weight += matricesWeights[i + j];
                }
                if (weight>0.0) {
                    let mweight = 1.0/weight;
                    for (var j = 0; j < 4; j++) {
                        matricesWeights[i + j] *= mweight;
                    }
                }
            }
        }


 

shadow-part.jpg

shadow-z.jpg

Link to comment
Share on other sites

The real problem is the one you are mentioning. When all weights are 0. The resulting code will obviously be wrong.

 

Here is an idea:

The bone matrices will contain an unchanged matrix at index bones.length. So perhaps the idea could be to also update matrices indices and just point to this identity matrix.

Does it make sense?

Link to comment
Share on other sites

Yes that would be perfect.
Zero influence is "legit" in meshes In my opinion, if I make a flag with a flagpole and weight-paint only the flag to move etc.

One more thing when for example the only weight (of only one bone) is low like 0.1
That means only a little infuence.
Maybe then the weights sould be
0.1 the minimally influencing bone
0.9 the "identity bone"

it can happen with weight paint like my model, so maybe my normalization of weight (if sum is under 1.0) is not correct!
 


 

Link to comment
Share on other sites

Now it's working perfectly!
With every mesh I tried.
I had to move the function into babylon.sceneLoader.ts, because the skeletons are not ready when parsing the geometry.

Here is the diff:
https://github.com/BitOfGold/Babylon.js/commit/e0e8a24e9bbdb0d8c4528441f4b82b8b2bee03e7

I don't know how to send a PR from this because there are many other changes in my fork/master.
I think I cannot do that without making another github user and another fork?
 

shadowaok.jpg

Link to comment
Share on other sites

  • 2 months later...

@satguru yes, no problem with my models now.
Maybe it's another, different error.
Negative scale can look similar bad with shadows.

A very similar bad transparent/distorted look was with (when using PBR material), the setting of alphaMode (I had to set it 0)

mo.material.subMaterials[0].specularColor = new C3(0.4,0.4,0.4);
mo.material.subMaterials[0].alphaMode = 0;
mo.material.subMaterials[1].specularColor = new C3(0.12,0.12,0.12);
mo.material.subMaterials[1].alphaMode = 0;

 

Link to comment
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...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...