1

I have created a shader(URP) using the shader graph and created a custom shader GUI to access the _SurfaceType keyword, but changing the _SurfaceType from the editor script does nothing. Any ideas?

 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;
        }
    }
Akash Gajbhiye
  • 335
  • 4
  • 17

0 Answers0