private void DoBlendMode() { int modeValue = (int)blendModeProp.floatValue; EditorGUI.BeginChangeCheck(); modeValue = EditorGUILayout.Popup(Styles.renderingModeLabel, modeValue, Styles.blendNames); if (EditorGUI.EndChangeCheck()) { blendModeProp.floatValue = modeValue; } UpgradeBlendMode mode = (UpgradeBlendMode)blendModeProp.floatValue; EditorGUILayout.Space(); if (mode == UpgradeBlendMode.Opaque) { int glossSource = (int)glossinessSourceProp.floatValue; m_MaterialEditor.TexturePropertySingleLine(Styles.albedoGlosinessLabels[glossSource], albedoMapProp, albedoColorProp); m_MaterialEditor.TextureScaleOffsetProperty(albedoMapProp); } else { m_MaterialEditor.TexturePropertySingleLine(Styles.albedoAlphaLabel, albedoMapProp, albedoColorProp); m_MaterialEditor.TextureScaleOffsetProperty(albedoMapProp); if (mode == UpgradeBlendMode.Cutout) { m_MaterialEditor.RangeProperty(alphaCutoffProp, "Cutoff"); } } }
private static void UpdateMaterialBlendMode(Material material) { UpgradeBlendMode mode = (UpgradeBlendMode)material.GetFloat("_Mode"); switch (mode) { case UpgradeBlendMode.Opaque: material.SetOverrideTag("RenderType", ""); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); SetKeyword(material, "_ALPHATEST_ON", false); SetKeyword(material, "_ALPHABLEND_ON", false); material.renderQueue = -1; break; case UpgradeBlendMode.Cutout: material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); SetKeyword(material, "_ALPHATEST_ON", true); SetKeyword(material, "_ALPHABLEND_ON", false); material.renderQueue = (int)RenderQueue.AlphaTest; break; case UpgradeBlendMode.Alpha: material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); SetKeyword(material, "_ALPHATEST_ON", false); SetKeyword(material, "_ALPHABLEND_ON", true); material.renderQueue = (int)RenderQueue.Transparent; break; } }
public static void SetMaterialBlendMode(Material material) { bool enableTransparent = material.IsKeywordEnabled("_ALPHABLEND_ON"); bool enableAlphaTest = material.IsKeywordEnabled("_ALPHATEST_ON"); bool enablePremultiply = material.IsKeywordEnabled("_ALPHAPREMULTIPLY_ON"); UpgradeBlendMode mode = UpgradeBlendMode.Opaque; float blendValue = 0; float surfaceTypeValue = 0; if (enableAlphaTest) { mode = UpgradeBlendMode.Cutout; } else if (enableTransparent) { surfaceTypeValue = 1; blendValue = 0; mode = UpgradeBlendMode.Alpha; } else if (enablePremultiply) { surfaceTypeValue = 1; blendValue = 1; mode = UpgradeBlendMode.Premultiply; } material.SetFloat("_Blend", blendValue); material.SetFloat("_Surface", surfaceTypeValue); switch (mode) { case UpgradeBlendMode.Opaque: material.SetOverrideTag("RenderType", ""); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.SetFloat("_AlphaClip", 0.0f); SetKeyword(material, "_ALPHATEST_ON", false); SetKeyword(material, "_ALPHABLEND_ON", false); SetKeyword(material, "_ALPHAPREMULTIPLY_ON", false); material.renderQueue = -1; break; case UpgradeBlendMode.Cutout: material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero); material.SetInt("_ZWrite", 1); material.SetFloat("_AlphaClip", 1.0f); SetKeyword(material, "_ALPHATEST_ON", true); SetKeyword(material, "_ALPHABLEND_ON", false); SetKeyword(material, "_ALPHAPREMULTIPLY_ON", false); material.renderQueue = (int)RenderQueue.AlphaTest; break; case UpgradeBlendMode.Alpha: material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.SetFloat("_AlphaClip", 0.0f); SetKeyword(material, "_ALPHATEST_ON", false); SetKeyword(material, "_ALPHABLEND_ON", true); SetKeyword(material, "_ALPHAPREMULTIPLY_ON", false); material.renderQueue = (int)RenderQueue.Transparent; break; case UpgradeBlendMode.Premultiply: material.SetOverrideTag("RenderType", "Transparent"); material.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One); material.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha); material.SetInt("_ZWrite", 0); material.SetFloat("_AlphaClip", 0.0f); SetKeyword(material, "_ALPHATEST_ON", false); SetKeyword(material, "_ALPHABLEND_ON", false); SetKeyword(material, "_ALPHAPREMULTIPLY_ON", true); material.renderQueue = (int)UnityEngine.Rendering.RenderQueue.Transparent; break; } }