Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Bug / Crash  Material property changes don't work with ObiCloth
#1
(I'm not sure if this is a bug, or an unsupported feature, or if I'm doing something wrong!)
  • We have a character in our game who wears a gown. The gown uses an Obi SkinnedCloth component for its cloth simulation.
  • If the character takes damage, the gown becomes "bloodied".
  • To do the bloody-gown effect, we're animating a property on its Material instance; a shader uses the property to do some color blending.
This all works properly when we use Unity cloth:

   

But when we use Obi cloth, changes to the gown Material's properties don't do anything:

   

(If we change the *master* Material's properties, we *can* get the bloody-gown effect to work with Obi - but of course, that means that all gowns share the "bloody" status.)

Why is this happening, and is there a way to solve it? Thanks!
Reply
#2
(01-11-2021, 11:25 PM)timconkling Wrote: (I'm not sure if this is a bug, or an unsupported feature, or if I'm doing something wrong!)
  • We have a character in our game who wears a gown. The gown uses an Obi SkinnedCloth component for its cloth simulation.
  • If the character takes damage, the gown becomes "bloodied".
  • To do the bloody-gown effect, we're animating a property on its Material instance; a shader uses the property to do some color blending.
This all works properly when we use Unity cloth:
But when we use Obi cloth, changes to the gown Material's properties don't do anything:

Hi Tim!

The reason for this is that Obi uses the list of shared materials in the renderer to render the cloth itself, since SkinnedMeshRenderer does not allow certain features needed for cloth rendering. Go to line 69 of ObiSkinnedClothRenderer.cs, and change:

Code:
skin.GetSharedMaterials(rendererMaterials);

to

Code:
skin.GetMaterials(rendererMaterials);

That should do it.

(01-11-2021, 11:25 PM)timconkling Wrote: (If we change the *master* Material's properties, we *can* get the bloody-gown effect to work with Obi - but of course, that means that all gowns share the "bloody" status.)

Do you mean the renderers sharedMaterial? This works the same way in Obi as in any other renderer: the sharedMaterial is a reference to a single material, shared by all renderers using it. As soon as you call renderer.material, an independent instance of the sharedMaterial is created and assigned to the renderer.

Using the individual material instances instead of the shared materials (by changing the line of code above) will do the trick.
Reply
#3
(02-11-2021, 08:09 AM)josemendez Wrote: Hi Tim!

The reason for this is that Obi uses the list of shared materials in the renderer to render the cloth itself, since SkinnedMeshRenderer does not allow certain features needed for cloth rendering. Go to line 69 of ObiSkinnedClothRenderer.cs, and change:

Code:
skin.GetSharedMaterials(rendererMaterials);

to

Code:
skin.GetMaterials(rendererMaterials);

That should do it.

Thanks! Is this something that will be officially supported by ObiCloth in the future (either by default, or via a toggle on the ObiSkinnedClothRenderer)?

*Edit: this seems to be a partial fix for the issue, but I'm not actually getting bloody-gown action yet. The instanced material property is getting updated as we'd expect, but it looks like the property changes are not actually being written to the GPU. At runtime, the gown remains un-bloodied. I can "fix" this by opening the gown's material inspector at runtime and changing any property inside it, which triggers (presumably) an upload of all properties to the GPU.

We're modifying the material property via a simple Unity animation that looks like this:

   

The Body mesh's "_Stain Amount" property is being sent the GPU. (This mesh does not use ObiCloth.) The Gown's two properties are not being updated. (Or rather: I can see the updated values in the inspector, but they don't result in any visual changes.)
Reply
#4
(02-11-2021, 08:41 PM)timconkling Wrote: Thanks! Is this something that will be officially supported by ObiCloth in the future (either by default, or via a toggle on the ObiSkinnedClothRenderer)?

Hi!

Yes, I think this makes more sense for this to be the default behavior. All future updates will contain this change.
Reply
#5
(02-11-2021, 09:06 PM)josemendez Wrote: Hi!

Yes, I think this makes more sense for this to be the default behavior. All future updates will contain this change.

Great!

And apologies for editing the post you were replying to while you were replying but just want to flag that this doesn't seem to be a complete solution (see the edit I just made to the previous post.)
Reply
#6
(02-11-2021, 09:24 PM)timconkling Wrote: Edit: this seems to be a partial fix for the issue, but I'm not actually getting bloody-gown action yet. The instanced material property is getting updated as we'd expect, but it looks like the property changes are not actually being written to the GPU. At runtime, the gown remains un-bloodied. I can "fix" this by opening the gown's material inspector at runtime and changing any property inside it, which triggers (presumably) an upload of all properties to the GPU.

Hi!

Animating properties using an animation clip does not modify the material. That's why even though the renderer is using an instance instead of the shared material, changes are not being made.

Animations use MaterialPropertyBlocks. (https://docs.unity3d.com/ScriptReference...Block.html)

Only if you modify the material itself -for instance, animating its values trough a script- will the changes have any effect. Obi's skinned renderer does not expose material property blocks as of now (no reason other than I didn't get to it yet). Adding support for them should be simple, will get back to you asap.
Reply
#7
Took no time Sonrisa.

Please find ObiSkinnedClothRenderer.cs attached, replace yours with it. This adds support for material property blocks, works properly with animation clips.

This will of course be part of the retail version of Obi, included in all future updates.


Attached Files
.cs   ObiSkinnedClothRenderer.cs (Size: 3.59 KB / Downloads: 6)
Reply
#8
(03-11-2021, 08:44 AM)josemendez Wrote: Took no time Sonrisa.

Please find ObiSkinnedClothRenderer.cs attached, replace yours with it. This adds support for material property blocks, works properly with animation clips.

This will of course be part of the retail version of Obi, included in all future updates.

Thanks, this works great!
Reply