Using deformer graphs to achieve cloth simulation on meshes with morph targets

For some time I’ve been curious about getting cloth painting+simulation to work on meshes that have morph targets. Currently, by default, cloth simulation does not work on meshes that have morph targets. When the cloth data asset is applied to a mesh’s material zone, it does nothing if the mesh has morphs.

However, I noticed that there is a deformer graph labeled “DG_LinearBlendSkin_Morph_Cloth” in the content examples. The description of this graph says the following:


A plain-face reading of this description makes it seem clear that the graph should support cloth simulation AND morph targets, as it says “All features of those pipelines are supported using this graph.” However, when applying this graph, it allows a mesh with morphs to simulate cloth physics, but the morphs themselves do nothing when applied. So, it’s not a solution to the problem of using morph targets with cloth physics.

My question is, is this intended behavior? Or possibly an oversight? Or am I using the graph wrong somehow, and it does actually do what it says it does?

2 Likes

Hi Any luck on this? . you can use partly skinned and partly cloth sim. but i also want to use the morphhs. please let me know

1 Like

Hey I found this thread through google looking for the same thing.
It doesn’t seem to work at least not out of the box, hoping someone with more experience will reply! :slight_smile:

1 Like

hey im looking into vertex shaders, skinning and cloth sim mixed, or just using rigid bodys. if you get a solution please post

No solution yet. Vertex shader is one possibility, though it becomes unreasonably complex to manage if you’re dealing with customizable characters with many different body shapes. Splitting clothing into separate zones, simulating one zone and using morphs on the other also doesn’t work that well, since the mesh geometry will easily break when applying morphs.

The best solution in my case would just be to have morphs and cloth physics active at the same time. I’m not a skinning or physics expert, so I don’t know if this is perhaps difficult to implement, hence why there’s no easy solution for this yet. Though from what I understand, this exact thing used to exist in earlier versions of UE4.

Okay. Thanks for the comprehensive information. I ended up using a skinned mesh for the area that needed free motion and the whole cloth is driven by the skinned section above it to achieve the effect I wasn’t. Although I ran into some issues with the bones and anim dynamics(more specifically the angular limits not constraining to the set values, maybe because it is a chain. I have a post if you can check it out if you can assist . https://forums.unrealengine.com/t/anim-dynamics-angular-limits-constraint-ignored-in-chain-mode/1836248.).
I think in the future I will look into an motion matching generator from the Ml deformer. Although in my head that seems to be just creating hundreds of animations. Thanks for the info.

Can anyone from Epic comment on this?

I’m in the same position, and have tried the deformer graphs that combine morph targets with cloth. As soon as cloth sim is enabled we get no data from the morph target node.

Given that these graphs lerp between the cloth and morph data, it must work in some configuration, or have worked at some point!

Would be great to get a comment from someone involved, to avoid spending ages pointlessly investigating it if it actually doesn’t work anymore

Thanks :slight_smile:

I tested this in 5.4 and still seems like DG_LinearBlendSkin_Morph_Cloth is not working as intended. Would love to have some clarity on this or hear from anyone who has this working.

What about order of operations?

What you have is a chicken or egg problem.

The obvious solution is to make the chicken the first thing so it can hatch the egg.

Morphs work on vertex by moving them.
Cloth works on vertex by moving them.

If cloth is applied after the morphs, then the morphs will not matter, the cloth will just simulate.

On the other hand, maybe, if you apply morphs after a simulation (or on top of it) you can get some kind of a result.

Quite honestly though, the whole concept is sheer BS. Could lead to some cool-ish effects, sure.
But so could adding and weight painting bones to do exactly what you need on top of the cloth without having to go beating around the bush for a different approach.
On top of that, you can author exact animations in any DCC if you do it right, so there really is very little to gain.

As far as why the function exists - its probably the starting point (and may even work if used correctly) to allow merged meshes to run both morphs and cloth at the same time.
Think fortnite. ideally you need to be able to merge a face while retaining its morphs onto a cape wearing body mesh while retaining the cloth sim.

These would however be different sections / not affecting the same verts (or mesh) before the programmatic (runtime) merge.

Now, afaik, the runtime merge for 4.25/27 still wont allow both things to work.
In fact, the only reason morphs are retained is that vertex groups are contained within their definitions and so the merge process preserves the groups.
Cloth definitions on the other hand are just rendered invalid by the merge re-indexing process…

I was finally able to resolve this problem, though the solution wasn’t as straightforward as I’d hoped it’d be. My idea was to copy skinned mesh vertex data from a non-simulating skeletal mesh with morphs to a simulating cloth asset:

Using a deformer graph I was able to read the verts and morph offset data from the (hidden) skinned mesh, and apply them to the simulated cloth asset. However initially this resulted in hard edges at the boundary of the skinned mesh region and the simulated region:

So I painted a smooth gradient on the skinned mesh with vertex color:

And in deformer graph read the influence/weight value of the red channel and used it to lerp between the skinned position and cloth position. Here’s the full HLSL:

bool AreEqual(float3 a, float3 b) {
    return (a.x == b.x) && (a.y == b.y) && (a.z == b.z);
}

KERNEL
{
    if (Index >= ReadNumThreads().x) return;
    
    float3 LocalPosition = ReadPosition(Index);

    float3 MorphDelta = SkeletalMesh::ReadDeltaPosition(Index);
    float3 MorphedPosition = LocalPosition + MorphDelta;

    float3x4 BoneMatrix = SkeletalMesh::ReadWeightedBoneMatrix(Index);
    float3 SkinnedPosition = mul(BoneMatrix, float4(MorphedPosition, 1));
    
    float3 ClothWeight = ReadClothWeight(Index) * SkeletalMesh::ReadInfluence(Index);
    float3 ClothPosition = ReadClothPosition(Index) + MorphDelta;
    float3 LocalClothPosition = mul(float4(ClothPosition, 1), ReadClothToLocal()).xyz;
    float3 FinalPosition = lerp(SkinnedPosition, LocalClothPosition.xyz, ClothWeight);
    
    if (!AreEqual(ReadPosition(Index), ReadClothPosition(Index)))
        WriteOutPosition(Index, FinalPosition));

}

This gave a clean result when applying the morph data.

However there’s still the problem of collisions. The first issue is that cloth simulation collides with physics capsules, and morph targets do not update the position or scale of physics capsules. Translating/scaling bones however DOES update the collider associated with that bone. So the key is to use a combination of pose assets AND morph targets simultaneously, so you can get the detail from the morph target while also updating the bone positions to match the new shape. This will in turn ensure the colliders are in the correct position when the morph+pose is applied and therefore prevent clipping with the cloth asset.

But there’s another problem, and that is that capsule colliders alone don’t provide a satisfactory result in terms of both visual and preventing clipping with the cloth asset, at least they didn’t on my character.

So for a better collision result I added a kinematic collider to the cloth asset using a low-poly proxy mesh of my character. This video explains how. The neat thing is, since we are projecting the skinning weights from the character mesh to the low poly proxy mesh, the proxy mesh will also update its position and shape in accordance with morphs, since we are now also using pose assets to change the positions of bones when a morph is applied. This leads to an even better collision result since we’re using BOTH physics capsules that update with morphs AND a kinematic mesh that updates with morphs.

Suffice to say I will be marking this problem as resolved since the answer is clearly yes, deformer graphs can be used for the purposes of achieving cloth sim with morphs, it’s just a huge pain in the ■■■. But it does work!

1 Like

This is brilliant!
Would you consider sharing the entire deformer graph?

1 Like

This is incredible work! I would love to see some kind of binding of cloth the way the groom binding asset works as it follows blend shapes. But this looks like a great workaround to this issue!

I get the intention, but aren’t you colliding the non expanded skirt that is attached and hidden to read vertex positions onto the larger leg definition?

If the cloth is not reacting to the acual geometry - whats the point of having it simulate?

That, (which you sort of covered explaining alternative to) and also:
isn’t the whole thing one frame behind?

Im still of the opinion that just using skeletal elements and bone scaling is preferrable to combining Morphs and Cloth.
However I do apploaud you figuring this out and sharing.

The hidden skinned mesh does not contribute or act on collisions at all, it exists only to read from the morph delta positions of the skirt when a morph target is applied to it.

The cloth does react to the changing geometry. As I noted above, since I am blending a pose asset when a morph target is applied, the bone positions change and the capsule colliders along with them. The cloth will collide with the updated capsule positions:

The kinematic collider specified in the cloth asset is also updating with the new shape, since we are projecting the character weights to it, which are changing with the applied morph/pose. If I were to completely disable the physics asset the cloth would still collide with the kinematic collider, since I am using both the physics asset and a kinematic collider at the same time for collisions. However the kinematic collider doesn’t show when showflag.collision is used.

I’m not sure if it’s one frame behind, that would depend on when the compute kernel is applied, I would assume it executes on the same frame as the cloth solver but I haven’t confirmed that. If it’s one frame behind I haven’t noticed it being problematic in my case, though perhaps it would be in some projects

This method does rely on skeletal elements as you suggest, otherwise it wouldn’t be possible for the collisions to update. The morph targets are purely to add detail to the final result, which can be tricky using bone manipulations alone.

1 Like

There’s a specific Physx flag for this - and with Chaos it probably got changed but you can give it a try anyway
~ PXVIS COLLISION 1

And since you are in a character the other possibility is you Show Debug Animation, tab to the character which exposes the bones and the collisions for it.

Got it - I thought you had it the other way around - simulate on the regular small one, then apply it over the stretched one. The opposite makes more sense.

1 Like