-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Batching skins and custom shader chunks #1233
Conversation
src/graphics/program-lib/basic.js
Outdated
if (options.chunks) { | ||
var customChunks = {}; | ||
var newP; | ||
var p; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please update this PR to have 4 spaces instead of tabs?
After the discussion on whether basic.js should include support for custom chunks, i decided to revert back to to original and instead just rely on standard.js the main choice of material to use. Essentially, with the right settings, standard.js can easily emulate any unlit material, right? So, basic.js is just for legacy purposes it seems. Regarding batching, when is clone(batch, meshInstances) method being used? I don't see any immediate case of it being used within the batch.js codebase itself. Regarding inverse bind poses from skin's rigs, from what I remembered, they are precomputed beforehand and remain immutable right? ie.They aren't modified during rendering so it should be safe to re-use the exact same reference instances of inverse bind poses from the same rig, without deep-cloning them, right? |
Batched skinning is something I’m interested in with regards optimising a
project - will Glenn’s changes be integrated to enable this feature?
…On Saturday, June 9, 2018, Glenn Ko ***@***.***> wrote:
After the discussion on whether basic.js should include support for custom
chunks, i decided to revert back to to original and just rely on
standard.js the main choice of material to use. Essentially, with the right
settings, standard.js can easily emulate any unlit material, right? So,
basic.js is just for legacy purposes it seems.
Regarding batching, when is clone() method being used? I don't see any
immediate case of it being used within the batch.js codebase itself.
Regarding inverse bind poses from skin's rigs, from what I remembered, they
are precomputed beforehand and remain immutable right? ie.They aren't
modified during rendering so it should be safe to re-use the exact same
reference instances of inverse bind poses for the same rig, without
deep-cloning them, right?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1233 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AE7yT0455uKZHjXuV1YaNMU9D5Twi4FPks5t6-gFgaJpZM4UfbK3>
.
|
src/scene/batching.js
Outdated
material.chunks.transformVS = this.transformVS; | ||
material.chunks.skinTexVS = this.skinTexVS; | ||
material.chunks.skinConstVS = this.skinConstVS; | ||
material.chunks.transformVS = this.boneLimit + "#define DYNAMICBATCH\n" + (material.chunks.transformVS ? material.chunks.transformVS : pc.shaderChunks.transformVS); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep in mind that shaders with DYNAMICBATCH define implement skinning with just one bone:
https://github.com/playcanvas/engine/blob/master/src/graphics/program-lib/chunks/transform.vert#L17
If you want proper batched skinning, you need to make shaders use SKIN define instead of it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... like:
material.chunks.transformVS = this.boneLimit + "#define "+(!isSkin ? "DYNAMICBATCH" : "SKIN")+"\n" + (material.chunks.transformVS ? material.chunks.transformVS : pc.shaderChunks.transformVS);
Is this correct? Looks like it's not just that.... I think you mean with various blend weights across possibly multiple bones, right? As the supplied inputs must also include the relavant weights if needed. Hmm.... Looks like the previous animation tests didn't blend the bones and i didn't noticed it. Gotta see how to get this to work proper when i hav the time though.. It seems with teh SKIN define, it has problems accessing x,y,z,w properties it seems? That's weird. Maybe it's because it ALWAYS assumes component size of 4 always?
Oh wait...so that's Playcanvas skinning convention? It always uploads bone component size of 4 always for skins, regardless of the actual model setup by the artist? Isn't that slightly wasteful for VRAM for some skins that don't require blending of all 4 components? (i might be wrong, i think component size of 1 still takes up all 4 registers?). But i guess this simplifies the shader setup though, otherwise need differnet vertex program for different skin blend amounts. Or, if i'm not wrong, eg. the y,z,w properties will default to zero if only component size 1 skin is used...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all shader-based game engines I ever saw or reverse engineered used 4 bones per-vertex, because it's usually enough, and you don't really want to to compile/switch more shaders just because some objects use less. And 4 bone indices fit neatly into 4 bytes, and you can't have less for a vertex attribute. So PlayCanvas too used 4 bones per vert from the beginning. All imported FBX models are set up to use 4.
Dynamic batching is basically a specialized skinning mode that only uses 1 bone and no weights. But if you want to batch skins, then you'll need to switch shaders to a "normal" skinning mode with 4 bones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant what if the skin had less than 4 blends, etc. But anyway...yea, it would mean having to create a differnet program setup for a trivial thing just to shave off a bit of bytes seems pointless.
Ok, i did up some changes, working fine now, you can preview the results in:
https://playcanv.as/p/3QlSEgHF/
Aha, now the animations look much more fluid/real now. Previously, there wasn't any blending. Lol, didn't realised.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ignore that, urm...was trying to test if IK was possible so i can align it with terrain slopes..... If you got any advice on how to get it to work, perhaps you can help. I just need basic IK solver to solve knee to ankle based off ankle position (y offset), ...also prefably solve ankle base to foot tip alignment along slope for sole base. Perhaps, the rig must be set up with certain conventions to help make the process simpler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Skin blending fox for batching: The changes up above, some 3 lines changed so it uses original skinning routine to keep the original blendings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(deleted duplicate)
BTW, I recommend testing if the combined mesh AABB is still correct for batched skins and doesn't waste performance. Right now batched mesh AABB is a combination of underlying mesh instances' AABBs: And skinned underlying instances will try to use their transformed matrices to generate full mesh AABB: Matrices are calculated for all draw calls before rendering: But given batching removes original models from the list of draw calls... perhaps they'll stop updating. That means you probably need to patch BatchManager.prototype.update() to generate the AABB using the matrices you build in SkinInstanceBatched. Here is a simple AABB visualization script: https://playcanvas.com/project/342895/overview/skinbounds |
It should be the same as regular meshes ( which also has a ".skinInstance" ) though I'm not too sure for playcanvas if skinned mesh (ie. the one skinned with animations) conservatively uses the largest possible bounding box based off all it's animations. ( I assume it should?? Oh ...it looks like it doesn't ...). Taking this further I might handle culling manually on my own via Okay, wait, it seems that the batch's Important tip to avoid unnecessary calculations: When calling
Notice that |
Okay, i'd proably need to update/redo this pull request to only pull from a proper branch with ONLY 1 file ( To recap, contrary to what guycalledfrank mentioned, Playcanvas engine DOES update the batched skins, and you don't need to call update() manually. (However, I do know that this generalised approach may not be very performant so I've personally considered ways of circumventing this dynamic batch bounding boxes updates if performance is a concern...such as manually force-flagging It appears that somehow skinned meshInstances must remain within the scene's layer composition (ie. remain within the draw call array list!) in order to have their individual bounding boxes update correctly per frame. Otherwise, the bounding boxes appear shorter than usual (even though they still morph/adjust themselves with the animations). Why? Something to do with skinned meshes having skin binding transform updates that only apply within renderComposition of forward-renderer.js? The project describing the above problem can be found in: Okay, so the real (suggested/to-be-discussed ) fix would be under this project: Basically, I added provision for original skinned meshes in
|
All changes in batching.js file....
batching.js code comment. And add support for batching animated Skinned models? #1231
Allow custom vertex shader chunks to work with dynamic batching #1227
Other changes to graphics/material files:
I confirm I have signed the Contributor License Agreement.