我已经使用着色器图创建了一个着色器(URP)并创建了一个自定义着色器 GUI 来访问 _SurfaceType 关键字,但是从编辑器脚本中更改 _SurfaceType 没有任何作用。有任何想法吗?
if (targetMat.HasProperty("_SurfaceType"))
selectedSurfaceType = (int)targetMat.GetFloat("_SurfaceType");
selectedSurfaceType = EditorGUILayout.Popup(" Surface Type ", selectedSurfaceType, SurfaceType_Enum);
if (EditorGUI.EndChangeCheck())
{
Debug.Log("Changed " + targetMat.shader.name + " " + selectedSurfaceType);
switch (selectedSurfaceType)
{
case 0:
targetMat.SetFloat("_SurfaceType", (int)SurfaceType.Opaque);
//targetMat.SetFloat("_Surface", (int)SurfaceType.Opaque);
targetMat.SetInt("_RenderQueueType", 1);
targetMat.SetFloat("_AlphaDstBlend", 0f);
targetMat.SetFloat("_DstBlend", 0f);
targetMat.SetFloat("_ZTestDepthEqualForOpaque", 3f);
targetMat.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Geometry;
break;
case 1:
targetMat.EnableKeyword("_BLENDMODE_ALPHA");
targetMat.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
targetMat.EnableKeyword("_ENABLE_FOG_ON_TRANSPARENT");
targetMat.DisableKeyword("_BLENDMODE_ADD");
targetMat.DisableKeyword("_BLENDMODE_PRE_MULTIPLY");
//targetMat.SetFloat("_Surface", (int)SurfaceType.Transparent);
targetMat.SetFloat("_SurfaceType", (int)SurfaceType.Transparent);
targetMat.SetFloat("_RenderQueueType", 5);
targetMat.SetFloat("_BlendMode", 0);
targetMat.SetFloat("_AlphaCutoffEnable", 0);
targetMat.SetFloat("_SrcBlend", 1f);
targetMat.SetFloat("_DstBlend", 10f);
targetMat.SetFloat("_AlphaSrcBlend", 1f);
targetMat.SetFloat("_AlphaDstBlend", 10f);
targetMat.SetFloat("_ZTestDepthEqualForOpaque", 4f);
targetMat.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent;
break;
}
}