您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
53 行
2.3 KiB
53 行
2.3 KiB
using UnityEngine;
|
|
using UnityEngine.Rendering;
|
|
|
|
namespace UnityEditor.Experimental.Rendering.LightweightPipeline
|
|
{
|
|
public static class LightweightShaderHelper
|
|
{
|
|
public static void SetMaterialBlendMode(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 SetKeyword(Material material, string keyword, bool enable)
|
|
{
|
|
if (enable)
|
|
material.EnableKeyword(keyword);
|
|
else
|
|
material.DisableKeyword(keyword);
|
|
}
|
|
}
|
|
}
|