浏览代码

Add transparency modes.

/main
Tim Cooper 7 年前
当前提交
0ceca805
共有 5 个文件被更改,包括 87 次插入53 次删除
  1. 45
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs
  2. 32
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/PBRMasterNode.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/UnlitMasterNode.cs
  4. 48
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/SurfaceMaterialOptions.cs
  5. 13
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightPBRForwardPass.template

45
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/LightWeightPBRSubShader.cs


using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;

var zWriteVisitor = new ShaderGenerator();
var materialOptions = new SurfaceMaterialOptions();
switch (masterNode.alphaMode)
{
case PBRMasterNode.AlphaMode.Overwrite:
case PBRMasterNode.AlphaMode.Clip:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.Zero;
materialOptions.cullMode = SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.On;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Geometry;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Opaque;
break;
case PBRMasterNode.AlphaMode.AlphaBlend:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.SrcAlpha;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.OneMinusSrcAlpha;
materialOptions.cullMode = 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 PBRMasterNode.AlphaMode.AdditiveBlend:
materialOptions.srcBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.dstBlend = SurfaceMaterialOptions.BlendMode.One;
materialOptions.cullMode = SurfaceMaterialOptions.CullMode.Back;
materialOptions.zTest = SurfaceMaterialOptions.ZTest.LEqual;
materialOptions.zWrite = SurfaceMaterialOptions.ZWrite.Off;
materialOptions.renderQueue = SurfaceMaterialOptions.RenderQueue.Transparent;
materialOptions.renderType = SurfaceMaterialOptions.RenderType.Transparent;
break;
}
materialOptions.GetTags(tagsVisitor);
materialOptions.GetBlend(blendingVisitor);
materialOptions.GetCull(cullingVisitor);

if (masterNode.model == PBRMasterNode.Model.Metallic)
defines.AddShaderChunk("#define _METALLIC_SETUP 1", true);
switch (masterNode.alphaMode)
{
case PBRMasterNode.AlphaMode.AlphaBlend:
case PBRMasterNode.AlphaMode.AdditiveBlend:
defines.AddShaderChunk("#define _AlphaOut 1", true);
break;
case PBRMasterNode.AlphaMode.Clip:
defines.AddShaderChunk("#define _AlphaClip 1", true);
break;
}
var templateLocation = ShaderGenerator.GetTemplatePath(template);

subShader.AddShaderChunk("SubShader", true);
subShader.AddShaderChunk("{", true);
subShader.Indent();
subShader.AddShaderChunk("Tags{ \"RenderType\" = \"Opaque\" \"RenderPipeline\" = \"LightweightPipeline\"}", true);
subShader.AddShaderChunk("Tags{ \"RenderPipeline\" = \"LightweightPipeline\"}", true);
subShader.AddShaderChunk(
GetShaderPassFromTemplate(

32
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/PBRMasterNode.cs


Metallic
}
public enum AlphaMode
{
Overwrite,
AlphaBlend,
AdditiveBlend,
Clip
}
private Model m_Model;
private Model m_Model = Model.Metallic;
[EnumControl("")]
public Model model

}
}
[SerializeField]
private AlphaMode m_AlphaMode;
[EnumControl("")]
public AlphaMode alphaMode
{
get { return m_AlphaMode; }
set
{
if (m_AlphaMode == value)
return;
m_AlphaMode = value;
if (onModified != null)
{
onModified(this, ModificationScope.Graph);
}
}
}
public PBRMasterNode()
{
UpdateNodeAfterDeserialization();

AddSlot(new Vector3MaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, Vector3.zero, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, 1f, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 0, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1f, ShaderStage.Fragment));
// clear out slot names that do not match the slots
// we support

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/LightweightPipeline/UnlitMasterNode.cs


{
name = "Unlit Master";
AddSlot(new Vector3MaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, new Vector3(0.5f, 0.5f, 0.5f), ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 0, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1, ShaderStage.Fragment));
// clear out slot names that do not match the slots
// we support

48
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/SurfaceModel/SurfaceMaterialOptions.cs


private RenderType m_RenderType = RenderType.Opaque;
[SerializeField]
private bool m_ShadowPass;
[SerializeField]
private bool m_FullForwardShadows;
[SerializeField]
private bool m_NoAmbient;
[SerializeField]
private bool m_NoVertexLights;
[SerializeField]
private bool m_NoLightmaps;
[SerializeField]
private bool m_NoDirLightmap;
[SerializeField]
private bool m_NoForwardAdd;
[SerializeField]
private bool m_ApproxView;
[SerializeField]
private bool m_HalfAsView;
[SerializeField]
[SerializeField]
private bool m_Expanded;
public void Init()
{

zWrite = ZWrite.On;
renderQueue = RenderQueue.Geometry;
renderType = RenderType.Opaque;
shadowPass = false;
fullForwardShadows = false;
noAmbient = false;
noVertexLights = false;
noLightmaps = false;
noDirLightmap = false;
noForwardAdd = false;
approxView = false;
halfAsView = false;
lod = 200;
}

public ZWrite zWrite { get { return m_ZWrite; } set { m_ZWrite = value; } }
public RenderQueue renderQueue { get { return m_RenderQueue; } set { m_RenderQueue = value; } }
public RenderType renderType { get { return m_RenderType; } set { m_RenderType = value; } }
public bool shadowPass { get { return m_ShadowPass; } set { m_ShadowPass = value; } }
public bool fullForwardShadows { get { return m_FullForwardShadows; } set { m_FullForwardShadows = value; } }
public bool noAmbient { get { return m_NoAmbient; } set { m_NoAmbient = value; } }
public bool noVertexLights { get { return m_NoVertexLights; } set { m_NoVertexLights = value; } }
public bool noLightmaps { get { return m_NoLightmaps; } set { m_NoLightmaps = value; } }
public bool noDirLightmap { get { return m_NoDirLightmap; } set { m_NoDirLightmap = value; } }
public bool noForwardAdd { get { return m_NoForwardAdd; } set { m_NoForwardAdd = value; } }
public bool approxView { get { return m_ApproxView; } set { m_ApproxView = value; } }
public bool halfAsView { get { return m_HalfAsView; } set { m_HalfAsView = value; } }
public int lod { get { return m_LOD; } set { m_LOD = value; } }
}
}

13
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Templates/lightweightPBRForwardPass.template


Emission = Emission * Emission;
#endif
return LightweightFragmentPBR(
half4 result = LightweightFragmentPBR(
IN.lwCustom,
WorldSpacePosition,
WorldSpaceNormal,

Occlusion,
Emission,
Alpha);
#if _AlphaOut
result.a = Alpha;
#else
result.a = 1;
#endif
#if _AlphaClip
clip(Alpha - 0.01);
#endif
return result;
}
ENDCG
正在加载...
取消
保存