Bug / Crash Material property changes don't work with ObiCloth - Printable Version +- Obi Official Forum (https://obi.virtualmethodstudio.com/forum) +-- Forum: Obi Users Category (https://obi.virtualmethodstudio.com/forum/forum-1.html) +--- Forum: Obi Cloth (https://obi.virtualmethodstudio.com/forum/forum-2.html) +--- Thread: Bug / Crash Material property changes don't work with ObiCloth (/thread-3160.html) |
Material property changes don't work with ObiCloth - timconkling - 01-11-2021 (I'm not sure if this is a bug, or an unsupported feature, or if I'm doing something wrong!)
[attachment=1149] But when we use Obi cloth, changes to the gown Material's properties don't do anything: [attachment=1150] (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! RE: Material property changes don't work with ObiCloth - josemendez - 02-11-2021 (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!) 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. RE: Material property changes don't work with ObiCloth - timconkling - 02-11-2021 (02-11-2021, 08:09 AM)josemendez Wrote: Hi Tim! 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: [attachment=1153] 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.) RE: Material property changes don't work with ObiCloth - josemendez - 02-11-2021 (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. RE: Material property changes don't work with ObiCloth - timconkling - 02-11-2021 (02-11-2021, 09:06 PM)josemendez Wrote: Hi! 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.) RE: Material property changes don't work with ObiCloth - josemendez - 03-11-2021 (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/MaterialPropertyBlock.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. RE: Material property changes don't work with ObiCloth - josemendez - 03-11-2021 Took no time . 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. RE: Material property changes don't work with ObiCloth - timconkling - 03-11-2021 (03-11-2021, 08:44 AM)josemendez Wrote: Took no time . Thanks, this works great! |