浏览代码

Clean way to plug default semantic behavior (using surfaceAttribute)

/scriptablerenderloop-materialgraph
Paul Demeulenaere 8 年前
当前提交
c79b25a0
共有 4 个文件被更改,包括 36 次插入24 次删除
  1. 35
      Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderloopMaterialGraph.cs
  2. 2
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin/BuiltinData.cs
  3. 4
      Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.cs
  4. 19
      Assets/ShaderGenerator/ShaderGeneratorAttributes.cs

35
Assets/ScriptableRenderLoop/HDRenderLoop/HDRenderloopMaterialGraph.cs


namespace UnityEngine.Experimental.ScriptableRenderLoop
{
public class DefaultAmbientOcclusion : AbstractMaterialNode
public class DefaultOneNode : AbstractMaterialNode
public const string kOutputSlotName = "DefaultAmbientOcclusion";
public const string kOutputSlotName = "DefaultOne";
public DefaultAmbientOcclusion()
public DefaultOneNode()
{
name = "Default Ambient Occlusion";
UpdateNodeAfterDeserialization();

priority = attribute.priority,
displayName = attribute.displayName,
materialID = attribute.filter,
semantic = attribute.semantic,
shaderOutputName = field.Name,
valueType = valueType
};

foreach (var slot in slots)
{
if (slot.displayName == "Normal")
switch (slot.semantic)
AddSlot(new MaterialSlotDefaultInput(slot.index, slot.displayName, slot.shaderOutputName, Graphing.SlotType.Input, slot.valueType, new WorldSpaceNormalNode(), WorldSpaceNormalNode.kOutputSlotId));
}
else if (slot.displayName == "Tangent")
{
AddSlot(new MaterialSlotDefaultInput(slot.index, slot.displayName, slot.shaderOutputName, Graphing.SlotType.Input, slot.valueType, new WorldSpaceTangentNode(), WorldSpaceTangentNode.kOutputSlotId));
}
else if (slot.displayName == "Ambient Occlusion")
{
AddSlot(new MaterialSlotDefaultInput(slot.index, slot.displayName, slot.shaderOutputName, Graphing.SlotType.Input, slot.valueType, new DefaultAmbientOcclusion(), DefaultAmbientOcclusion.kOutputSlotId));
}
else
{
AddSlot(new MaterialSlot(slot.index, slot.displayName, slot.shaderOutputName, Graphing.SlotType.Input, slot.valueType, Vector4.zero));
case SurfaceDataAttributes.Semantic.None:
AddSlot(new MaterialSlot(slot.index, slot.displayName, slot.shaderOutputName, Graphing.SlotType.Input, slot.valueType, Vector4.zero));
break;
case SurfaceDataAttributes.Semantic.Normal:
AddSlot(new MaterialSlotDefaultInput(slot.index, slot.displayName, slot.shaderOutputName, Graphing.SlotType.Input, slot.valueType, new WorldSpaceNormalNode(), WorldSpaceNormalNode.kOutputSlotId));
break;
case SurfaceDataAttributes.Semantic.Tangent:
AddSlot(new MaterialSlotDefaultInput(slot.index, slot.displayName, slot.shaderOutputName, Graphing.SlotType.Input, slot.valueType, new WorldSpaceTangentNode(), WorldSpaceTangentNode.kOutputSlotId));
break;
case SurfaceDataAttributes.Semantic.Opacity:
case SurfaceDataAttributes.Semantic.AmbientOcclusion:
AddSlot(new MaterialSlotDefaultInput(slot.index, slot.displayName, slot.shaderOutputName, Graphing.SlotType.Input, slot.valueType, new DefaultOneNode(), DefaultOneNode.kOutputSlotId));
break;
}
}
}

2
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Builtin/BuiltinData.cs


[GenerateHLSL(PackingRules.Exact, false, true, 100)]
public struct BuiltinData
{
[SurfaceDataAttributes("Opacity")]
[SurfaceDataAttributes("Opacity", 0, null, SurfaceDataAttributes.Semantic.Opacity)]
public float opacity;
// These are lighting data.

4
Assets/ScriptableRenderLoop/HDRenderLoop/Material/Lit/Lit.cs


[SurfaceDataAttributes("Specular Occlusion")]
public float specularOcclusion;
[SurfaceDataAttributes("Normal")]
[SurfaceDataAttributes("Normal", 0, null, SurfaceDataAttributes.Semantic.Normal)]
public Vector3 normalWS;
[SurfaceDataAttributes("Smoothness")]
public float perceptualSmoothness;

[SurfaceDataAttributes("Ambient Occlusion")]
[SurfaceDataAttributes("Ambient Occlusion", 0, null, SurfaceDataAttributes.Semantic.AmbientOcclusion)]
public float ambientOcclusion;
// MaterialId dependent attribute

19
Assets/ShaderGenerator/ShaderGeneratorAttributes.cs


[AttributeUsage(AttributeTargets.Field)]
public class SurfaceDataAttributes : System.Attribute
{
public enum Semantic
{
None,
Normal,
Tangent,
Opacity,
AmbientOcclusion,
}
public Semantic semantic { get; private set; }
public SurfaceDataAttributes(string displayName = "", int priority = 0, int[] filter = null)
public SurfaceDataAttributes(string _displayName = "", int _priority = 0, int[] _filter = null, Semantic _semantic = Semantic.None)
this.displayName = displayName;
this.priority = priority;
this.filter = filter;
displayName = _displayName;
priority = _priority;
filter = _filter;
semantic = _semantic;
}
}
}
正在加载...
取消
保存