You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Removing a mesh from a ClippingPrimitive resets all the properties from the material. It clears the properties that the clipping system has set, but the issue is that it also clears all the properties that other systems have set to the material using a MaterialPropertyBlock
To reproduce
Set a color to a material using a MaterialPropertyBlock
Add the render to a clipping primitive
Remove the render from the clipping primitive
Check that the color set in step 1 is lost
You can use this code to reproduce it
using Microsoft.MixedReality.GraphicsTools;using System.Collections;using System.Collections.Generic;using System.Linq;using UnityEngine;publicclassRemoveFromClippingPrimitiveBugTest:MonoBehaviour{publicboolrandomColor=false;publicColorcolor= Color.yellow;publicMaterialmaterial;publicList<MeshRenderer>renderers;privateMaterialPropertyBlockpropBlock;publicClippingPrimitiveclippingPrimitive;publicfloatwaitTime=1f;publicvoidOnEnable(){renderers=this.GetComponentsInChildren<MeshRenderer>().ToList();foreach(var renderer in renderers){
renderer.sharedMaterial =material;}propBlock=new MaterialPropertyBlock();}public IEnumerator Start(){
clippingPrimitive.gameObject.SetActive(false);yieldreturnnew WaitForSeconds(waitTime);
SetColor();//Use property block to set coloryieldreturnnew WaitForSeconds(waitTime);
AddToClippingPrimitive();//Add all renderers to clipping primitiveyieldreturnnew WaitForSeconds(waitTime);
RemoveFromClippingPrimitive();//Remove all renderers to clipping primitive. See how color is lost}privatevoidSetColor(){foreach(var renderer in renderers){Colorc=randomColor? Random.ColorHSV():color;
renderer.GetPropertyBlock(propBlock);
propBlock.SetColor("_Color", c);
renderer.SetPropertyBlock(propBlock);}}privatevoidAddToClippingPrimitive(){
clippingPrimitive.gameObject.SetActive(true);foreach(var renderer in renderers){
clippingPrimitive.AddRenderer(renderer);}}privatevoidRemoveFromClippingPrimitive(){
clippingPrimitive.gameObject.SetActive(false);foreach(var renderer in renderers){
clippingPrimitive.RemoveRenderer(renderer);}}publicvoidUpdate(){if(Input.GetKeyDown(KeyCode.Space)){
SetColor();}if(Input.GetKeyDown(KeyCode.C)){
ClearPropertyBlock();}}privatevoidClearPropertyBlock(){foreach(var renderer in renderers){
propBlock.Clear();
renderer.SetPropertyBlock(propBlock);}}}
This is happing because ClippingPrimitive.RemoveRenderer calls to ClippingPrimitive.ResetRenderer that has this call
Describe the bug
Removing a mesh from a ClippingPrimitive resets all the properties from the material. It clears the properties that the clipping system has set, but the issue is that it also clears all the properties that other systems have set to the material using a MaterialPropertyBlock
To reproduce
You can use this code to reproduce it
This is happing because ClippingPrimitive.RemoveRenderer calls to ClippingPrimitive.ResetRenderer that has this call
MixedReality-GraphicsTools-Unity/com.microsoft.mrtk.graphicstools.unity/Runtime/Clipping/ClippingPrimitive.cs
Line 187 in 9a2f124
Expected behavior
The color (or any other property that is used outside the clipping system) remains.
This was the behavior in MRTK 2.x
Screenshots
2023-12-29.11-25-11.mp4
Your setup (please complete the following information)
Target platform (please complete the following information)
Additional context
The used shader is Graphics Tool/Standard
The text was updated successfully, but these errors were encountered: