浏览代码

Rebuild previous branch (see comments)

Also:
- Add cull control to shadow and depth
- Add clip define (need to add clip to shadow/depth frag)
- Add HD pipeline tag to unlit subshader
/main
Peter Bay Bastian 7 年前
当前提交
e7f9893d
共有 45 个文件被更改,包括 561 次插入238 次删除
  1. 1
      ShaderGraph/HDPipeline/HDUnlitSubShader.cs
  2. 8
      ShaderGraph/Testing/Editor/TestSlot.cs
  3. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/BitangentMaterialSlot.cs
  4. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/BooleanMaterialSlot.cs
  5. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/ColorMaterialSlot.cs
  6. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/ColorRGBMaterialSlot.cs
  7. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/CubemapInputMaterialSlot.cs
  8. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/CubemapMaterialSlot.cs
  9. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/DynamicMatrixMaterialSlot.cs
  10. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/DynamicValueMaterialSlot.cs
  11. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs
  12. 12
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/GradientInputMaterialSlot.cs
  13. 6
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/GradientMaterialSlot.cs
  14. 54
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/MaterialSlot.cs
  15. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Matrix2MaterialSlot.cs
  16. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Matrix3MaterialSlot.cs
  17. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Matrix4MaterialSlot.cs
  18. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/NormalMaterialSlot.cs
  19. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/PositionMaterialSlot.cs
  20. 3
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/PreviewMode.cs
  21. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/SamplerStateMaterialSlot.cs
  22. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/ScreenPositionMaterialSlot.cs
  23. 3
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/ShaderGraphRequirements.cs
  24. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/SpaceMaterialSlot.cs
  25. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/TangentMaterialSlot.cs
  26. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DInputMaterialSlot.cs
  27. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DMaterialSlot.cs
  28. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/UVMaterialSlot.cs
  29. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Vector1MaterialSlot.cs
  30. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Vector2MaterialSlot.cs
  31. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Vector3MaterialSlot.cs
  32. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Vector4MaterialSlot.cs
  33. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/VertexColorMaterialSlot.cs
  34. 4
      ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/ViewDirectionMaterialSlot.cs
  35. 98
      ShaderGraph/com.unity.shadergraph/Editor/Data/Implementation/NodeUtils.cs
  36. 35
      ShaderGraph/com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs
  37. 23
      ShaderGraph/com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs
  38. 34
      ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/ShaderStage.cs
  39. 85
      ShaderGraph/com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs
  40. 13
      ShaderGraph/com.unity.shadergraph/Editor/Data/Util/PropertyCollector.cs
  41. 195
      ShaderGraph/com.unity.shadergraph/Editor/Data/Util/ShaderGenerator.cs
  42. 33
      ShaderGraph/com.unity.shadergraph/Editor/Data/Util/ShaderStringBuilder.cs
  43. 2
      ShaderGraph/com.unity.shadergraph/Editor/DefaultShaderIncludes.cs
  44. 69
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/PreviewManager.cs
  45. 17
      ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs

1
ShaderGraph/HDPipeline/HDUnlitSubShader.cs


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

8
ShaderGraph/Testing/Editor/TestSlot.cs


{
public TestSlot() {}
public TestSlot(int slotId, string displayName, SlotType slotType, ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, displayName, slotType, shaderStage, hidden) {}
public TestSlot(int slotId, string displayName, SlotType slotType, ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, displayName, slotType, stageCapability, hidden) {}
public TestSlot(int slotId, string displayName, SlotType slotType, int priority, ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, displayName, slotType, priority, shaderStage, hidden) {}
public TestSlot(int slotId, string displayName, SlotType slotType, int priority, ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, displayName, slotType, priority, stageCapability, hidden) {}
public override SlotValueType valueType
{

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/BitangentMaterialSlot.cs


{}
public BitangentMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, space, shaderStage, hidden)
ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, shaderOutputName, space, stageCapability, hidden)
{}
public override VisualElement InstantiateControl()

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/BooleanMaterialSlot.cs


string shaderOutputName,
SlotType slotType,
bool value,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
m_DefaultValue = value;
m_Value = value;

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/ColorMaterialSlot.cs


string shaderOutputName,
SlotType slotType,
Vector4 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, value, shaderStage, hidden: hidden)
: base(slotId, displayName, shaderOutputName, slotType, value, stageCapability, hidden: hidden)
{
}

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/ColorRGBMaterialSlot.cs


string shaderOutputName,
SlotType slotType,
Color value,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, (Vector4)value, shaderStage, hidden: hidden)
: base(slotId, displayName, shaderOutputName, slotType, (Vector4)value, stageCapability, hidden: hidden)
{
}

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/CubemapInputMaterialSlot.cs


int slotId,
string displayName,
string shaderOutputName,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, SlotType.Input, stageCapability, hidden)
{}
public override VisualElement InstantiateControl()

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/CubemapMaterialSlot.cs


string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{}
public override SlotValueType valueType { get { return SlotValueType.Cubemap; } }

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/DynamicMatrixMaterialSlot.cs


string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
m_Value = value;
}

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/DynamicValueMaterialSlot.cs


string shaderOutputName,
SlotType slotType,
Matrix4x4 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
m_Value = value;
}

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs


string shaderOutputName,
SlotType slotType,
Vector4 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
m_Value = value;
}

12
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/GradientInputMaterialSlot.cs


int slotId,
string displayName,
string shaderOutputName,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, SlotType.Input, stageCapability, hidden)
{
}

generatePropertyBlock = false
});
}
for(int i = 0; i < 8; i++)
{
properties.AddShaderProperty(new Vector4ShaderProperty()

generatePropertyBlock = false
});
}
}
}
var prop = new GradientShaderProperty();

vector4Value = i < value.colorKeys.Length ? GradientUtils.ColorKeyToVector(value.colorKeys[i]) : Vector4.zero
});
}
for(int i = 0; i < 8; i++)
{
properties.Add(new PreviewProperty(PropertyType.Vector2)

value = slot.value;
}
}
}
}

6
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/GradientMaterialSlot.cs


string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
}

{
}
}
}
}

54
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/MaterialSlot.cs


string m_ShaderOutputName;
[SerializeField]
ShaderStage m_ShaderStage;
ShaderStageCapability m_StageCapability;
protected MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
protected MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
{
m_Id = slotId;
m_DisplayName = displayName;

this.shaderStage = shaderStage;
this.stageCapability = stageCapability;
protected MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, int priority, ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
protected MaterialSlot(int slotId, string displayName, string shaderOutputName, SlotType slotType, int priority, ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
{
m_Id = slotId;
m_DisplayName = displayName;

m_ShaderOutputName = shaderOutputName;
this.shaderStage = shaderStage;
this.stageCapability = stageCapability;
}
public virtual VisualElement InstantiateControl()

return m_DisplayName;
}
public static MaterialSlot CreateMaterialSlot(SlotValueType type, int slotId, string displayName, string shaderOutputName, SlotType slotType, Vector4 defaultValue, ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
public static MaterialSlot CreateMaterialSlot(SlotValueType type, int slotId, string displayName, string shaderOutputName, SlotType slotType, Vector4 defaultValue, ShaderStageCapability shaderStageCapability = ShaderStageCapability.All, bool hidden = false)
return new SamplerStateMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
return new SamplerStateMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
return new DynamicMatrixMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
return new DynamicMatrixMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
return new Matrix4MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
return new Matrix4MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
return new Matrix3MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
return new Matrix3MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
return new Matrix2MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
return new Matrix2MaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
? new Texture2DInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStage, hidden)
: new Texture2DMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
? new Texture2DInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
: new Texture2DMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
? new CubemapInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStage, hidden)
: new CubemapMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
? new CubemapInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
: new CubemapMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
? new GradientInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStage, hidden)
: new GradientMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden);
? new GradientInputMaterialSlot(slotId, displayName, shaderOutputName, shaderStageCapability, hidden)
: new GradientMaterialSlot(slotId, displayName, shaderOutputName, slotType, shaderStageCapability, hidden);
return new DynamicVectorMaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden);
return new DynamicVectorMaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden);
return new Vector4MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden: hidden);
return new Vector4MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden: hidden);
return new Vector3MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden: hidden);
return new Vector3MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden: hidden);
return new Vector2MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStage, hidden: hidden);
return new Vector2MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue, shaderStageCapability, hidden: hidden);
return new Vector1MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue.x, shaderStage, hidden: hidden);
return new Vector1MaterialSlot(slotId, displayName, shaderOutputName, slotType, defaultValue.x, shaderStageCapability, hidden: hidden);
return new DynamicValueMaterialSlot(slotId, displayName, shaderOutputName, slotType, new Matrix4x4(defaultValue, Vector4.zero, Vector4.zero, Vector4.zero), shaderStage, hidden);
return new DynamicValueMaterialSlot(slotId, displayName, shaderOutputName, slotType, new Matrix4x4(defaultValue, Vector4.zero, Vector4.zero, Vector4.zero), shaderStageCapability, hidden);
return new BooleanMaterialSlot(slotId, displayName, shaderOutputName, slotType, false, shaderStage, hidden);
return new BooleanMaterialSlot(slotId, displayName, shaderOutputName, slotType, false, shaderStageCapability, hidden);
}
throw new ArgumentOutOfRangeException("type", type, null);

private set { m_ShaderOutputName = value; }
}
public ShaderStage shaderStage
public ShaderStageCapability stageCapability
get { return m_ShaderStage; }
set { m_ShaderStage = value; }
get { return m_StageCapability; }
set { m_StageCapability = value; }
}
public bool hasError

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Matrix2MaterialSlot.cs


string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
}

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Matrix3MaterialSlot.cs


string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
}

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Matrix4MaterialSlot.cs


string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
}

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/NormalMaterialSlot.cs


{}
public NormalMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, space, shaderStage, hidden)
ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, shaderOutputName, space, stageCapability, hidden)
{}
public override VisualElement InstantiateControl()

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/PositionMaterialSlot.cs


{}
public PositionMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, space, shaderStage, hidden)
ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, shaderOutputName, space, stageCapability, hidden)
{}
public override VisualElement InstantiateControl()

3
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/PreviewMode.cs


public enum PreviewMode
{
Preview2D,
Preview3D
Preview3D,
Wireframe
}
}

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/SamplerStateMaterialSlot.cs


string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
}

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/ScreenPositionMaterialSlot.cs


{}
public ScreenPositionMaterialSlot(int slotId, string displayName, string shaderOutputName, ScreenSpaceType screenSpaceType,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, shaderStage, hidden: hidden)
ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, stageCapability, hidden: hidden)
{
this.screenSpaceType = screenSpaceType;
}

3
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/ShaderGraphRequirements.cs


return newReqs;
}
public static ShaderGraphRequirements FromNodes(List<INode> nodes)
public static ShaderGraphRequirements FromNodes<T>(List<T> nodes)
where T : class, INode
{
NeededCoordinateSpace requiresNormal = nodes.OfType<IMayRequireNormal>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresNormal());
NeededCoordinateSpace requiresBitangent = nodes.OfType<IMayRequireBitangent>().Aggregate(NeededCoordinateSpace.None, (mask, node) => mask | node.RequiresBitangent());

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/SpaceMaterialSlot.cs


{}
protected SpaceMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, shaderStage, hidden: hidden)
ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, stageCapability, hidden: hidden)
{
this.space = space;
}

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/TangentMaterialSlot.cs


{}
public TangentMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, space, shaderStage, hidden)
ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, shaderOutputName, space, stageCapability, hidden)
{}
public override VisualElement InstantiateControl()

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DInputMaterialSlot.cs


int slotId,
string displayName,
string shaderOutputName,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, SlotType.Input, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, SlotType.Input, stageCapability, hidden)
{}
public override VisualElement InstantiateControl()

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Texture2DMaterialSlot.cs


string displayName,
string shaderOutputName,
SlotType slotType,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{}
public override SlotValueType valueType { get { return SlotValueType.Texture2D; } }

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/UVMaterialSlot.cs


{}
public UVMaterialSlot(int slotId, string displayName, string shaderOutputName, UVChannel channel,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector2.zero, shaderStage, hidden: hidden)
ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector2.zero, stageCapability, hidden: hidden)
{
this.channel = channel;
}

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Vector1MaterialSlot.cs


string shaderOutputName,
SlotType slotType,
float value,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
m_DefaultValue = value;
m_Value = value;

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Vector2MaterialSlot.cs


string shaderOutputName,
SlotType slotType,
Vector2 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
m_Value = value;
m_Labels = new[] { label1, label2 };

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Vector3MaterialSlot.cs


string shaderOutputName,
SlotType slotType,
Vector3 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
m_Value = value;
m_Labels = new[] { label1, label2, label3 };

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/Vector4MaterialSlot.cs


string shaderOutputName,
SlotType slotType,
Vector4 value,
ShaderStage shaderStage = ShaderStage.Dynamic,
ShaderStageCapability stageCapability = ShaderStageCapability.All,
: base(slotId, displayName, shaderOutputName, slotType, shaderStage, hidden)
: base(slotId, displayName, shaderOutputName, slotType, stageCapability, hidden)
{
m_Value = value;
m_Labels = new[] { label1, label2, label3, label4 };

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/VertexColorMaterialSlot.cs


public class VertexColorMaterialSlot : Vector4MaterialSlot, IMayRequireScreenPosition
{
public VertexColorMaterialSlot(int slotId, string displayName, string shaderOutputName,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, shaderStage, hidden: hidden)
ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, shaderOutputName, SlotType.Input, Vector3.zero, stageCapability, hidden: hidden)
{}
public override VisualElement InstantiateControl()

4
ShaderGraph/com.unity.shadergraph/Editor/Data/Graphs/ViewDirectionMaterialSlot.cs


{}
public ViewDirectionMaterialSlot(int slotId, string displayName, string shaderOutputName, CoordinateSpace space,
ShaderStage shaderStage = ShaderStage.Dynamic, bool hidden = false)
: base(slotId, displayName, shaderOutputName, space, shaderStage, hidden)
ShaderStageCapability stageCapability = ShaderStageCapability.All, bool hidden = false)
: base(slotId, displayName, shaderOutputName, space, stageCapability, hidden)
{}
public override VisualElement InstantiateControl()
{

98
ShaderGraph/com.unity.shadergraph/Editor/Data/Implementation/NodeUtils.cs


Exclude
}
public static void DepthFirstCollectNodesFromNode(List<INode> nodeList, INode node, IncludeSelf includeSelf = IncludeSelf.Include, List<int> slotIds = null)
public static void DepthFirstCollectNodesFromNode<T>(List<T> nodeList, T node, IncludeSelf includeSelf = IncludeSelf.Include, List<int> slotIds = null)
where T : class, INode
{
// no where to start
if (node == null)

{
foreach (var edge in node.owner.GetEdges(node.GetSlotReference(slot)))
{
var outputNode = node.owner.GetNodeFromGuid(edge.outputSlot.nodeGuid);
var outputNode = node.owner.GetNodeFromGuid(edge.outputSlot.nodeGuid) as T;
if (outputNode != null)
DepthFirstCollectNodesFromNode(nodeList, outputNode);
}
}

nodeList.Add(node);
}
static Stack<INode> s_NodeStack = new Stack<INode>();
static Stack<MaterialSlot> s_SlotStack = new Stack<MaterialSlot>();
public static ShaderStage FindEffectiveShaderStage(INode initialNode, bool goingBackwards)
public static ShaderStage GetEffectiveShaderStage(MaterialSlot initialSlot, bool goingBackwards)
var shaderStage = ShaderStage.Dynamic;
s_NodeStack.Clear();
s_NodeStack.Push(initialNode);
while (s_NodeStack.Any() && shaderStage == ShaderStage.Dynamic)
var graph = initialSlot.owner.owner;
s_SlotStack.Clear();
s_SlotStack.Push(initialSlot);
while (s_SlotStack.Any())
var node = s_NodeStack.Pop();
foreach (var slot in goingBackwards ? node.GetInputSlots<MaterialSlot>() : node.GetOutputSlots<MaterialSlot>())
var slot = s_SlotStack.Pop();
ShaderStage stage;
if (slot.stageCapability.TryGetShaderStage(out stage))
return stage;
if (goingBackwards && slot.isInputSlot)
{
foreach (var edge in graph.GetEdges(slot.slotReference))
if (shaderStage != ShaderStage.Dynamic)
break;
if (slot.shaderStage == ShaderStage.Dynamic)
var node = graph.GetNodeFromGuid(edge.outputSlot.nodeGuid);
s_SlotStack.Push(node.FindOutputSlot<MaterialSlot>(edge.outputSlot.slotId));
}
}
else if (!goingBackwards && slot.isOutputSlot)
foreach (var edge in node.owner.GetEdges(slot.slotReference))
foreach (var edge in graph.GetEdges(slot.slotReference))
var connectedNode = node.owner.GetNodeFromGuid(goingBackwards ? edge.outputSlot.nodeGuid : edge.inputSlot.nodeGuid);
var connectedSlot = goingBackwards ? connectedNode.FindOutputSlot<MaterialSlot>(edge.outputSlot.slotId) : connectedNode.FindInputSlot<MaterialSlot>(edge.inputSlot.slotId);
if (connectedSlot.shaderStage == ShaderStage.Dynamic)
s_NodeStack.Push(connectedNode);
var node = graph.GetNodeFromGuid(edge.inputSlot.nodeGuid);
s_SlotStack.Push(node.FindInputSlot<MaterialSlot>(edge.inputSlot.slotId));
}
}
shaderStage = connectedSlot.shaderStage;
break;
var ownerSlots = Enumerable.Empty<MaterialSlot>();
if (goingBackwards && slot.isOutputSlot)
ownerSlots = slot.owner.GetInputSlots<MaterialSlot>();
else if (!goingBackwards && slot.isInputSlot)
ownerSlots = slot.owner.GetOutputSlots<MaterialSlot>();
foreach (var ownerSlot in ownerSlots)
s_SlotStack.Push(ownerSlot);
// We default to fragment shader stage if all connected nodes were compatible with both.
return ShaderStage.Fragment;
}
public static ShaderStageCapability GetEffectiveShaderStageCapability(MaterialSlot initialSlot, bool goingBackwards)
{
var graph = initialSlot.owner.owner;
s_SlotStack.Clear();
s_SlotStack.Push(initialSlot);
while (s_SlotStack.Any())
{
var slot = s_SlotStack.Pop();
ShaderStage stage;
if (slot.stageCapability.TryGetShaderStage(out stage))
return slot.stageCapability;
if (goingBackwards && slot.isInputSlot)
{
foreach (var edge in graph.GetEdges(slot.slotReference))
{
var node = graph.GetNodeFromGuid(edge.outputSlot.nodeGuid);
s_SlotStack.Push(node.FindOutputSlot<MaterialSlot>(edge.outputSlot.slotId));
}
}
else if (!goingBackwards && slot.isOutputSlot)
{
foreach (var edge in graph.GetEdges(slot.slotReference))
{
var node = graph.GetNodeFromGuid(edge.inputSlot.nodeGuid);
s_SlotStack.Push(node.FindInputSlot<MaterialSlot>(edge.inputSlot.slotId));
}
shaderStage = slot.shaderStage;
{
var ownerSlots = Enumerable.Empty<MaterialSlot>();
if (goingBackwards && slot.isOutputSlot)
ownerSlots = slot.owner.GetInputSlots<MaterialSlot>();
else if (!goingBackwards && slot.isInputSlot)
ownerSlots = slot.owner.GetOutputSlots<MaterialSlot>();
foreach (var ownerSlot in ownerSlots)
s_SlotStack.Push(ownerSlot);
return shaderStage;
return ShaderStageCapability.All;
}
public static string GetSlotDimension(ConcreteSlotValueType slotValue)

35
ShaderGraph/com.unity.shadergraph/Editor/Data/MasterNodes/PBRMasterNode.cs


{
[Serializable]
[Title("Master", "PBR")]
public class PBRMasterNode : MasterNode<IPBRSubShader>, IMayRequireNormal
public class PBRMasterNode : MasterNode<IPBRSubShader>, IMayRequirePosition
{
public const string AlbedoSlotName = "Albedo";
public const string NormalSlotName = "Normal";

public const string OcclusionSlotName = "Occlusion";
public const string AlphaSlotName = "Alpha";
public const string AlphaClipThresholdSlotName = "AlphaClipThreshold";
public const string VertexOffsetName = "VertexPosition";
public const string PositionName = "Position";
public const int AlbedoSlotId = 0;
public const int NormalSlotId = 1;

public const int OcclusionSlotId = 6;
public const int AlphaSlotId = 7;
public const int AlphaThresholdSlotId = 8;
public const int PositionSlotId = 9;
public enum Model
{

{
base.UpdateNodeAfterDeserialization();
name = "PBR Master";
AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, Color.grey, ShaderStage.Fragment));
AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, CoordinateSpace.Tangent, ShaderStage.Fragment));
AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ShaderStage.Fragment));
AddSlot(new PositionMaterialSlot(PositionSlotId, PositionName, PositionName, CoordinateSpace.Object, ShaderStageCapability.Vertex));
AddSlot(new ColorRGBMaterialSlot(AlbedoSlotId, AlbedoSlotName, AlbedoSlotName, SlotType.Input, Color.grey, ShaderStageCapability.Fragment));
AddSlot(new NormalMaterialSlot(NormalSlotId, NormalSlotName, NormalSlotName, CoordinateSpace.Tangent, ShaderStageCapability.Fragment));
AddSlot(new ColorRGBMaterialSlot(EmissionSlotId, EmissionSlotName, EmissionSlotName, SlotType.Input, Color.black, ShaderStageCapability.Fragment));
AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(MetallicSlotId, MetallicSlotName, MetallicSlotName, SlotType.Input, 0, ShaderStageCapability.Fragment));
AddSlot(new ColorRGBMaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, Color.grey, 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, 1f, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0f, ShaderStage.Fragment));
AddSlot(new ColorRGBMaterialSlot(SpecularSlotId, SpecularSlotName, SpecularSlotName, SlotType.Input, Color.grey, ShaderStageCapability.Fragment));
AddSlot(new Vector1MaterialSlot(SmoothnessSlotId, SmoothnessSlotName, SmoothnessSlotName, SlotType.Input, 0.5f, ShaderStageCapability.Fragment));
AddSlot(new Vector1MaterialSlot(OcclusionSlotId, OcclusionSlotName, OcclusionSlotName, SlotType.Input, 1f, ShaderStageCapability.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1f, ShaderStageCapability.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0f, ShaderStageCapability.Fragment));
// clear out slot names that do not match the slots
// we support

PositionSlotId,
AlbedoSlotId,
NormalSlotId,
EmissionSlotId,

protected override VisualElement CreateCommonSettingsElement()
{
return new PBRSettingsView(this);
}
public NeededCoordinateSpace RequiresPosition()
{
s_TempSlots.Clear();
GetInputSlots(s_TempSlots);
var binding = NeededCoordinateSpace.None;
foreach (var slot in s_TempSlots)
binding |= slot.RequiresPosition();
return binding;
}
}
}

23
ShaderGraph/com.unity.shadergraph/Editor/Data/MasterNodes/UnlitMasterNode.cs


{
[Serializable]
[Title("Master", "Unlit")]
public class UnlitMasterNode : MasterNode<IUnlitSubShader>
public class UnlitMasterNode : MasterNode<IUnlitSubShader>, IMayRequirePosition
public const string VertexOffsetName = "VertexPosition";
public const string PositionName = "Position";
public const int PositionSlotId = 9;
[SerializeField]
SurfaceType m_SurfaceType;

{
base.UpdateNodeAfterDeserialization();
name = "Unlit Master";
AddSlot(new ColorRGBMaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Color.grey, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1, ShaderStage.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0f, ShaderStage.Fragment));
AddSlot(new PositionMaterialSlot(PositionSlotId, PositionName, PositionName, CoordinateSpace.Object, ShaderStageCapability.Vertex));
AddSlot(new ColorRGBMaterialSlot(ColorSlotId, ColorSlotName, ColorSlotName, SlotType.Input, Color.grey, ShaderStageCapability.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaSlotId, AlphaSlotName, AlphaSlotName, SlotType.Input, 1, ShaderStageCapability.Fragment));
AddSlot(new Vector1MaterialSlot(AlphaThresholdSlotId, AlphaClipThresholdSlotName, AlphaClipThresholdSlotName, SlotType.Input, 0f, ShaderStageCapability.Fragment));
// clear out slot names that do not match the slots
// we support

PositionSlotId,
ColorSlotId,
AlphaSlotId,
AlphaThresholdSlotId

protected override VisualElement CreateCommonSettingsElement()
{
return new UnlitSettingsView(this);
}
public NeededCoordinateSpace RequiresPosition()
{
s_TempSlots.Clear();
GetInputSlots(s_TempSlots);
var binding = NeededCoordinateSpace.None;
foreach (var slot in s_TempSlots)
binding |= slot.RequiresPosition();
return binding;
}
}
}

34
ShaderGraph/com.unity.shadergraph/Editor/Data/Nodes/ShaderStage.cs


namespace UnityEditor.ShaderGraph
{
[Flags]
public enum ShaderStageCapability
{
Vertex = 1 << 0,
Fragment = 1 << 1,
All = Vertex | Fragment
}
Dynamic,
}
public static class ShaderStageExtensions
{
/// <summary>
/// Tries to convert a ShaderStageCapability into a ShaderStage. The conversion is only successful if the given ShaderStageCapability <paramref name="capability"/> refers to exactly 1 shader stage.
/// </summary>
/// <param name="capability">The ShaderStageCapability to convert.</param>
/// <param name="stage">If <paramref name="capability"/> refers to exactly 1 shader stage, this parameter will contain the equivalent ShaderStage of that. Otherwise the value is undefined.</param>
/// <returns>True is <paramref name="capability"/> holds exactly 1 shader stage.</returns>
public static bool TryGetShaderStage(this ShaderStageCapability capability, out ShaderStage stage)
{
switch (capability)
{
case ShaderStageCapability.Vertex:
stage = ShaderStage.Vertex;
return true;
case ShaderStageCapability.Fragment:
stage = ShaderStage.Fragment;
return true;
default:
stage = ShaderStage.Fragment;
return false;
}
}
}
}

85
ShaderGraph/com.unity.shadergraph/Editor/Data/Util/GraphUtil.cs


public static void GenerateApplicationVertexInputs(ShaderGraphRequirements graphRequiements, ShaderGenerator vertexInputs)
{
vertexInputs.AddShaderChunk("struct GraphVertexInput", false);
vertexInputs.AddShaderChunk("{", false);
vertexInputs.Indent();
vertexInputs.AddShaderChunk("float4 vertex : POSITION;", false);
vertexInputs.AddShaderChunk("float3 normal : NORMAL;", false);
vertexInputs.AddShaderChunk("float4 tangent : TANGENT;", false);
var builder = new ShaderStringBuilder();
GenerateApplicationVertexInputs(graphRequiements, builder);
vertexInputs.AddShaderChunk(builder.ToString(), false);
}
if (graphRequiements.requiresVertexColor)
public static void GenerateApplicationVertexInputs(ShaderGraphRequirements graphRequiements, ShaderStringBuilder vertexInputs)
{
vertexInputs.AppendLine("struct GraphVertexInput");
using (vertexInputs.BlockSemicolonScope())
vertexInputs.AddShaderChunk("float4 color : COLOR;", false);
vertexInputs.AppendLine("float4 vertex : POSITION;");
vertexInputs.AppendLine("float3 normal : NORMAL;");
vertexInputs.AppendLine("float4 tangent : TANGENT;");
if (graphRequiements.requiresVertexColor)
{
vertexInputs.AppendLine("float4 color : COLOR;");
}
foreach (var channel in graphRequiements.requiresMeshUVs.Distinct())
vertexInputs.AppendLine("float4 texcoord{0} : TEXCOORD{0};", (int)channel);
vertexInputs.AppendLine("UNITY_VERTEX_INPUT_INSTANCE_ID");
foreach (var channel in graphRequiements.requiresMeshUVs.Distinct())
vertexInputs.AddShaderChunk(string.Format("float4 texcoord{0} : TEXCOORD{0};", (int)channel), false);
vertexInputs.AddShaderChunk("UNITY_VERTEX_INPUT_INSTANCE_ID", true);
vertexInputs.Deindent();
vertexInputs.AddShaderChunk("};", false);
}
static void Visit(List<INode> outputList, Dictionary<Guid, INode> unmarkedNodes, INode node)

surfaceDescriptionFunction.AddShaderChunk("}", false);
}
const string k_VertexDescriptionStructName = "VertexDescription";
public static void GenerateVertexDescriptionStruct(ShaderStringBuilder builder, List<MaterialSlot> slots)
{
builder.AppendLine("struct {0}", k_VertexDescriptionStructName);
using (builder.BlockSemicolonScope())
{
foreach (var slot in slots)
builder.AppendLine("{0} {1};", NodeUtils.ConvertConcreteSlotValueTypeToString(AbstractMaterialNode.OutputPrecision.@float, slot.concreteValueType), NodeUtils.GetHLSLSafeName(slot.shaderOutputName));
}
}
public static void GenerateVertexDescriptionFunction(
ShaderStringBuilder builder,
FunctionRegistry functionRegistry,
PropertyCollector shaderProperties,
GenerationMode generationMode,
List<AbstractMaterialNode> nodes,
List<MaterialSlot> slots)
{
builder.AppendLine("{0} PopulateVertexData(VertexDescriptionInputs IN)", k_VertexDescriptionStructName);
using (builder.BlockScope())
{
builder.AppendLine("{0} description = ({0})0;", k_VertexDescriptionStructName);
foreach (var node in nodes)
{
var generatesFunction = node as IGeneratesFunction;
if (generatesFunction != null)
{
functionRegistry.builder.currentNode = node;
generatesFunction.GenerateNodeFunction(functionRegistry, generationMode);
}
var generatesBodyCode = node as IGeneratesBodyCode;
if (generatesBodyCode != null)
{
var generator = new ShaderGenerator();
generatesBodyCode.GenerateNodeCode(generator, generationMode);
builder.AppendLines(generator.GetShaderString(0));
}
node.CollectShaderProperties(shaderProperties, generationMode);
}
foreach (var slot in slots)
{
var isSlotConnected = slot.owner.owner.GetEdges(slot.slotReference).Any();
var slotName = NodeUtils.GetHLSLSafeName(slot.shaderOutputName);
var slotValue = isSlotConnected ? ((AbstractMaterialNode)slot.owner).GetSlotValue(slot.id, generationMode) : slot.GetDefaultValue(generationMode);
builder.AppendLine("description.{0} = {1};", slotName, slotValue);
}
builder.AppendLine("return description;");
}
}
public static GenerationResults GetUberPreviewShader(this AbstractMaterialGraph graph)
public static GenerationResults GetUberColorShader(this AbstractMaterialGraph graph)
{
return graph.GetShader(null, GenerationMode.Preview, "hidden/preview");
}

13
ShaderGraph/com.unity.shadergraph/Editor/Data/Util/PropertyCollector.cs


public string GetPropertiesDeclaration(int baseIndentLevel)
{
var sb = new StringBuilder();
var builder = new ShaderStringBuilder(baseIndentLevel);
GetPropertiesDeclaration(builder);
return builder.ToString();
}
public void GetPropertiesDeclaration(ShaderStringBuilder builder)
{
for (var i = 0; i < baseIndentLevel; i++)
sb.Append("\t");
sb.AppendLine(prop.GetPropertyDeclarationString());
builder.AppendLine(prop.GetPropertyDeclarationString());
return sb.ToString();
}
public List<TextureInfo> GetConfiguredTexutres()

195
ShaderGraph/com.unity.shadergraph/Editor/Data/Util/ShaderGenerator.cs


NeededCoordinateSpace neededSpaces,
InterpolatorType interpolatorType,
ShaderGenerator surfaceInputs,
string toReplace = "float3 {0};")
string format = "float3 {0};")
{
var builder = new ShaderStringBuilder();
GenerateSpaceTranslationSurfaceInputs(neededSpaces, interpolatorType, builder, format);
surfaceInputs.AddShaderChunk(builder.ToString(), false);
}
public static void GenerateSpaceTranslationSurfaceInputs(
NeededCoordinateSpace neededSpaces,
InterpolatorType interpolatorType,
ShaderStringBuilder builder,
string format = "float3 {0};")
surfaceInputs.AddShaderChunk(string.Format(toReplace, CoordinateSpace.Object.ToVariableName(interpolatorType)), false);
builder.AppendLine(format, CoordinateSpace.Object.ToVariableName(interpolatorType));
surfaceInputs.AddShaderChunk(string.Format(toReplace, CoordinateSpace.World.ToVariableName(interpolatorType)), false);
builder.AppendLine(format, CoordinateSpace.World.ToVariableName(interpolatorType));
surfaceInputs.AddShaderChunk(string.Format(toReplace, CoordinateSpace.View.ToVariableName(interpolatorType)), false);
builder.AppendLine(format, CoordinateSpace.View.ToVariableName(interpolatorType));
surfaceInputs.AddShaderChunk(string.Format(toReplace, CoordinateSpace.Tangent.ToVariableName(interpolatorType)), false);
builder.AppendLine(format, CoordinateSpace.Tangent.ToVariableName(interpolatorType));
}
public static void GenerateStandardTransforms(

ShaderStringBuilder vertexDescriptionInputs,
CoordinateSpace preferedCoordinateSpace)
ShaderGraphRequirements vertexDescriptionRequirements,
CoordinateSpace preferredCoordinateSpace)
if (preferedCoordinateSpace == CoordinateSpace.Tangent)
preferedCoordinateSpace = CoordinateSpace.World;
if (preferredCoordinateSpace == CoordinateSpace.Tangent)
preferredCoordinateSpace = CoordinateSpace.World;
var combinedRequierments = graphRequiements.Union(modelRequiements);
var graphModelRequirements = graphRequiements.Union(modelRequiements);
var combinedRequirements = vertexDescriptionRequirements.Union(graphModelRequirements);
if (combinedRequierments.requiresNormal > 0 || combinedRequierments.requiresBitangent > 0)
if (combinedRequirements.requiresNormal > 0 || combinedRequirements.requiresBitangent > 0)
var name = preferedCoordinateSpace.ToVariableName(InterpolatorType.Normal);
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.Normal);
vertexDescriptionInputs.AppendLine("float3 {0} = {1};", name, ConvertBetweenSpace("v.normal", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Normal));
if (vertexDescriptionRequirements.requiresNormal > 0 || vertexDescriptionRequirements.requiresBitangent > 0)
vertexDescriptionInputs.AppendLine("vdi.{0} = {0};", name);
if (graphModelRequirements.requiresNormal > 0 || graphModelRequirements.requiresBitangent > 0)
{
vertexShader.AddShaderChunk(string.Format("o.{0} = {1};", name, ConvertBetweenSpace("v.normal", CoordinateSpace.Object, preferedCoordinateSpace, InputType.Normal)), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = {0};", name), false);
}
if (combinedRequierments.requiresTangent > 0 || combinedRequierments.requiresBitangent > 0)
if (combinedRequirements.requiresTangent > 0 || combinedRequirements.requiresBitangent > 0)
var name = preferedCoordinateSpace.ToVariableName(InterpolatorType.Tangent);
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.Tangent);
vertexDescriptionInputs.AppendLine("float3 {0} = {1};", name, ConvertBetweenSpace("v.tangent.xyz", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Vector));
if (vertexDescriptionRequirements.requiresTangent > 0 || vertexDescriptionRequirements.requiresBitangent > 0)
vertexDescriptionInputs.AppendLine("vdi.{0} = {0};", name);
if (graphModelRequirements.requiresTangent > 0 || graphModelRequirements.requiresBitangent > 0)
{
vertexShader.AddShaderChunk(string.Format("o.{0} = {1};", name, ConvertBetweenSpace("v.tangent.xyz", CoordinateSpace.Object, preferedCoordinateSpace, InputType.Vector)), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = {0};", name), false);
}
if (combinedRequierments.requiresBitangent > 0)
if (combinedRequirements.requiresBitangent > 0)
{
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.BiTangent);
vertexDescriptionInputs.AppendLine("float3 {0} = normalize(cross({1}, {2}.xyz) * {3});",
name,
preferredCoordinateSpace.ToVariableName(InterpolatorType.Normal),
preferredCoordinateSpace.ToVariableName(InterpolatorType.Tangent),
"v.tangent.w");
if (vertexDescriptionRequirements.requiresBitangent > 0)
vertexDescriptionInputs.AppendLine("vdi.{0} = {0};", name);
if (graphModelRequirements.requiresBitangent > 0)
var name = preferedCoordinateSpace.ToVariableName(InterpolatorType.BiTangent);
vertexShader.AddShaderChunk(string.Format("o.{0} = normalize(cross(o.{1}, o.{2}.xyz) * {3});",
name,
preferedCoordinateSpace.ToVariableName(InterpolatorType.Normal),
preferedCoordinateSpace.ToVariableName(InterpolatorType.Tangent),
"v.tangent.w"), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = {0};", name), false);
}
if (combinedRequierments.requiresViewDir > 0)
if (combinedRequirements.requiresViewDir > 0)
var name = preferedCoordinateSpace.ToVariableName(InterpolatorType.ViewDirection);
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.ViewDirection);
const string worldSpaceViewDir = "SafeNormalize(_WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz)";
var preferredSpaceViewDir = ConvertBetweenSpace(worldSpaceViewDir, CoordinateSpace.World, preferredCoordinateSpace, InputType.Vector);
if (vertexDescriptionRequirements.requiresViewDir > 0)
vertexDescriptionInputs.AppendLine("vdi.{0} = {1};", name, preferredSpaceViewDir);
if (graphModelRequirements.requiresViewDir > 0)
{
var worldSpaceViewDir = "SafeNormalize(_WorldSpaceCameraPos.xyz - mul(GetObjectToWorldMatrix(), float4(v.vertex.xyz, 1.0)).xyz)";
vertexShader.AddShaderChunk(string.Format("o.{0} = {1};", name, ConvertBetweenSpace(worldSpaceViewDir, CoordinateSpace.World, preferedCoordinateSpace, InputType.Vector)), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = {1};", name, preferredSpaceViewDir), false);
}
if (combinedRequierments.requiresPosition > 0)
if (combinedRequirements.requiresPosition > 0)
{
var name = preferredCoordinateSpace.ToVariableName(InterpolatorType.Position);
var preferredSpacePosition = ConvertBetweenSpace("v.vertex", CoordinateSpace.Object, preferredCoordinateSpace, InputType.Position);
if (vertexDescriptionRequirements.requiresPosition > 0)
vertexDescriptionInputs.AppendLine("float3 {0} = {1};", name, preferredSpacePosition);
if (graphModelRequirements.requiresPosition > 0)
var name = preferedCoordinateSpace.ToVariableName(InterpolatorType.Position);
vertexShader.AddShaderChunk(string.Format("o.{0} = {1}.xyz;", name, ConvertBetweenSpace("v.vertex", CoordinateSpace.Object, preferedCoordinateSpace, InputType.Position)), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = {1}.xyz;", name, preferredSpacePosition), false);
}
if (combinedRequierments.NeedsTangentSpace())
if (combinedRequirements.NeedsTangentSpace())
var tangent = preferredCoordinateSpace.ToVariableName(InterpolatorType.Tangent);
var bitangent = preferredCoordinateSpace.ToVariableName(InterpolatorType.BiTangent);
var normal = preferredCoordinateSpace.ToVariableName(InterpolatorType.Normal);
if (vertexDescriptionRequirements.NeedsTangentSpace())
vertexDescriptionInputs.AppendLine("float3x3 tangentSpaceTransform = float3x3({0},{1},{2});",
tangent, bitangent, normal);
if (graphModelRequirements.NeedsTangentSpace())
preferedCoordinateSpace.ToVariableName(InterpolatorType.Tangent), preferedCoordinateSpace.ToVariableName(InterpolatorType.BiTangent), preferedCoordinateSpace.ToVariableName(InterpolatorType.Normal)), false);
tangent, bitangent, normal), false);
}
// Generate the space translations needed by the vertex description
{
var sg = new ShaderGenerator();
GenerateSpaceTranslations(vertexDescriptionRequirements.requiresNormal, InterpolatorType.Normal, preferredCoordinateSpace,
InputType.Normal, sg, Dimension.Three);
GenerateSpaceTranslations(vertexDescriptionRequirements.requiresTangent, InterpolatorType.Tangent, preferredCoordinateSpace,
InputType.Vector, sg, Dimension.Three);
GenerateSpaceTranslations(vertexDescriptionRequirements.requiresBitangent, InterpolatorType.BiTangent, preferredCoordinateSpace,
InputType.Vector, sg, Dimension.Three);
GenerateSpaceTranslations(vertexDescriptionRequirements.requiresViewDir, InterpolatorType.ViewDirection, preferredCoordinateSpace,
InputType.Vector, sg, Dimension.Three);
GenerateSpaceTranslations(vertexDescriptionRequirements.requiresPosition, InterpolatorType.Position, preferredCoordinateSpace,
InputType.Position, sg, Dimension.Three);
vertexDescriptionInputs.AppendLines(sg.GetShaderString(0));
ShaderGenerator.GenerateSpaceTranslationPixelShader(combinedRequierments.requiresNormal, InterpolatorType.Normal, preferedCoordinateSpace,
// Generate the space translations needed by the surface description and model
GenerateSpaceTranslations(graphModelRequirements.requiresNormal, InterpolatorType.Normal, preferredCoordinateSpace,
ShaderGenerator.GenerateSpaceTranslationPixelShader(combinedRequierments.requiresTangent, InterpolatorType.Tangent, preferedCoordinateSpace,
GenerateSpaceTranslations(graphModelRequirements.requiresTangent, InterpolatorType.Tangent, preferredCoordinateSpace,
ShaderGenerator.GenerateSpaceTranslationPixelShader(combinedRequierments.requiresBitangent, InterpolatorType.BiTangent, preferedCoordinateSpace,
GenerateSpaceTranslations(graphModelRequirements.requiresBitangent, InterpolatorType.BiTangent, preferredCoordinateSpace,
ShaderGenerator.GenerateSpaceTranslationPixelShader(combinedRequierments.requiresViewDir, InterpolatorType.ViewDirection, preferedCoordinateSpace,
GenerateSpaceTranslations(graphModelRequirements.requiresViewDir, InterpolatorType.ViewDirection, preferredCoordinateSpace,
ShaderGenerator.GenerateSpaceTranslationPixelShader(combinedRequierments.requiresPosition, InterpolatorType.Position, preferedCoordinateSpace,
GenerateSpaceTranslations(graphModelRequirements.requiresPosition, InterpolatorType.Position, preferredCoordinateSpace,
if (combinedRequierments.requiresVertexColor)
if (vertexDescriptionRequirements.requiresVertexColor)
vertexDescriptionInputs.AppendLine("vdi.{0} = v.color;", ShaderGeneratorNames.VertexColor);
if (graphModelRequirements.requiresVertexColor)
{
interpolators.AddShaderChunk(string.Format("float4 {0} : COLOR;", ShaderGeneratorNames.VertexColor), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = v.color;", ShaderGeneratorNames.VertexColor), false);

if (combinedRequierments.requiresScreenPosition)
if (combinedRequirements.requiresScreenPosition)
{
interpolators.AddShaderChunk(string.Format("float4 {0} : TEXCOORD{1};", ShaderGeneratorNames.ScreenPosition, interpolatorIndex), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = ComputeScreenPos(mul(GetWorldToHClipMatrix(), mul(GetObjectToWorldMatrix(), v.vertex)), _ProjectionParams.x);", ShaderGeneratorNames.ScreenPosition), false);

foreach (var channel in combinedRequierments.requiresMeshUVs.Distinct())
if (combinedRequirements.requiresScreenPosition)
{
var screenPosition = "ComputeScreenPos(mul(GetWorldToHClipMatrix(), mul(GetObjectToWorldMatrix(), v.vertex.xyz)), _ProjectionParams.x)";
if (vertexDescriptionRequirements.requiresScreenPosition)
{
vertexDescriptionInputs.AppendLine("float4 {0} = {1};", ShaderGeneratorNames.ScreenPosition, screenPosition);
}
if (graphModelRequirements.requiresScreenPosition)
{
interpolators.AddShaderChunk(string.Format("float4 {0} : TEXCOORD{1};", ShaderGeneratorNames.ScreenPosition, interpolatorIndex), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = {1};", ShaderGeneratorNames.ScreenPosition, screenPosition), false);
pixelShader.AddShaderChunk(string.Format("float4 {0} = IN.{0};", ShaderGeneratorNames.ScreenPosition), false);
interpolatorIndex++;
}
}
foreach (var channel in vertexDescriptionRequirements.requiresMeshUVs.Distinct())
{
vertexDescriptionInputs.AppendLine("vdi.{0} = v.texcoord{1};", channel.GetUVName(), (int)channel);
}
foreach (var channel in graphModelRequirements.requiresMeshUVs.Distinct())
{
interpolators.AddShaderChunk(string.Format("half4 {0} : TEXCOORD{1};", channel.GetUVName(), interpolatorIndex == 0 ? "" : interpolatorIndex.ToString()), false);
vertexShader.AddShaderChunk(string.Format("o.{0} = v.texcoord{1};", channel.GetUVName(), (int)channel), false);

// structure using the requirements for ONLY the shader graph
// additional requirements have come from the lighting model
// and are not needed in the shader graph
{
var replaceString = "surfaceInput.{0} = {0};";
GenerateSpaceTranslationSurfaceInputs(graphRequiements.requiresNormal, InterpolatorType.Normal, surfaceInputs, replaceString);
GenerateSpaceTranslationSurfaceInputs(graphRequiements.requiresTangent, InterpolatorType.Tangent, surfaceInputs, replaceString);

}
{
var replaceString = "vdi.{0} = {0};";
var sg = new ShaderGenerator();
GenerateSpaceTranslationSurfaceInputs(vertexDescriptionRequirements.requiresNormal, InterpolatorType.Normal, sg, replaceString);
GenerateSpaceTranslationSurfaceInputs(vertexDescriptionRequirements.requiresTangent, InterpolatorType.Tangent, sg, replaceString);
GenerateSpaceTranslationSurfaceInputs(vertexDescriptionRequirements.requiresBitangent, InterpolatorType.BiTangent, sg, replaceString);
GenerateSpaceTranslationSurfaceInputs(vertexDescriptionRequirements.requiresViewDir, InterpolatorType.ViewDirection, sg, replaceString);
GenerateSpaceTranslationSurfaceInputs(vertexDescriptionRequirements.requiresPosition, InterpolatorType.Position, sg, replaceString);
vertexDescriptionInputs.AppendLines(sg.GetShaderString(0));
}
if (graphRequiements.requiresVertexColor)
surfaceInputs.AddShaderChunk(string.Format("surfaceInput.{0} = {0};", ShaderGeneratorNames.VertexColor), false);

return "error";
}
public static void GenerateSpaceTranslationPixelShader(
public static void GenerateSpaceTranslations(
NeededCoordinateSpace neededSpaces,
InterpolatorType type,
CoordinateSpace from,

public static string GetPreviewSubShader(AbstractMaterialNode node, ShaderGraphRequirements shaderGraphRequirements)
{
var interpolators = new ShaderGenerator();
var vertexDescriptionInputs = new ShaderStringBuilder(3);
var vertexShader = new ShaderGenerator();
var pixelShader = new ShaderGenerator();
var surfaceInputs = new ShaderGenerator();

16,
interpolators,
vertexDescriptionInputs,
ShaderGraphRequirements.none,
vertexDescriptionInputs.AppendLines(vertexShader.GetShaderString(0));
var outputs = new ShaderGenerator();
if (node != null)

}
var res = subShaderTemplate.Replace("${Interpolators}", interpolators.GetShaderString(0));
res = res.Replace("${VertexShader}", vertexShader.GetShaderString(0));
res = res.Replace("${VertexShader}", vertexDescriptionInputs.ToString());
res = res.Replace("${LocalPixelShader}", pixelShader.GetShaderString(0));
res = res.Replace("${SurfaceInputs}", surfaceInputs.GetShaderString(0));
res = res.Replace("${SurfaceOutputRemap}", outputs.GetShaderString(0));

33
ShaderGraph/com.unity.shadergraph/Editor/Data/Util/ShaderStringBuilder.cs


enum ScopeType
{
Indent,
Block
Block,
BlockSemicolon
}
StringBuilder m_StringBuilder;

m_ScopeStack = new Stack<ScopeType>();
m_Mappings = new List<ShaderStringMapping>();
m_CurrentMapping = new ShaderStringMapping();
}
public ShaderStringBuilder(int indentationLevel)
: this()
{
IncreaseIndent(indentationLevel);
}
public void AppendNewLine()

AppendLine("{");
IncreaseIndent();
m_ScopeStack.Push(ScopeType.Block);
return this;
}
public IDisposable BlockSemicolonScope()
{
AppendLine("{");
IncreaseIndent();
m_ScopeStack.Push(ScopeType.BlockSemicolon);
return this;
}

}
public void IncreaseIndent(int level)
{
for (var i = 0; i < level; i++)
IncreaseIndent();
}
public void DecreaseIndent(int level)
{
for (var i = 0; i < level; i++)
DecreaseIndent();
}
public void Dispose()
{
switch (m_ScopeStack.Pop())

case ScopeType.Block:
DecreaseIndent();
AppendLine("}");
break;
case ScopeType.BlockSemicolon:
DecreaseIndent();
AppendLine("};");
break;
}
}

2
ShaderGraph/com.unity.shadergraph/Editor/DefaultShaderIncludes.cs


var path = GetRepositoryPath();
if (path == null)
return null;
path = Path.Combine(path, "DebugOutput");
path = Application.dataPath + "/DebugOutput";// Path.Combine(path, "DebugOutput");
return Directory.Exists(path) ? path : null;
}

69
ShaderGraph/com.unity.shadergraph/Editor/Drawing/PreviewManager.cs


MaterialPropertyBlock m_PreviewPropertyBlock;
PreviewSceneResources m_SceneResources;
Texture2D m_ErrorTexture;
Shader m_UberShader;
Shader m_ColorShader;
string m_OutputIdName;
Vector2? m_NewMasterPreviewSize;

m_ErrorTexture.filterMode = FilterMode.Point;
m_ErrorTexture.Apply();
m_SceneResources = new PreviewSceneResources();
m_UberShader = ShaderUtil.CreateShaderAsset(k_EmptyShader);
m_UberShader.hideFlags = HideFlags.HideAndDontSave;
m_ColorShader = ShaderUtil.CreateShaderAsset(k_EmptyShader);
m_ColorShader.hideFlags = HideFlags.HideAndDontSave;
m_MasterRenderData = new PreviewRenderData
{
renderTexture = new RenderTexture(400, 400, 16, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default) { hideFlags = HideFlags.HideAndDontSave }

public void RenderPreviews()
{
UpdateShaders();
// Union time dependent previews into dirty previews
m_DirtyPreviews.UnionWith(m_TimeDependentPreviews);
PropagateNodeSet(m_DirtyPreviews);
m_NodesWithWireframePreview.Clear();
else if (node.previewMode == PreviewMode.Wireframe)
m_NodesWithWireframePreview.Add(node.tempId.index);
PropagateNodeSet(m_NodesWithWireframePreview);
m_NodesWith3DPreview.UnionWith(m_NodesWithWireframePreview);
UpdateShaders();
// Union time dependent previews into dirty previews
m_DirtyPreviews.UnionWith(m_TimeDependentPreviews);
PropagateNodeSet(m_DirtyPreviews);
foreach (var index in m_DirtyPreviews)
{
var renderData = m_RenderDatas[index];

}
IndexSet m_NodesWith3DPreview = new IndexSet();
IndexSet m_NodesWithWireframePreview = new IndexSet();
void UpdateShaders()
{

var masterNodes = new List<INode>();
var uberNodes = new List<INode>();
var colorNodes = new List<INode>();
var wireframeNodes = new List<INode>();
var node = m_Graph.GetNodeFromTempId(m_Identifiers[index]);
var node = m_Graph.GetNodeFromTempId(m_Identifiers[index]) as AbstractMaterialNode;
else if(node.previewMode == PreviewMode.Wireframe)
wireframeNodes.Add(node);
uberNodes.Add(node);
colorNodes.Add(node);
var count = Math.Min(uberNodes.Count, 1) + masterNodes.Count;
var count = Math.Min(colorNodes.Count, 1) + masterNodes.Count;
try
{

i++;
EditorUtility.DisplayProgressBar("Shader Graph", string.Format("Compiling preview shaders ({0}/{1})", i, count), 0f);
}
if (uberNodes.Count > 0)
if (colorNodes.Count > 0)
var results = m_Graph.GetUberPreviewShader();
var results = m_Graph.GetUberColorShader();
ShaderUtil.UpdateShaderAsset(m_UberShader, results.shader);
ShaderUtil.UpdateShaderAsset(m_ColorShader, results.shader);
File.WriteAllText(debugOutputPath + "/UberShader.shader", (results.shader ?? "null").Replace("UnityEngine.MaterialGraph", "Generated"));
File.WriteAllText(debugOutputPath + "/ColorShader.shader", (results.shader ?? "null").Replace("UnityEngine.MaterialGraph", "Generated"));
if (MaterialGraphAsset.ShaderHasError(m_UberShader))
if (MaterialGraphAsset.ShaderHasError(m_ColorShader))
var errors = MaterialGraphAsset.GetShaderErrors(m_UberShader);
var errors = MaterialGraphAsset.GetShaderErrors(m_ColorShader);
var message = new ShaderStringBuilder();
message.AppendLine(@"Preview shader for graph has {0} error{1}:", errors.Length, errors.Length != 1 ? "s" : "");
foreach (var error in errors)

}
}
Debug.LogWarning(message.ToString());
ShaderUtil.ClearShaderErrors(m_UberShader);
ShaderUtil.UpdateShaderAsset(m_UberShader, k_EmptyShader);
ShaderUtil.ClearShaderErrors(m_ColorShader);
ShaderUtil.UpdateShaderAsset(m_ColorShader, k_EmptyShader);
foreach (var node in uberNodes)
foreach (var node in colorNodes)
shaderData.shader = m_UberShader;
shaderData.shader = m_ColorShader;
shaderData.hasError = uberShaderHasError;
}
i++;

return;
var shaderData = renderData.shaderData;
if (!(node is IMasterNode) && (!node.hasPreview || NodeUtils.FindEffectiveShaderStage(node, true) == ShaderStage.Vertex))
if (!(node is IMasterNode) && !node.hasPreview)
{
shaderData.shaderString = null;
}

// Debug output
if (MaterialGraphAsset.ShaderHasError(shaderData.shader))
{
var errors = MaterialGraphAsset.GetShaderErrors(shaderData.shader);
foreach (var error in errors)
Debug.LogFormat("Compilation error in {3} at line {1} (on {2}):\n{0}", error.message, error.line, error.platform, "graph");
shaderData.hasError = true;
if (debugOutputPath != null)
{

{
if (renderData.shaderData != null
&& renderData.shaderData.shader != null
&& renderData.shaderData.shader != m_UberShader)
&& renderData.shaderData.shader != m_ColorShader)
Object.DestroyImmediate(renderData.shaderData.shader, true);
if (renderData.renderTexture != null)
Object.DestroyImmediate(renderData.renderTexture, true);

void ReleaseUnmanagedResources()
{
if (m_UberShader != null)
if (m_ColorShader != null)
Object.DestroyImmediate(m_UberShader, true);
m_UberShader = null;
Object.DestroyImmediate(m_ColorShader, true);
m_ColorShader = null;
}
if (m_ErrorTexture != null)
{

17
ShaderGraph/com.unity.shadergraph/Editor/Drawing/Views/MaterialGraphView.cs


if (startSlot == null)
return compatibleAnchors;
var startStage = startSlot.shaderStage;
if (startStage == ShaderStage.Dynamic)
startStage = NodeUtils.FindEffectiveShaderStage(startSlot.owner, startSlot.isOutputSlot);
var startStage = startSlot.stageCapability;
if (startStage == ShaderStageCapability.All)
startStage = NodeUtils.GetEffectiveShaderStageCapability(startSlot, true) & NodeUtils.GetEffectiveShaderStageCapability(startSlot, false);
foreach (var candidateAnchor in ports.ToList())
{

if (startStage != ShaderStage.Dynamic)
if (startStage != ShaderStageCapability.All)
var candidateStage = candidateSlot.shaderStage;
if (candidateStage == ShaderStage.Dynamic)
candidateStage = NodeUtils.FindEffectiveShaderStage(candidateSlot.owner, !startSlot.isOutputSlot);
if (candidateStage != ShaderStage.Dynamic && candidateStage != startStage)
var candidateStage = candidateSlot.stageCapability;
if (candidateStage == ShaderStageCapability.All)
candidateStage = NodeUtils.GetEffectiveShaderStageCapability(candidateSlot, true)
& NodeUtils.GetEffectiveShaderStageCapability(candidateSlot, false);
if (candidateStage != ShaderStageCapability.All && candidateStage != startStage)
continue;
}

正在加载...
取消
保存