GameMonetize Posted September 14, 2017 Share Posted September 14, 2017 We change the shadows to get far more precision and now we can do self shadowing but now the shadows are really sensitive to how bones change the world matrix. Sorry I must be stupid but I cannot find the link to the playground Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted September 14, 2017 Share Posted September 14, 2017 The model is too big for the playground, here is the text file to copy: pcode Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted September 14, 2017 Share Posted September 14, 2017 Yes, shadows are really nice, I just realized .frustumEdgeFalloff exists, the only problem is with skeleton models. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 14, 2017 Share Posted September 14, 2017 Ok after analysing your bones they seem to produce matrices with a negative determinant. Not a big deal, just set shadowGenerator.bias = -1; Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted September 15, 2017 Share Posted September 15, 2017 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 wiggle.blend Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 15, 2017 Share Posted September 15, 2017 There is something wrong in the matrices because if I manually fix them it works: (see line#31) https://www.babylonjs-playground.com/#DCYRZX#6 Here is the code used to try to clean the indices:https://github.com/BabylonJS/Babylon.js/blob/master/src/Mesh/babylon.geometry.ts#L1003 Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted September 16, 2017 Share Posted September 16, 2017 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; } } } } Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 18, 2017 Share Posted September 18, 2017 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? Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted September 20, 2017 Share Posted September 20, 2017 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! Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 20, 2017 Share Posted September 20, 2017 Correct. Do you want to try to update the function that cleans the matrices? Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted September 22, 2017 Share Posted September 22, 2017 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? Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted September 22, 2017 Share Posted September 22, 2017 This is cool! Basically you can fork bjs again, apply this change and do the PR Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted September 23, 2017 Share Posted September 23, 2017 PR sent! (I could not fork another copy from the same repo from github, maybe with some command line git I don't know. But I'm now using another github account) Quote Link to comment Share on other sites More sharing options...
satguru Posted December 11, 2017 Author Share Posted December 11, 2017 @BitOfGold Is your PR in? I find that I still need to do "shadowGenerator.bias=-0.3;" Quote Link to comment Share on other sites More sharing options...
BitOfGold Posted December 11, 2017 Share Posted December 11, 2017 @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; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.