浏览代码

Split blend enum into two

/main
Matt Dean 7 年前
当前提交
fcd875c3
共有 6 个文件被更改,包括 94 次插入48 次删除
  1. 4
      com.unity.shadergraph/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs
  2. 4
      com.unity.shadergraph/Editor/Data/LightweightPipeline/LightWeightUnlitSubShader.cs
  3. 14
      com.unity.shadergraph/Editor/Data/MasterNodes/AlphaMode.cs
  4. 19
      com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs
  5. 19
      com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs
  6. 82
      com.unity.shadergraph/Editor/Data/Util/ShaderGenerator.cs

4
com.unity.shadergraph/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs


if (masterNode.IsSlotConnected(PBRMasterNode.AlphaThresholdSlotId))
defines.AddShaderChunk("#define _AlphaClip 1", true);
if(masterNode.alphaMode == AlphaMode.Transparent)
if(masterNode.surfaceType == SurfaceType.Transparent && masterNode.alphaMode == AlphaMode.Premultiply)
defines.AddShaderChunk("#define _ALPHAPREMULTIPLY_ON 1", true);
var templateLocation = ShaderGenerator.GetTemplatePath(template);

subShader.Indent();
subShader.AddShaderChunk("Tags{ \"RenderPipeline\" = \"LightweightPipeline\"}", true);
var materialOptions = ShaderGenerator.GetMaterialOptions(masterNode.alphaMode, masterNode.twoSided.isOn);
var materialOptions = ShaderGenerator.GetMaterialOptions(masterNode.surfaceType, masterNode.alphaMode, masterNode.twoSided.isOn);
var tagsVisitor = new ShaderGenerator();
materialOptions.GetTags(tagsVisitor);
subShader.AddShaderChunk(tagsVisitor.GetShaderString(0), true);

4
com.unity.shadergraph/Editor/Data/LightweightPipeline/LightWeightUnlitSubShader.cs


if (masterNode.IsSlotConnected(UnlitMasterNode.AlphaThresholdSlotId))
defines.AddShaderChunk("#define _AlphaClip 1", true);
if(masterNode.alphaMode == AlphaMode.Transparent)
if(masterNode.surfaceType == SurfaceType.Transparent && masterNode.alphaMode == AlphaMode.Premultiply)
defines.AddShaderChunk("#define _ALPHAPREMULTIPLY_ON 1", true);
var templateLocation = ShaderGenerator.GetTemplatePath(template);

subShader.Indent();
subShader.AddShaderChunk("Tags{ \"RenderType\" = \"Opaque\" \"RenderPipeline\" = \"LightweightPipeline\"}", true);
var materialOptions = ShaderGenerator.GetMaterialOptions(masterNode.alphaMode, masterNode.twoSided.isOn);
var materialOptions = ShaderGenerator.GetMaterialOptions(masterNode.surfaceType, masterNode.alphaMode, masterNode.twoSided.isOn);
var tagsVisitor = new ShaderGenerator();
materialOptions.GetTags(tagsVisitor);
subShader.AddShaderChunk(tagsVisitor.GetShaderString(0), true);

14
com.unity.shadergraph/Editor/Data/MasterNodes/AlphaMode.cs


using System;
namespace UnityEditor.ShaderGraph {
public enum AlphaMode
namespace UnityEditor.ShaderGraph
{
public enum SurfaceType
Fade,
Transparent,
Transparent
}
public enum AlphaMode
{
Alpha,
Premultiply,
Additive,
Multiply
}

19
com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs


}
[SerializeField]
private SurfaceType m_SurfaceType;
[EnumControl("Surface")]
public SurfaceType surfaceType
{
get { return m_SurfaceType; }
set
{
if (m_SurfaceType == value)
return;
m_SurfaceType = value;
Dirty(ModificationScope.Graph);
}
}
[SerializeField]
[EnumControl("Blending")]
[EnumControl("Blend")]
public AlphaMode alphaMode
{
get { return m_AlphaMode; }

19
com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs


[SerializeField]
private SurfaceType m_SurfaceType;
[EnumControl("Surface")]
public SurfaceType surfaceType
{
get { return m_SurfaceType; }
set
{
if (m_SurfaceType == value)
return;
m_SurfaceType = value;
Dirty(ModificationScope.Graph);
}
}
[SerializeField]
[EnumControl("Blending")]
[EnumControl("Blend")]
public AlphaMode alphaMode
{
get { return m_AlphaMode; }

82
com.unity.shadergraph/Editor/Data/Util/ShaderGenerator.cs


return res;
}
public static SurfaceMaterialOptions GetMaterialOptions(AlphaMode alphaMode, bool twoSided)
public static SurfaceMaterialOptions GetMaterialOptions(SurfaceType surfaceType, AlphaMode alphaMode, bool twoSided)
switch (alphaMode)
switch (surfaceType)
case AlphaMode.Opaque:
case SurfaceType.Opaque:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.Zero;
materialOptions.cullMode = twoSided ? SurfaceMaterialOptions.CullMode.Off : SurfaceMaterialOptions.CullMode.Back;

materialOptions.renderType = SurfaceMaterialOptions.RenderType.Opaque;
break;
case AlphaMode.Fade:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.SrcAlpha;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.OneMinusSrcAlpha;
materialOptions.cullMode = twoSided ? SurfaceMaterialOptions.CullMode.Off : SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
case AlphaMode.Transparent:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.OneMinusSrcAlpha;
materialOptions.cullMode = twoSided ? SurfaceMaterialOptions.CullMode.Off : SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
case AlphaMode.Additive:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.cullMode = twoSided ? SurfaceMaterialOptions.CullMode.Off : SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
case AlphaMode.Multiply:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.DstColor;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.Zero;
materialOptions.cullMode = twoSided ? SurfaceMaterialOptions.CullMode.Off : SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
case SurfaceType.Transparent:
switch (alphaMode)
{
case AlphaMode.Alpha:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.SrcAlpha;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.OneMinusSrcAlpha;
materialOptions.cullMode = twoSided ? SurfaceMaterialOptions.CullMode.Off : SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
case AlphaMode.Premultiply:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.OneMinusSrcAlpha;
materialOptions.cullMode = twoSided ? SurfaceMaterialOptions.CullMode.Off : SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
case AlphaMode.Additive:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.cullMode = twoSided ? SurfaceMaterialOptions.CullMode.Off : SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
case AlphaMode.Multiply:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.DstColor;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.Zero;
materialOptions.cullMode = twoSided ? SurfaceMaterialOptions.CullMode.Off : SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
}
return materialOptions;
}

正在加载...
取消
保存