initial commit

This commit is contained in:
Jo 2025-01-07 02:06:59 +01:00
parent 6715289efe
commit 788c3389af
37645 changed files with 2526849 additions and 80 deletions

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b43ef3944c134a74995e6582de94d21b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,86 @@
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Basic", "Boolean")]
class BooleanNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private bool m_Value;
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
public BooleanNode()
{
name = "Boolean";
synonyms = new string[] { "switch", "true", "false", "on", "off" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new BooleanMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, false));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[ToggleControl("")]
public ToggleData value
{
get { return new ToggleData(m_Value); }
set
{
if (m_Value == value.isOn)
return;
m_Value = value.isOn;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new BooleanShaderProperty()
{
overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = m_Value
});
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (generationMode.IsPreview())
return;
sb.AppendLine("$precision {0} = {1};", GetVariableNameForNode(), (m_Value ? 1 : 0));
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Boolean)
{
name = GetVariableNameForNode(),
booleanValue = m_Value
});
}
public AbstractShaderProperty AsShaderProperty()
{
return new BooleanShaderProperty { value = m_Value };
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a6bd4d4655c0b9046a14e6ab0caebdc3
timeCreated: 1445864587
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,175 @@
using System;
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph.Internal
{
public enum ColorMode
{
Default,
HDR
}
}
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Basic", "Color")]
class ColorNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
public override int latestVersion => 1;
public ColorNode()
{
name = "Color";
synonyms = new string[] { "rgba" };
UpdateNodeAfterDeserialization();
}
[SerializeField]
Color m_Color = new Color(UnityEngine.Color.clear, ColorMode.Default);
[Serializable]
public struct Color
{
public UnityEngine.Color color;
public ColorMode mode;
public Color(UnityEngine.Color color, ColorMode mode)
{
this.color = color;
this.mode = mode;
}
}
[ColorControl("")]
public Color color
{
get { return m_Color; }
set
{
if ((value.color == m_Color.color) && (value.mode == m_Color.mode))
return;
if ((value.mode != m_Color.mode) && (value.mode == ColorMode.Default))
{
float r = Mathf.Clamp(value.color.r, 0, 1);
float g = Mathf.Clamp(value.color.g, 0, 1);
float b = Mathf.Clamp(value.color.b, 0, 1);
float a = Mathf.Clamp(value.color.a, 0, 1);
value.color = new UnityEngine.Color(r, g, b, a);
}
m_Color = value;
Dirty(ModificationScope.Graph);
}
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new ColorShaderProperty()
{
overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = color.color,
colorMode = color.mode
});
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (generationMode.IsPreview())
return;
switch (sgVersion)
{
case 0:
sb.AppendLine(@"$precision4 {0} = IsGammaSpace() ? $precision4({1}, {2}, {3}, {4}) : $precision4(SRGBToLinear($precision3({1}, {2}, {3})), {4});"
, GetVariableNameForNode()
, NodeUtils.FloatToShaderValue(color.color.r)
, NodeUtils.FloatToShaderValue(color.color.g)
, NodeUtils.FloatToShaderValue(color.color.b)
, NodeUtils.FloatToShaderValue(color.color.a));
break;
case 1:
//HDR color picker assumes Linear space, regular color picker assumes SRGB. Handle both cases
if (color.mode == ColorMode.Default)
{
sb.AppendLine(@"$precision4 {0} = IsGammaSpace() ? $precision4({1}, {2}, {3}, {4}) : $precision4(SRGBToLinear($precision3({1}, {2}, {3})), {4});"
, GetVariableNameForNode()
, NodeUtils.FloatToShaderValue(color.color.r)
, NodeUtils.FloatToShaderValue(color.color.g)
, NodeUtils.FloatToShaderValue(color.color.b)
, NodeUtils.FloatToShaderValue(color.color.a));
}
else
{
sb.AppendLine(@"$precision4 {0} = IsGammaSpace() ? LinearToSRGB($precision4({1}, {2}, {3}, {4})) : $precision4({1}, {2}, {3}, {4});"
, GetVariableNameForNode()
, NodeUtils.FloatToShaderValue(color.color.r)
, NodeUtils.FloatToShaderValue(color.color.g)
, NodeUtils.FloatToShaderValue(color.color.b)
, NodeUtils.FloatToShaderValue(color.color.a));
}
break;
}
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
UnityEngine.Color propColor = color.color;
if (color.mode == ColorMode.Default)
{
if (PlayerSettings.colorSpace == ColorSpace.Linear)
propColor = propColor.linear;
}
if (color.mode == ColorMode.HDR)
{
switch (sgVersion)
{
case 0:
if (PlayerSettings.colorSpace == ColorSpace.Linear)
propColor = propColor.linear;
break;
case 1:
if (PlayerSettings.colorSpace == ColorSpace.Gamma)
propColor = propColor.gamma;
break;
}
}
// we use Vector4 type to avoid all of the automatic color conversions of PropertyType.Color
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = GetVariableNameForNode(),
vector4Value = propColor
});
}
public AbstractShaderProperty AsShaderProperty()
{
return new ColorShaderProperty() { value = color.color, colorMode = color.mode };
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 325c0e24c20746345a5f90dc201973f8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,75 @@
using System.Collections.Generic;
using System.Globalization;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
enum ConstantType
{
PI,
TAU,
PHI,
E,
SQRT2
};
[Title("Input", "Basic", "Constant")]
class ConstantNode : AbstractMaterialNode, IGeneratesBodyCode
{
static Dictionary<ConstantType, float> m_constantList = new Dictionary<ConstantType, float>
{
{ConstantType.PI, 3.1415926f },
{ConstantType.TAU, 6.28318530f},
{ConstantType.PHI, 1.618034f},
{ConstantType.E, 2.718282f},
{ConstantType.SQRT2, 1.414214f},
};
[SerializeField]
private ConstantType m_constant = ConstantType.PI;
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Out";
[EnumControl("")]
public ConstantType constant
{
get { return m_constant; }
set
{
if (m_constant == value)
return;
m_constant = value;
Dirty(ModificationScope.Graph);
}
}
public ConstantNode()
{
name = "Constant";
synonyms = new string[] { "pi", "tau", "phi" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
sb.AppendLine(string.Format("$precision {0} = {1};"
, GetVariableNameForNode()
, m_constantList[constant].ToString(CultureInfo.InvariantCulture)));
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f48f68efc30ae334098ff30e88fbf9db
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,89 @@
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Basic", "Integer")]
class IntegerNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private int m_Value;
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
public IntegerNode()
{
name = "Integer";
synonyms = new string[] { "whole number" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[IntegerControl("")]
public int value
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = value,
floatType = FloatType.Integer
});
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (generationMode.IsPreview())
return;
sb.AppendLine(string.Format("$precision {0} = {1};", GetVariableNameForNode(), m_Value));
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Float)
{
name = GetVariableNameForNode(),
floatValue = m_Value
});
}
public AbstractShaderProperty AsShaderProperty()
{
return new Vector1ShaderProperty { value = value, floatType = FloatType.Integer };
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: e449bdf3b245898489ebab4f709ded62
timeCreated: 1445864587
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,95 @@
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using System.Globalization;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Basic", "Slider")]
class SliderNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private Vector3 m_Value = new Vector3(0f, 0f, 1f);
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
public SliderNode()
{
name = "Slider";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[SliderControl("", true)]
public Vector3 value
{
get { return m_Value; }
set
{
if (m_Value == value)
return;
m_Value = value;
Dirty(ModificationScope.Node);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = GetVariableNameForNode(),
generatePropertyBlock = false,
value = value.x,
rangeValues = new Vector2(value.y, value.z),
floatType = FloatType.Slider
});
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (generationMode.IsPreview())
return;
sb.AppendLine(string.Format(CultureInfo.InvariantCulture, "$precision {0} = {1};", GetVariableNameForNode(), m_Value.x));
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Float)
{
name = GetVariableNameForNode(),
floatValue = m_Value.x
});
}
public AbstractShaderProperty AsShaderProperty()
{
return new Vector1ShaderProperty
{
value = value.x,
rangeValues = new Vector2(value.y, value.z),
floatType = FloatType.Slider
};
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 39d5ba890306e584c9fb4fede8c37f9c
timeCreated: 1445864587
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,64 @@
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Basic", "Time")]
class TimeNode : AbstractMaterialNode, IMayRequireTime
{
private const string kOutputSlotName = "Time";
private const string kOutputSlot1Name = "Sine Time";
private const string kOutputSlot2Name = "Cosine Time";
private const string kOutputSlot3Name = "Delta Time";
private const string kOutputSlot4Name = "Smooth Delta";
public const int OutputSlotId = 0;
public const int OutputSlot1Id = 1;
public const int OutputSlot2Id = 2;
public const int OutputSlot3Id = 3;
public const int OutputSlot4Id = 4;
public TimeNode()
{
name = "Time";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlot2Id, kOutputSlot2Name, kOutputSlot2Name, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlot3Id, kOutputSlot3Name, kOutputSlot3Name, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlot4Id, kOutputSlot4Name, kOutputSlot4Name, SlotType.Output, 0));
RemoveSlotsNameNotMatching(validSlots);
}
protected int[] validSlots
{
get { return new[] { OutputSlotId, OutputSlot1Id, OutputSlot2Id, OutputSlot3Id, OutputSlot4Id }; }
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlot1Id:
return "IN.TimeParameters.y";
case OutputSlot2Id:
return "IN.TimeParameters.z";
case OutputSlot3Id:
return "unity_DeltaTime.x";
case OutputSlot4Id:
return "unity_DeltaTime.z";
default:
return "IN.TimeParameters.x";
}
}
public bool RequiresTime()
{
return true;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 66310de0dabd3074aa56ab7714324cc0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,57 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Basic", "Float")]
class Vector1Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private float m_Value = 0;
const string kInputSlotXName = "X";
const string kOutputSlotName = "Out";
public const int InputSlotXId = 1;
public const int OutputSlotId = 0;
public Vector1Node()
{
name = "Float";
synonyms = new string[] { "Vector 1", "1", "v1", "vec1", "scalar" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(InputSlotXId, kInputSlotXName, kInputSlotXName, SlotType.Input, m_Value));
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, InputSlotXId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var inputValue = GetSlotValue(InputSlotXId, generationMode);
sb.AppendLine(string.Format("$precision {0} = {1};", GetVariableNameForSlot(OutputSlotId), inputValue));
}
public AbstractShaderProperty AsShaderProperty()
{
var slot = FindInputSlot<Vector1MaterialSlot>(InputSlotXId);
return new Vector1ShaderProperty { value = slot.value };
}
public override void OnAfterDeserialize()
{
base.OnAfterDeserialize();
name = "Float";
}
int IPropertyFromNode.outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 87c4299b09d95d64c99884296038ceeb
timeCreated: 1445864587
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,62 @@
using System.Collections.Generic;
using System.Linq;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Basic", "Vector 2")]
class Vector2Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private Vector2 m_Value = Vector2.zero;
const string kInputSlotXName = "X";
const string kInputSlotYName = "Y";
const string kOutputSlotName = "Out";
public const int OutputSlotId = 0;
public const int InputSlotXId = 1;
public const int InputSlotYId = 2;
public Vector2Node()
{
name = "Vector 2";
synonyms = new string[] { "2", "v2", "vec2", "float2" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(InputSlotXId, kInputSlotXName, kInputSlotXName, SlotType.Input, m_Value.x));
AddSlot(new Vector1MaterialSlot(InputSlotYId, kInputSlotYName, kInputSlotYName, SlotType.Input, m_Value.y, label1: "Y"));
AddSlot(new Vector2MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, InputSlotXId, InputSlotYId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var inputXValue = GetSlotValue(InputSlotXId, generationMode);
var inputYValue = GetSlotValue(InputSlotYId, generationMode);
var outputName = GetVariableNameForSlot(OutputSlotId);
var s = string.Format("$precision2 {0} = $precision2({1}, {2});",
outputName,
inputXValue,
inputYValue);
sb.AppendLine(s);
}
public AbstractShaderProperty AsShaderProperty()
{
var slotX = FindInputSlot<Vector1MaterialSlot>(InputSlotXId);
var slotY = FindInputSlot<Vector1MaterialSlot>(InputSlotYId);
return new Vector2ShaderProperty { value = new Vector2(slotX.value, slotY.value) };
}
int IPropertyFromNode.outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 8361d1f9d12a489438c0b1e2e48c8542
timeCreated: 1446473341
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,67 @@
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Basic", "Vector 3")]
class Vector3Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private Vector3 m_Value = Vector3.zero;
const string kInputSlotXName = "X";
const string kInputSlotYName = "Y";
const string kInputSlotZName = "Z";
const string kOutputSlotName = "Out";
public const int OutputSlotId = 0;
public const int InputSlotXId = 1;
public const int InputSlotYId = 2;
public const int InputSlotZId = 3;
public Vector3Node()
{
name = "Vector 3";
synonyms = new string[] { "3", "v3", "vec3", "float3" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(InputSlotXId, kInputSlotXName, kInputSlotXName, SlotType.Input, m_Value.x));
AddSlot(new Vector1MaterialSlot(InputSlotYId, kInputSlotYName, kInputSlotYName, SlotType.Input, m_Value.y, label1: "Y"));
AddSlot(new Vector1MaterialSlot(InputSlotZId, kInputSlotZName, kInputSlotZName, SlotType.Input, m_Value.z, label1: "Z"));
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, InputSlotXId, InputSlotYId, InputSlotZId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var inputXValue = GetSlotValue(InputSlotXId, generationMode);
var inputYValue = GetSlotValue(InputSlotYId, generationMode);
var inputZValue = GetSlotValue(InputSlotZId, generationMode);
var outputName = GetVariableNameForSlot(outputSlotId);
var s = string.Format("$precision3 {0} = $precision3({1}, {2}, {3});",
outputName,
inputXValue,
inputYValue,
inputZValue);
sb.AppendLine(s);
}
public AbstractShaderProperty AsShaderProperty()
{
var slotX = FindInputSlot<Vector1MaterialSlot>(InputSlotXId);
var slotY = FindInputSlot<Vector1MaterialSlot>(InputSlotYId);
var slotZ = FindInputSlot<Vector1MaterialSlot>(InputSlotZId);
return new Vector3ShaderProperty { value = new Vector3(slotX.value, slotY.value, slotZ.value) };
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 1350e4a38ff5ae44a9d8627d33b48de8
timeCreated: 1453378777
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,73 @@
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Basic", "Vector 4")]
class Vector4Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private Vector4 m_Value = Vector4.zero;
const string kInputSlotXName = "X";
const string kInputSlotYName = "Y";
const string kInputSlotZName = "Z";
const string kInputSlotWName = "W";
const string kOutputSlotName = "Out";
public const int OutputSlotId = 0;
public const int InputSlotXId = 1;
public const int InputSlotYId = 2;
public const int InputSlotZId = 3;
public const int InputSlotWId = 4;
public Vector4Node()
{
name = "Vector 4";
synonyms = new string[] { "4", "v4", "vec4", "float4" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(InputSlotXId, kInputSlotXName, kInputSlotXName, SlotType.Input, m_Value.x));
AddSlot(new Vector1MaterialSlot(InputSlotYId, kInputSlotYName, kInputSlotYName, SlotType.Input, m_Value.y, label1: "Y"));
AddSlot(new Vector1MaterialSlot(InputSlotZId, kInputSlotZName, kInputSlotZName, SlotType.Input, m_Value.z, label1: "Z"));
AddSlot(new Vector1MaterialSlot(InputSlotWId, kInputSlotWName, kInputSlotWName, SlotType.Input, m_Value.w, label1: "W"));
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, InputSlotXId, InputSlotYId, InputSlotZId, InputSlotWId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var inputXValue = GetSlotValue(InputSlotXId, generationMode);
var inputYValue = GetSlotValue(InputSlotYId, generationMode);
var inputZValue = GetSlotValue(InputSlotZId, generationMode);
var inputWValue = GetSlotValue(InputSlotWId, generationMode);
var outputName = GetVariableNameForSlot(outputSlotId);
var s = string.Format("$precision4 {0} = $precision4({1}, {2}, {3}, {4});",
outputName,
inputXValue,
inputYValue,
inputZValue,
inputWValue);
sb.AppendLine(s);
}
public AbstractShaderProperty AsShaderProperty()
{
var slotX = FindInputSlot<Vector1MaterialSlot>(InputSlotXId);
var slotY = FindInputSlot<Vector1MaterialSlot>(InputSlotYId);
var slotZ = FindInputSlot<Vector1MaterialSlot>(InputSlotZId);
var slotW = FindInputSlot<Vector1MaterialSlot>(InputSlotWId);
return new Vector4ShaderProperty { value = new Vector4(slotX.value, slotY.value, slotZ.value, slotW.value) };
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f34a640000e664d4f8b2e0795df7fad9
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,280 @@
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
using UnityEditor.Rendering;
namespace UnityEditor.ShaderGraph
{
[Serializable]
[Title("Custom Interpolators", "Instance")]
class CustomInterpolatorNode : AbstractMaterialNode
{
[SerializeField]
internal string customBlockNodeName = "K_INVALID";
[SerializeField]
private BlockNode.CustomBlockType serializedType = BlockNode.CustomBlockType.Vector4;
public override bool hasPreview { get { return true; } }
internal override bool ExposeToSearcher { get => false; } // This is exposed in a special way.
public override bool allowedInSubGraph { get => false; }
internal BlockNode e_targetBlockNode // weak indirection via customBlockNodeName
{
get => (owner?.vertexContext.blocks.Find(cib => cib.value.descriptor.name == customBlockNodeName))?.value ?? null;
}
public CustomInterpolatorNode()
{
UpdateNodeAfterDeserialization();
}
internal void ConnectToCustomBlock(BlockNode node)
{
// if somehow we were already connected, be sure to unregister.
if (e_targetBlockNode != null)
{
e_targetBlockNode.UnregisterCallback(OnCustomBlockModified);
}
// if a new cib is renamed to match us when we didn't have a target (unusual case, but covering all bases here).
if (node?.isCustomBlock ?? false)
{
name = node.customName + " (Custom Interpolator)";
customBlockNodeName = node.customName;
serializedType = node.customWidth;
BuildSlot();
node.RegisterCallback(OnCustomBlockModified);
}
}
internal void ConnectToCustomBlockByName(string customBlockName)
{
// see above
if (e_targetBlockNode != null)
{
e_targetBlockNode.UnregisterCallback(OnCustomBlockModified);
}
name = customBlockName + " (Custom Interpolator)";
customBlockNodeName = customBlockName;
if (e_targetBlockNode != null)
{
serializedType = e_targetBlockNode.customWidth;
BuildSlot();
e_targetBlockNode.RegisterCallback(OnCustomBlockModified);
}
else
{
// We should get badged in OnValidate.
}
}
void OnCustomBlockModified(AbstractMaterialNode node, Graphing.ModificationScope scope)
{
if (node is BlockNode bnode)
{
if (bnode?.isCustomBlock ?? false)
{
name = bnode.customName + " (Custom Interpolator)";
customBlockNodeName = bnode.customName;
if (e_targetBlockNode != null && e_targetBlockNode.owner != null)
{
serializedType = e_targetBlockNode.customWidth;
BuildSlot();
Dirty(ModificationScope.Node);
Dirty(ModificationScope.Topological);
}
}
}
// bnode information we got is somehow invalid, this is probably case for an exception.
}
public override void ValidateNode()
{
// Our node was deleted or we had bad deserialization, we need to badge.
if (e_targetBlockNode == null || e_targetBlockNode.owner == null)
{
e_targetBlockNode?.UnregisterCallback(OnCustomBlockModified);
owner.AddValidationError(objectId, String.Format("Custom Block Interpolator '{0}' not found.", customBlockNodeName), ShaderCompilerMessageSeverity.Error);
}
else
{
// our blockNode reference is somehow valid again after it wasn't,
// we can reconnect and everything should be restored.
ConnectToCustomBlockByName(customBlockNodeName);
}
}
public override void UpdateNodeAfterDeserialization()
{
// our e_targetBlockNode is unsafe here, so we build w/our serialization info and hope for the best!
BuildSlot();
base.UpdateNodeAfterDeserialization();
}
void BuildSlot()
{
switch (serializedType)
{
case BlockNode.CustomBlockType.Float:
AddSlot(new Vector1MaterialSlot(0, "Out", "Out", SlotType.Output, default(float), ShaderStageCapability.Fragment));
break;
case BlockNode.CustomBlockType.Vector2:
AddSlot(new Vector2MaterialSlot(0, "Out", "Out", SlotType.Output, default(Vector2), ShaderStageCapability.Fragment));
break;
case BlockNode.CustomBlockType.Vector3:
AddSlot(new Vector3MaterialSlot(0, "Out", "Out", SlotType.Output, default(Vector3), ShaderStageCapability.Fragment));
break;
case BlockNode.CustomBlockType.Vector4:
AddSlot(new Vector4MaterialSlot(0, "Out", "Out", SlotType.Output, default(Vector4), ShaderStageCapability.Fragment));
break;
}
RemoveSlotsNameNotMatching(new[] { 0 });
}
public override string GetVariableNameForSlot(int slotid)
{
// Awkward case where current preview generation code does not use the Output for the all/isfinite preview for self.
// GetOutputForSlot does _not_ make use of GetVariableNameForSlot in any way, so this is just to prevent disrupting
// any existing expected behavior in the preview.
if (CustomInterpolatorUtils.generatorNodeOnly)
{
var slotRef = GetSlotReference(0);
return GetOutputForSlot(slotRef, slotRef.slot.concreteValueType, GenerationMode.Preview);
}
return "float4(1,0,1,1)";
}
protected internal override string GetOutputForSlot(SlotReference fromSocketRef, ConcreteSlotValueType valueType, GenerationMode generationMode)
{
// check to see if we can inline a value.
List<PreviewProperty> props = new List<PreviewProperty>();
e_targetBlockNode?.CollectPreviewMaterialProperties(props);
// if the cib is inActive, this node still might be in an active branch.
bool isActive = e_targetBlockNode?.isActive ?? false;
// if the cib has no input node, we can use the input property to inline a magic value.
bool canInline = e_targetBlockNode?.GetInputNodeFromSlot(0) == null && props.Count != 0;
// vector width of target slot
int toWidth = SlotTypeToWidth(valueType);
string finalResult = "";
// If cib is inactive (or doesn't exist), then we default to black (as is the case for other nodes).
if (!isActive || CustomInterpolatorUtils.generatorSkipFlag)
{
finalResult = ConvertVector("$precision4(0,0,0,0)", 4, toWidth);
}
// cib has no input; we can directly use the inline value instead.
else if (canInline)
{
Vector4 v = default;
if (props[0].propType != PropertyType.Float)
v = props[0].vector4Value;
int outWidth = 4;
string result;
switch (props[0].propType)
{
case PropertyType.Float:
result = $" $precision1({props[0].floatValue}) ";
outWidth = 1;
break;
default:
result = $" $precision4({v.x},{v.y},{v.z},{v.w}) ";
outWidth = 4;
break;
}
finalResult = ConvertVector(result, outWidth, toWidth);
}
// Preview Node doesn't support CI, but we can fake it by asking the cib's source input for it's value instead.
else if (CustomInterpolatorUtils.generatorNodeOnly)
{
var sourceSlot = FindSourceSlot(out var found);
// CIB's type needs to constrain the incoming value (eg. vec2(out)->float(cib) | float(cin)->vec2(in))
// If we didn't do this next line, we'd get vec2(out)->vec2(in), which would ignore the truncation in the preview.
var result = sourceSlot.node.GetOutputForSlot(sourceSlot, FindSlot<MaterialSlot>(0).concreteValueType, GenerationMode.Preview);
finalResult = ConvertVector(result, (int)e_targetBlockNode.customWidth, toWidth);
}
// If we made it this far, then cib is in a valid and meaningful configuration in the SDI struct.
else
{
// pull directly out of the SDI and just use it.
var result = string.Format("IN.{0}", customBlockNodeName);
finalResult = ConvertVector(result, (int)e_targetBlockNode.customWidth, toWidth);
}
return finalResult.Replace(PrecisionUtil.Token, concretePrecision.ToShaderString());
}
SlotReference FindSourceSlot(out bool found)
{
try
{
found = true;
return owner.GetEdges(e_targetBlockNode).First().outputSlot;
}
catch
{
found = false;
return default;
}
}
private static int SlotTypeToWidth(ConcreteSlotValueType valueType)
{
switch (valueType)
{
case ConcreteSlotValueType.Boolean:
case ConcreteSlotValueType.Vector1: return 1;
case ConcreteSlotValueType.Vector2: return 2;
case ConcreteSlotValueType.Vector3: return 3;
default: return 4;
}
}
private static string ConvertVector(string name, int fromLen, int toLen)
{
if (fromLen == toLen)
return name;
var key = new char[] { 'x', 'y', 'z', 'w' };
string begin = $"$precision{toLen}({name}.";
var mid = "";
string end = ")";
if (toLen == 4)
{
// We assume homogenous coordinates for some reason.
end = ", 1.0)";
toLen -= 1;
}
if (fromLen == 1)
{
// we expand floats for each component for some reason.
fromLen = toLen;
key = new char[] { 'x', 'x', 'x' };
}
// expand the swizzle
int swizzLen = Math.Min(fromLen, toLen);
for (int i = 0; i < swizzLen; ++i)
mid += key[i];
// fill gaps
for (int i = fromLen; i < toLen; ++i)
mid += ", 0.0";
// float<toLen>(<name>.<swizz>, <gap...>, 1.0)"
return $"({begin}{mid}{end})";
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0ccc92de4363bc249858ecefc3a07775
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 5e9138df313dc9e4fa20f92625c26b59
folderAsset: yes
timeCreated: 1495527166
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,36 @@
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Geometry", "Bitangent Vector")]
class BitangentVectorNode : GeometryNode, IMayRequireBitangent
{
public const int kOutputSlotId = 0;
public const string kOutputSlotName = "Out";
public BitangentVectorNode()
{
name = "Bitangent Vector";
synonyms = new string[] { "binormal" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, new Vector4(0, 0, 1)));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
return string.Format("IN.{0}", space.ToVariableName(InterpolatorType.BiTangent));
}
public NeededCoordinateSpace RequiresBitangent(ShaderStageCapability stageCapability)
{
return space.ToNeededCoordinateSpace();
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 25ded6c13e7523d48935f8bd1b9afcb6
timeCreated: 1481041579
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,34 @@
using System.Reflection;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Geometry", "Instance ID")]
class InstanceIDNode : CodeFunctionNode
{
public override bool hasPreview { get { return false; } }
public InstanceIDNode()
{
name = "Instance ID";
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("UnityGetInstanceID", BindingFlags.Static | BindingFlags.NonPublic);
}
static string UnityGetInstanceID([Slot(0, Binding.None)] out Vector1 Out)
{
return
@"
{
#if UNITY_ANY_INSTANCING_ENABLED
Out = unity_InstanceID;
#else
Out = 0;
#endif
}
";
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 215e6221fbd6f9a4bbd14e951c9575d6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,37 @@
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[FormerName("UnityEngine.MaterialGraph.NormalNode")]
[Title("Input", "Geometry", "Normal Vector")]
class NormalVectorNode : GeometryNode, IMayRequireNormal
{
public const int kOutputSlotId = 0;
public const string kOutputSlotName = "Out";
public NormalVectorNode()
{
name = "Normal Vector";
synonyms = new string[] { "surface direction" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, new Vector4(0, 0, 1)));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
return string.Format("IN.{0}", space.ToVariableName(InterpolatorType.Normal));
}
public NeededCoordinateSpace RequiresNormal(ShaderStageCapability stageCapability)
{
return space.ToNeededCoordinateSpace();
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5b34601661908b3499c4c5e2ecd61f75
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,72 @@
using System;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[FormerName("UnityEngine.MaterialGraph.WorldPosNode")]
[Title("Input", "Geometry", "Position")]
class PositionNode : GeometryNode, IMayRequirePosition, IMayRequirePositionPredisplacement
{
public override int latestVersion => 1;
private const int kOutputSlotId = 0;
public const string kOutputSlotName = "Out";
public override List<CoordinateSpace> validSpaces => new List<CoordinateSpace> { CoordinateSpace.Object, CoordinateSpace.View, CoordinateSpace.World, CoordinateSpace.Tangent, CoordinateSpace.AbsoluteWorld };
[SerializeField]
internal PositionSource m_PositionSource = PositionSource.Default;
public PositionNode()
{
name = "Position";
precision = Precision.Single;
synonyms = new string[] { "location" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(
kOutputSlotId,
kOutputSlotName,
kOutputSlotName,
SlotType.Output,
Vector3.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
var name = string.Format("IN.{0}", space.ToVariableName(InterpolatorType.Position));
if (RequiresPositionPredisplacement(ShaderStageCapability.All) != NeededCoordinateSpace.None)
{
name += PositionSource.Predisplacement.ToString();
}
return name;
}
public NeededCoordinateSpace RequiresPosition(ShaderStageCapability stageCapability)
{
return space.ToNeededCoordinateSpace();
}
public NeededCoordinateSpace RequiresPositionPredisplacement(ShaderStageCapability stageCapability = ShaderStageCapability.All)
{
return m_PositionSource == PositionSource.Predisplacement ? space.ToNeededCoordinateSpace() : NeededCoordinateSpace.None;
}
public override void OnAfterMultiDeserialize(string json)
{
base.OnAfterMultiDeserialize(json);
//required update
if (sgVersion < 1)
{
ChangeVersion(1);
}
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 137f6921c5ee7ca4dbffb34de10f52f5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,54 @@
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Geometry", "Screen Position")]
class ScreenPositionNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireScreenPosition
{
public ScreenPositionNode()
{
name = "Screen Position";
UpdateNodeAfterDeserialization();
}
[SerializeField]
private ScreenSpaceType m_ScreenSpaceType = ScreenSpaceType.Default;
[EnumControl("Mode")]
public ScreenSpaceType screenSpaceType
{
get { return m_ScreenSpaceType; }
set
{
if (m_ScreenSpaceType == value)
return;
m_ScreenSpaceType = value;
Dirty(ModificationScope.Graph);
}
}
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Out";
public override bool hasPreview { get { return true; } }
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
sb.AppendLine(string.Format("$precision4 {0} = {1};", GetVariableNameForSlot(kOutputSlotId), m_ScreenSpaceType.ToValueAsVariable()));
}
public bool RequiresScreenPosition(ShaderStageCapability stageCapability)
{
return true;
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e204c7999bfa0ee42a18d8a560a36244
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,35 @@
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Geometry", "Tangent Vector")]
class TangentVectorNode : GeometryNode, IMayRequireTangent
{
public const int kOutputSlotId = 0;
public const string kOutputSlotName = "Out";
public TangentVectorNode()
{
name = "Tangent Vector";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, new Vector4(0, 0, 1, 1)));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
return string.Format("IN.{0}", space.ToVariableName(InterpolatorType.Tangent));
}
public NeededCoordinateSpace RequiresTangent(ShaderStageCapability stageCapability)
{
return space.ToNeededCoordinateSpace();
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 9e8bd6ff1eba8ea4589ec534a00f4767
timeCreated: 1480080968
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,56 @@
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Geometry", "UV")]
class UVNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
{
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
[SerializeField]
private UVChannel m_OutputChannel;
[EnumControl("Channel")]
public UVChannel uvChannel
{
get { return m_OutputChannel; }
set
{
if (m_OutputChannel == value)
return;
m_OutputChannel = value;
Dirty(ModificationScope.Graph);
}
}
public override bool hasPreview { get { return true; } }
public UVNode()
{
name = "UV";
synonyms = new string[] { "texcoords", "coords", "coordinates" };
UpdateNodeAfterDeserialization();
}
public override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector2.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
sb.AppendLine(string.Format("$precision4 {0} = IN.{1};", GetVariableNameForSlot(OutputSlotId), m_OutputChannel.GetUVName()));
}
public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability)
{
return channel == uvChannel;
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 1c05002dbfc8cd14cb3b544630cf1017
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,37 @@
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Geometry", "Vertex Color")]
class VertexColorNode : AbstractMaterialNode, IMayRequireVertexColor
{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Out";
public override bool hasPreview { get { return true; } }
public VertexColorNode()
{
name = "Vertex Color";
m_PreviewMode = PreviewMode.Preview3D;
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.one));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
return string.Format("IN.{0}", ShaderGeneratorNames.VertexColor);
}
public bool RequiresVertexColor(ShaderStageCapability stageCapability)
{
return true;
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 923cdcd772822d84b9d79807e27d502b
timeCreated: 1481123160
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,36 @@
using UnityEngine;
using UnityEditor.Graphing;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Geometry", "Vertex ID")]
class VertexIDNode : AbstractMaterialNode, IMayRequireVertexID
{
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Out";
public override bool hasPreview { get { return false; } }
public VertexIDNode()
{
name = "Vertex ID";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, (int)0, ShaderStageCapability.Vertex));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
return string.Format("IN.{0}", ShaderGeneratorNames.VertexID);
}
public bool RequiresVertexID(ShaderStageCapability stageCapability)
{
return true;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8cc9905543f080945b4250dfa558e604
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,76 @@
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
using System.Collections.Generic;
namespace UnityEditor.ShaderGraph
{
[FormerName("UnityEngine.MaterialGraph.ViewDirectionNode")]
[Title("Input", "Geometry", "View Direction")]
class ViewDirectionNode : GeometryNode, IMayRequireViewDirection, IHasCustomDeprecationMessage
{
private const int kOutputSlotId = 0;
public const string kOutputSlotName = "Out";
public override int latestVersion => 1;
public override IEnumerable<int> allowedNodeVersions => new int[] { 1 };
public ViewDirectionNode()
{
name = "View Direction";
synonyms = new string[] { "eye direction" };
UpdateNodeAfterDeserialization();
onAfterVersionChange += () => { if (sgVersion > 0) owner.ClearErrorsForNode(this); };
}
public override void ValidateNode()
{
base.ValidateNode();
if (sgVersion == 0)
{
owner.AddValidationError(objectId, "Node behavior was changed. See inspector for details", Rendering.ShaderCompilerMessageSeverity.Warning);
}
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(
kOutputSlotId,
kOutputSlotName,
kOutputSlotName,
SlotType.Output,
Vector4.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
return string.Format("IN.{0}", space.ToVariableName(InterpolatorType.ViewDirection));
}
public NeededCoordinateSpace RequiresViewDirection(ShaderStageCapability stageCapability)
{
return space.ToNeededCoordinateSpace();
}
public void GetCustomDeprecationMessage(out string deprecationString, out string buttonText, out string labelText, out MessageType messageType)
{
deprecationString = null;
buttonText = null;
labelText = null;
messageType = MessageType.Warning;
if (sgVersion == 0)
{
deprecationString = "The View Direction node has changed behavior in 2021.2. Please see documentation for more info.";
buttonText = "Dismiss";
labelText = "UPDATED: Hover for info";
messageType = MessageType.Info;
}
}
public string GetCustomDeprecationLabel()
{
return name;
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 30cf94a5e32cd254eb6eadf45e5cdfe3
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,151 @@
using System;
using System.Text.RegularExpressions;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.ShaderGraph.Internal;
using System.Reflection;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Geometry", "View Vector")]
class ViewVectorNode : CodeFunctionNode
{
public ViewVectorNode()
{
name = "View Vector";
synonyms = new string[] { "eye vector" };
}
public virtual List<CoordinateSpace> validSpaces => new List<CoordinateSpace> { CoordinateSpace.Object, CoordinateSpace.View, CoordinateSpace.World, CoordinateSpace.Tangent };
[SerializeField]
private CoordinateSpace m_Space = CoordinateSpace.World;
[PopupControl("Space")]
public PopupList spacePopup
{
get
{
var names = validSpaces.Select(cs => cs.ToString().PascalToLabel()).ToArray();
return new PopupList(names, (int)m_Space);
}
set
{
if (m_Space == (CoordinateSpace)value.selectedEntry)
return;
m_Space = (CoordinateSpace)value.selectedEntry;
UpdateNodeAfterDeserialization();
Dirty(ModificationScope.Topological);
}
}
public CoordinateSpace space => m_Space;
public override bool hasPreview
{
get { return true; }
}
public override PreviewMode previewMode
{
get { return PreviewMode.Preview3D; }
}
protected override MethodInfo GetFunctionToConvert()
{
switch (space)
{
case CoordinateSpace.Object:
return GetType().GetMethod("Unity_ViewVectorObject", BindingFlags.Static | BindingFlags.NonPublic);
case CoordinateSpace.View:
return GetType().GetMethod("Unity_ViewVectorView", BindingFlags.Static | BindingFlags.NonPublic);
case CoordinateSpace.World:
return GetType().GetMethod("Unity_ViewVectorWorld", BindingFlags.Static | BindingFlags.NonPublic);
case CoordinateSpace.Tangent:
return GetType().GetMethod("Unity_ViewVectorTangent", BindingFlags.Static | BindingFlags.NonPublic);
default:
throw new Exception();
}
}
static string Unity_ViewVectorObject(
[Slot(3, Binding.WorldSpacePosition, true, ShaderStageCapability.All)] Vector3 WorldSpacePosition,
[Slot(0, Binding.None)] out Vector3 Out)
{
Out = new Vector3();
return
@"
{
Out = _WorldSpaceCameraPos.xyz - GetAbsolutePositionWS(WorldSpacePosition);
if(!IsPerspectiveProjection())
{
Out = GetViewForwardDir() * dot(Out, GetViewForwardDir());
}
Out = TransformWorldToObjectDir(Out, false);
}
";
}
static string Unity_ViewVectorView(
[Slot(2, Binding.ViewSpacePosition, true, ShaderStageCapability.All)] Vector3 ViewSpacePosition,
[Slot(0, Binding.None)] out Vector3 Out)
{
Out = new Vector3();
return
@"
{
if(IsPerspectiveProjection())
{
Out = -ViewSpacePosition;
}
else
{
Out = -$precision3(0.0f, 0.0f, ViewSpacePosition.z);
}
}
";
}
static string Unity_ViewVectorWorld(
[Slot(3, Binding.WorldSpacePosition, true, ShaderStageCapability.All)] Vector3 WorldSpacePosition,
[Slot(0, Binding.None)] out Vector3 Out)
{
Out = new Vector3();
return
@"
{
Out = _WorldSpaceCameraPos.xyz - GetAbsolutePositionWS(WorldSpacePosition);
if(!IsPerspectiveProjection())
{
Out = GetViewForwardDir() * dot(Out, GetViewForwardDir());
}
}
";
}
static string Unity_ViewVectorTangent(
[Slot(3, Binding.WorldSpacePosition, true, ShaderStageCapability.All)] Vector3 WorldSpacePosition,
[Slot(4, Binding.WorldSpaceTangent, true, ShaderStageCapability.All)] Vector3 WorldSpaceTangent,
[Slot(5, Binding.WorldSpaceBitangent, true, ShaderStageCapability.All)] Vector3 WorldSpaceBitangent,
[Slot(6, Binding.WorldSpaceNormal, true, ShaderStageCapability.All)] Vector3 WorldSpaceNormal,
[Slot(0, Binding.None)] out Vector3 Out)
{
Out = new Vector3();
return
@"
{
$precision3x3 basisTransform = $precision3x3(WorldSpaceTangent, WorldSpaceBitangent, WorldSpaceNormal);
Out = _WorldSpaceCameraPos.xyz - GetAbsolutePositionWS(WorldSpacePosition);
if(!IsPerspectiveProjection())
{
Out = GetViewForwardDir() * dot(Out, GetViewForwardDir());
}
Out = length(Out) * TransformWorldToTangent(Out, basisTransform);
}
";
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7b36a91e8a7cf304b81905da7b233f23
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6c3178830acf943f8bf39e5a651057f2
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,45 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Gradient", "Blackbody")]
class BlackbodyNode : CodeFunctionNode
{
public BlackbodyNode()
{
name = "Blackbody";
}
public override bool hasPreview
{
get { return true; }
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Blackbody", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Blackbody(
[Slot(0, Binding.None, 512.0f, 512.0f, 512.0f, 512.0f)] Vector1 Temperature,
[Slot(1, Binding.None)] out Vector3 Out)
{
Out = Vector3.zero;
return
@"
{
//based on data by Mitchell Charity http://www.vendian.org/mncharity/dir3/blackbody/
$precision3 color = $precision3(255.0, 255.0, 255.0);
color.x = 56100000. * pow(Temperature,(-3.0 / 2.0)) + 148.0;
color.y = 100.04 * log(Temperature) - 623.6;
if (Temperature > 6500.0) color.y = 35200000.0 * pow(Temperature,(-3.0 / 2.0)) + 184.0;
color.z = 194.18 * log(Temperature) - 1448.6;
color = clamp(color, 0.0, 255.0)/255.0;
if (Temperature < 1000.0) color *= Temperature/1000.0;
Out = color;
}
";
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4dc57a132d2b8f346b104de7154e28a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,139 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Gradient", "Gradient")]
class GradientNode : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
[SerializeField]
private float m_Value;
public const int OutputSlotId = 0;
private const string kOutputSlotName = "Out";
public GradientNode()
{
name = "Gradient";
synonyms = new string[] { "ramp" };
UpdateNodeAfterDeserialization();
}
string GetFunctionName()
{
return string.Format("Unity_{0}", GetVariableNameForNode());
}
Gradient m_Gradient = new Gradient();
[SerializeField]
Vector4[] m_SerializableColorKeys = { new Vector4(1f, 1f, 1f, 0f), new Vector4(0f, 0f, 0f, 1f), };
[SerializeField]
Vector2[] m_SerializableAlphaKeys = { new Vector2(1f, 0f), new Vector2(1f, 1f) };
[SerializeField]
int m_SerializableMode = 0;
[GradientControl("")]
public Gradient gradient
{
get
{
if (m_SerializableAlphaKeys != null && m_SerializableColorKeys != null)
{
m_Gradient = new Gradient();
var colorKeys = m_SerializableColorKeys.Select(k => new GradientColorKey(new Color(k.x, k.y, k.z, 1f), k.w)).ToArray();
var alphaKeys = m_SerializableAlphaKeys.Select(k => new GradientAlphaKey(k.x, k.y)).ToArray();
m_SerializableAlphaKeys = null;
m_SerializableColorKeys = null;
m_Gradient.SetKeys(colorKeys, alphaKeys);
m_Gradient.mode = (GradientMode)m_SerializableMode;
}
return m_Gradient;
}
set
{
var scope = ModificationScope.Nothing;
if (!GradientUtil.CheckEquivalency(gradient, value))
scope = scope < ModificationScope.Graph ? ModificationScope.Graph : scope;
if (scope > ModificationScope.Nothing)
{
var newColorKeys = value.colorKeys;
var newAlphaKeys = value.alphaKeys;
m_Gradient.SetKeys(newColorKeys, newAlphaKeys);
m_Gradient.mode = value.mode;
Dirty(ModificationScope.Node);
}
}
}
public override void OnBeforeSerialize()
{
base.OnBeforeSerialize();
if (m_Gradient != null)
{
m_SerializableColorKeys = m_Gradient.colorKeys.Select(k => new Vector4(k.color.r, k.color.g, k.color.b, k.time)).ToArray();
m_SerializableAlphaKeys = m_Gradient.alphaKeys.Select(k => new Vector2(k.alpha, k.time)).ToArray();
m_SerializableMode = (int)m_Gradient.mode;
}
}
public override bool hasPreview { get { return false; } }
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new GradientMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (generationMode.IsPreview())
{
sb.AppendLine("Gradient {0} = {1};", GetVariableNameForSlot(outputSlotId), GradientUtil.GetGradientForPreview(GetVariableNameForNode()));
}
else
{
sb.AppendLine("Gradient {0} = {1}", GetVariableNameForSlot(outputSlotId), GradientUtil.GetGradientValue(gradient, ";"));
}
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
properties.Add(new PreviewProperty(PropertyType.Gradient)
{
name = GetVariableNameForNode(),
gradientValue = gradient
});
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
base.CollectShaderProperties(properties, generationMode);
GradientUtil.GetGradientPropertiesForPreview(properties, GetVariableNameForNode(), gradient);
}
public AbstractShaderProperty AsShaderProperty()
{
return new GradientShaderProperty { value = gradient };
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 74a7bf7b417cd4fe4be8985888ddffae
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,94 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Gradient", "Sample Gradient")]
class SampleGradient : CodeFunctionNode
{
public override int latestVersion => 1;
public SampleGradient()
{
name = "Sample Gradient";
}
public override bool hasPreview
{
get { return true; }
}
protected override MethodInfo GetFunctionToConvert()
{
switch (sgVersion)
{
case 0:
return GetType().GetMethod("Unity_SampleGradientV0", BindingFlags.Static | BindingFlags.NonPublic);
case 1:
default:
return GetType().GetMethod("Unity_SampleGradientV1", BindingFlags.Static | BindingFlags.NonPublic);
}
}
static string Unity_SampleGradientV0(
[Slot(0, Binding.None)] Gradient Gradient,
[Slot(1, Binding.None)] Vector1 Time,
[Slot(2, Binding.None)] out Vector4 Out)
{
Out = Vector4.zero;
return
@"
{
$precision3 color = Gradient.colors[0].rgb;
[unroll]
for (int c = 1; c < Gradient.colorsLength; c++)
{
$precision colorPos = saturate((Time - Gradient.colors[c - 1].w) / (Gradient.colors[c].w - Gradient.colors[c - 1].w)) * step(c, Gradient.colorsLength - 1);
color = lerp(color, Gradient.colors[c].rgb, lerp(colorPos, step(0.01, colorPos), Gradient.type));
}
#ifndef UNITY_COLORSPACE_GAMMA
color = SRGBToLinear(color);
#endif
$precision alpha = Gradient.alphas[0].x;
[unroll]
for (int a = 1; a < Gradient.alphasLength; a++)
{
$precision alphaPos = saturate((Time - Gradient.alphas[a - 1].y) / (Gradient.alphas[a].y - Gradient.alphas[a - 1].y)) * step(a, Gradient.alphasLength - 1);
alpha = lerp(alpha, Gradient.alphas[a].x, lerp(alphaPos, step(0.01, alphaPos), Gradient.type));
}
Out = $precision4(color, alpha);
}
";
}
static string Unity_SampleGradientV1(
[Slot(0, Binding.None)] Gradient Gradient,
[Slot(1, Binding.None)] Vector1 Time,
[Slot(2, Binding.None)] out Vector4 Out)
{
Out = Vector4.zero;
return
@"
{
$precision3 color = Gradient.colors[0].rgb;
[unroll]
for (int c = 1; c < Gradient.colorsLength; c++)
{
$precision colorPos = saturate((Time - Gradient.colors[c - 1].w) / (Gradient.colors[c].w - Gradient.colors[c - 1].w)) * step(c, Gradient.colorsLength - 1);
color = lerp(color, Gradient.colors[c].rgb, lerp(colorPos, step(0.01, colorPos), Gradient.type));
}
#ifdef UNITY_COLORSPACE_GAMMA
color = LinearToSRGB(color);
#endif
$precision alpha = Gradient.alphas[0].x;
[unroll]
for (int a = 1; a < Gradient.alphasLength; a++)
{
$precision alphaPos = saturate((Time - Gradient.alphas[a - 1].y) / (Gradient.alphas[a].y - Gradient.alphas[a - 1].y)) * step(a, Gradient.alphasLength - 1);
alpha = lerp(alpha, Gradient.alphas[a].x, lerp(alphaPos, step(0.01, alphaPos), Gradient.type));
}
Out = $precision4(color, alpha);
}
";
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5b12835ccaa954dc3ad06e9958e1e740
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 401863ee77eb66240b3581283427644d
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,46 @@
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Lighting", "Ambient")]
class AmbientNode : AbstractMaterialNode
{
const string kOutputSlotName = "Color/Sky";
const string kOutputSlot1Name = "Equator";
const string kOutputSlot2Name = "Ground";
public const int OutputSlotId = 0;
public const int OutputSlot1Id = 1;
public const int OutputSlot2Id = 2;
public AmbientNode()
{
name = "Ambient";
synonyms = new string[] { "scene color" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new ColorRGBMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero, ColorMode.Default));
AddSlot(new ColorRGBMaterialSlot(OutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, Vector4.zero, ColorMode.Default));
AddSlot(new ColorRGBMaterialSlot(OutputSlot2Id, kOutputSlot2Name, kOutputSlot2Name, SlotType.Output, Vector4.zero, ColorMode.Default));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, OutputSlot1Id, OutputSlot2Id });
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlot1Id:
return "SHADERGRAPH_AMBIENT_EQUATOR";
case OutputSlot2Id:
return "SHADERGRAPH_AMBIENT_GROUND";
default:
return "SHADERGRAPH_AMBIENT_SKY";
}
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 0f9e9a126b4ecf24d81258763ac4a64d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,77 @@
using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[FormerName("UnityEditor.ShaderGraph.BakedGAbstractMaterialNode")]
[FormerName("UnityEditor.ShaderGraph.LightProbeNode")]
[Title("Input", "Lighting", "Baked GI")]
class BakedGINode : CodeFunctionNode
{
public override bool hasPreview { get { return false; } }
public BakedGINode()
{
name = "Baked GI";
synonyms = new string[] { "global illumination" };
}
protected override MethodInfo GetFunctionToConvert()
{
if (applyScaling.isOn)
return GetType().GetMethod("Unity_BakedGIScale", BindingFlags.Static | BindingFlags.NonPublic);
else
return GetType().GetMethod("Unity_BakedGI", BindingFlags.Static | BindingFlags.NonPublic);
}
[SerializeField]
private bool m_ApplyScaling = true;
[ToggleControl("Apply Lightmap Scaling")]
public ToggleData applyScaling
{
get { return new ToggleData(m_ApplyScaling); }
set
{
if (m_ApplyScaling == value.isOn)
return;
m_ApplyScaling = value.isOn;
Dirty(ModificationScope.Node);
}
}
static string Unity_BakedGI(
[Slot(2, Binding.WorldSpacePosition)] Vector3 Position,
[Slot(0, Binding.WorldSpaceNormal)] Vector3 Normal,
[Slot(3, Binding.MeshUV1)] Vector2 StaticUV,
[Slot(4, Binding.MeshUV2)] Vector2 DynamicUV,
[Slot(1, Binding.None)] out Vector3 Out)
{
Out = Vector3.one;
return
@"
{
Out = SHADERGRAPH_BAKED_GI(Position, Normal, StaticUV, DynamicUV, false);
}
";
}
static string Unity_BakedGIScale(
[Slot(2, Binding.WorldSpacePosition)] Vector3 Position,
[Slot(0, Binding.WorldSpaceNormal)] Vector3 Normal,
[Slot(3, Binding.MeshUV1)] Vector2 StaticUV,
[Slot(4, Binding.MeshUV2)] Vector2 DynamicUV,
[Slot(1, Binding.None)] out Vector3 Out)
{
Out = Vector3.one;
return
@"
{
Out = SHADERGRAPH_BAKED_GI(Position, Normal, StaticUV, DynamicUV, true);
}
";
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 5f77cdea8b1204b12bb03da3dd3bd3b6
timeCreated: 1495482070
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,37 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Lighting", "Reflection Probe")]
class ReflectionProbeNode : CodeFunctionNode
{
public ReflectionProbeNode()
{
name = "Reflection Probe";
synonyms = new string[] { "light probe", "cube map", "environment" };
}
public override bool hasPreview { get { return false; } }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_ReflectionProbe", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_ReflectionProbe(
[Slot(0, Binding.ObjectSpaceViewDirection)] Vector3 ViewDir,
[Slot(1, Binding.ObjectSpaceNormal)] Vector3 Normal,
[Slot(2, Binding.None)] Vector1 LOD,
[Slot(3, Binding.None)] out Vector3 Out)
{
Out = Vector3.one;
return
@"
{
Out = SHADERGRAPH_REFLECTION_PROBE(ViewDir, Normal, LOD);
}
";
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fb8845c10261f47d0a719ac80481e667
timeCreated: 1495482070
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 278936628273864438e48ff64aa20e32
folderAsset: yes
timeCreated: 1495662409
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,137 @@
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Matrix", "Matrix 2x2")]
class Matrix2Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
public const int OutputSlotId = 0;
const string kOutputSlotName = "Out";
[SerializeField]
Vector2 m_Row0;
[SerializeField]
Vector2 m_Row1;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector2 row0
{
get { return m_Row0; }
set { SetRow(ref m_Row0, value); }
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector2 row1
{
get { return m_Row1; }
set { SetRow(ref m_Row1, value); }
}
void SetRow(ref Vector2 row, Vector2 value)
{
if (value == row)
return;
row = value;
Dirty(ModificationScope.Node);
}
public Matrix2Node()
{
name = "Matrix 2x2";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Matrix2MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new Vector2ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m0", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row0
});
properties.AddShaderProperty(new Vector2ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m1", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row1
});
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
{
sb.AppendLine("$precision2 _{0}_m0 = $precision2 ({1}, {2});", GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row0.x),
NodeUtils.FloatToShaderValue(m_Row0.y));
sb.AppendLine("$precision2 _{0}_m1 = $precision2 ({1}, {2});", GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row1.x),
NodeUtils.FloatToShaderValue(m_Row1.y));
}
sb.AppendLine("$precision2x2 {0} = $precision2x2 (_{0}_m0.x, _{0}_m0.y, _{0}_m1.x, _{0}_m1.y);", GetVariableNameForNode());
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Vector2)
{
name = string.Format("_{0}_m0", GetVariableNameForNode()),
vector4Value = m_Row0
});
properties.Add(new PreviewProperty(PropertyType.Vector2)
{
name = string.Format("_{0}_m1", GetVariableNameForNode()),
vector4Value = m_Row1
});
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public AbstractShaderProperty AsShaderProperty()
{
return new Matrix2ShaderProperty
{
value = new Matrix4x4()
{
m00 = row0.x,
m01 = row0.y,
m02 = 0,
m03 = 0,
m10 = row1.x,
m11 = row1.y,
m12 = 0,
m13 = 0,
m20 = 0,
m21 = 0,
m22 = 0,
m23 = 0,
m30 = 0,
m31 = 0,
m32 = 0,
m33 = 0,
}
};
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: a01da6bf9ffa118478ae371b28d2e166
timeCreated: 1446473341
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,166 @@
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Matrix", "Matrix 3x3")]
class Matrix3Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
public const int OutputSlotId = 0;
const string kOutputSlotName = "Out";
[SerializeField]
Vector3 m_Row0;
[SerializeField]
Vector3 m_Row1;
[SerializeField]
Vector3 m_Row2;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector3 row0
{
get { return m_Row0; }
set { SetRow(ref m_Row0, value); }
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector3 row1
{
get { return m_Row1; }
set { SetRow(ref m_Row1, value); }
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector3 row2
{
get { return m_Row2; }
set { SetRow(ref m_Row2, value); }
}
void SetRow(ref Vector3 row, Vector3 value)
{
if (value == row)
return;
row = value;
Dirty(ModificationScope.Node);
}
public Matrix3Node()
{
name = "Matrix 3x3";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Matrix3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new Vector3ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m0", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row0
});
properties.AddShaderProperty(new Vector3ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m1", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row1
});
properties.AddShaderProperty(new Vector3ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m2", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row2
});
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
{
sb.AppendLine("$precision3 _{0}_m0 = $precision3 ({1}, {2}, {3});", GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row0.x),
NodeUtils.FloatToShaderValue(m_Row0.y),
NodeUtils.FloatToShaderValue(m_Row0.z));
sb.AppendLine("$precision3 _{0}_m1 = $precision3 ({1}, {2}, {3});", GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row1.x),
NodeUtils.FloatToShaderValue(m_Row1.y),
NodeUtils.FloatToShaderValue(m_Row1.z));
sb.AppendLine("$precision3 _{0}_m2 = $precision3 ({1}, {2}, {3});", GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row2.x),
NodeUtils.FloatToShaderValue(m_Row2.y),
NodeUtils.FloatToShaderValue(m_Row2.z));
}
sb.AppendLine("$precision3x3 {0} = $precision3x3 (_{0}_m0.x, _{0}_m0.y, _{0}_m0.z, _{0}_m1.x, _{0}_m1.y, _{0}_m1.z, _{0}_m2.x, _{0}_m2.y, _{0}_m2.z);", GetVariableNameForNode());
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Vector3)
{
name = string.Format("_{0}_m0", GetVariableNameForNode()),
vector4Value = m_Row0
});
properties.Add(new PreviewProperty(PropertyType.Vector3)
{
name = string.Format("_{0}_m1", GetVariableNameForNode()),
vector4Value = m_Row1
});
properties.Add(new PreviewProperty(PropertyType.Vector3)
{
name = string.Format("_{0}_m2", GetVariableNameForNode()),
vector4Value = m_Row2
});
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public AbstractShaderProperty AsShaderProperty()
{
return new Matrix3ShaderProperty
{
value = new Matrix4x4()
{
m00 = row0.x,
m01 = row0.y,
m02 = row0.z,
m03 = 0,
m10 = row1.x,
m11 = row1.y,
m12 = row1.z,
m13 = 0,
m20 = row2.x,
m21 = row2.y,
m22 = row2.z,
m23 = 0,
m30 = 0,
m31 = 0,
m32 = 0,
m33 = 0,
}
};
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: fec4ad06a8bd71044af822b7d2258a69
timeCreated: 1446473341
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,198 @@
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Matrix", "Matrix 4x4")]
class Matrix4Node : AbstractMaterialNode, IGeneratesBodyCode, IPropertyFromNode
{
public const int OutputSlotId = 0;
const string kOutputSlotName = "Out";
[SerializeField]
Vector4 m_Row0;
[SerializeField]
Vector4 m_Row1;
[SerializeField]
Vector4 m_Row2;
[SerializeField]
Vector4 m_Row3;
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row0
{
get { return m_Row0; }
set { SetRow(ref m_Row0, value); }
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row1
{
get { return m_Row1; }
set { SetRow(ref m_Row1, value); }
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row2
{
get { return m_Row2; }
set { SetRow(ref m_Row2, value); }
}
[MultiFloatControl("", " ", " ", " ", " ")]
public Vector4 row3
{
get { return m_Row3; }
set { SetRow(ref m_Row3, value); }
}
void SetRow(ref Vector4 row, Vector4 value)
{
if (value == row)
return;
row = value;
Dirty(ModificationScope.Node);
}
public Matrix4Node()
{
name = "Matrix 4x4";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Matrix4MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m0", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row0
});
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m1", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row1
});
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m2", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row2
});
properties.AddShaderProperty(new Vector4ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_m3", GetVariableNameForNode()),
generatePropertyBlock = false,
value = m_Row3
});
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
{
sb.AppendLine("$precision4 _{0}_m0 = $precision4 ({1}, {2}, {3}, {4});", GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row0.x),
NodeUtils.FloatToShaderValue(m_Row0.y),
NodeUtils.FloatToShaderValue(m_Row0.z),
NodeUtils.FloatToShaderValue(m_Row0.w));
sb.AppendLine("$precision4 _{0}_m1 = $precision4 ({1}, {2}, {3}, {4});", GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row1.x),
NodeUtils.FloatToShaderValue(m_Row1.y),
NodeUtils.FloatToShaderValue(m_Row1.z),
NodeUtils.FloatToShaderValue(m_Row1.w));
sb.AppendLine("$precision4 _{0}_m2 = $precision4 ({1}, {2}, {3}, {4});", GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row2.x),
NodeUtils.FloatToShaderValue(m_Row2.y),
NodeUtils.FloatToShaderValue(m_Row2.z),
NodeUtils.FloatToShaderValue(m_Row2.w));
sb.AppendLine("$precision4 _{0}_m3 = $precision4 ({1}, {2}, {3}, {4});", GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Row3.x),
NodeUtils.FloatToShaderValue(m_Row3.y),
NodeUtils.FloatToShaderValue(m_Row3.z),
NodeUtils.FloatToShaderValue(m_Row3.w));
}
sb.AppendLine("$precision4x4 {0} = $precision4x4 (_{0}_m0.x, _{0}_m0.y, _{0}_m0.z, _{0}_m0.w, _{0}_m1.x, _{0}_m1.y, _{0}_m1.z, _{0}_m1.w, _{0}_m2.x, _{0}_m2.y, _{0}_m2.z, _{0}_m2.w, _{0}_m3.x, _{0}_m3.y, _{0}_m3.z, _{0}_m3.w);",
GetVariableNameForNode());
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_m0", GetVariableNameForNode()),
vector4Value = m_Row0
});
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_m1", GetVariableNameForNode()),
vector4Value = m_Row1
});
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_m2", GetVariableNameForNode()),
vector4Value = m_Row2
});
properties.Add(new PreviewProperty(PropertyType.Vector4)
{
name = string.Format("_{0}_m3", GetVariableNameForNode()),
vector4Value = m_Row3
});
}
public override string GetVariableNameForSlot(int slotId)
{
return GetVariableNameForNode();
}
public AbstractShaderProperty AsShaderProperty()
{
return new Matrix4ShaderProperty
{
value = new Matrix4x4()
{
m00 = row0.x,
m01 = row0.y,
m02 = row0.z,
m03 = row0.w,
m10 = row1.x,
m11 = row1.y,
m12 = row1.z,
m13 = row1.w,
m20 = row2.x,
m21 = row2.y,
m22 = row2.z,
m23 = row2.w,
m30 = row3.x,
m31 = row3.y,
m32 = row3.z,
m33 = row3.w,
}
};
}
public int outputSlotId { get { return OutputSlotId; } }
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: d3889ae2c6ffabd40a2ee45f5b051d3b
timeCreated: 1446473341
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,119 @@
using UnityEditor.Graphing;
using System.Collections.Generic;
using System.Globalization;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
enum TransformationMatrixType
{
None = -1,
ModelView,
View,
Projection,
ViewProjection,
TransposeModelView,
InverseTransposeModelView,
ObjectToWorld,
WorldToObject
};
internal enum UnityMatrixType
{
Model,
InverseModel,
View,
InverseView,
Projection,
InverseProjection,
ViewProjection,
InverseViewProjection
}
[Title("Input", "Matrix", "Transformation Matrix")]
class TransformationMatrixNode : AbstractMaterialNode, IMayRequireTransform
{
static Dictionary<UnityMatrixType, string> m_MatrixList = new Dictionary<UnityMatrixType, string>
{
{UnityMatrixType.Model, "UNITY_MATRIX_M"},
{UnityMatrixType.InverseModel, "UNITY_MATRIX_I_M"},
{UnityMatrixType.View, "UNITY_MATRIX_V"},
{UnityMatrixType.InverseView, "UNITY_MATRIX_I_V"},
{UnityMatrixType.Projection, "UNITY_MATRIX_P"},
{UnityMatrixType.InverseProjection, "UNITY_MATRIX_I_P"},
{UnityMatrixType.ViewProjection, "UNITY_MATRIX_VP"},
{UnityMatrixType.InverseViewProjection, "UNITY_MATRIX_I_VP"},
};
static Dictionary<TransformationMatrixType, UnityMatrixType> m_MatrixUpgrade = new Dictionary<TransformationMatrixType, UnityMatrixType>
{
{TransformationMatrixType.ModelView, UnityMatrixType.Model},
{TransformationMatrixType.View, UnityMatrixType.View},
{TransformationMatrixType.Projection, UnityMatrixType.Projection},
{TransformationMatrixType.ViewProjection, UnityMatrixType.ViewProjection},
{TransformationMatrixType.TransposeModelView, UnityMatrixType.Model},
{TransformationMatrixType.InverseTransposeModelView, UnityMatrixType.Model},
{TransformationMatrixType.ObjectToWorld, UnityMatrixType.Model},
{TransformationMatrixType.WorldToObject, UnityMatrixType.InverseModel},
};
[SerializeField]
private TransformationMatrixType m_matrix = TransformationMatrixType.ModelView;
[SerializeField]
private UnityMatrixType m_MatrixType = UnityMatrixType.Model;
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Out";
public override bool hasPreview { get { return false; } }
[EnumControl("")]
public UnityMatrixType matrixType
{
get { return m_MatrixType; }
set
{
if (m_MatrixType == value)
return;
m_MatrixType = value;
Dirty(ModificationScope.Graph);
}
}
public TransformationMatrixNode()
{
name = "Transformation Matrix";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
if (m_matrix != TransformationMatrixType.None)
{
m_MatrixType = m_MatrixUpgrade[m_matrix];
m_matrix = TransformationMatrixType.None;
}
AddSlot(new Matrix4MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public override string GetVariableNameForSlot(int slotId)
{
return m_MatrixList[matrixType].ToString(CultureInfo.InvariantCulture);
}
public bool RequiresVertexColor()
{
return true;
}
public NeededTransform[] RequiresTransform(ShaderStageCapability stageCapability = ShaderStageCapability.All)
{
return new[] { new NeededTransform(matrixType) };
}
}
}

View file

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 080829bc2938e23489292a936367364d
timeCreated: 1481123160
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bc2d9fef9660c574dad26112f3061731
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,162 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEditor.ShaderGraph.Internal;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
enum DielectricMaterialType
{
Common,
RustedMetal,
Water,
Ice,
Glass,
Custom
};
[Title("Input", "PBR", "Dielectric Specular")]
class DielectricSpecularNode : AbstractMaterialNode, IGeneratesBodyCode
{
public DielectricSpecularNode()
{
name = "Dielectric Specular";
synonyms = new string[] { "reflectance" };
UpdateNodeAfterDeserialization();
}
[SerializeField]
DielectricMaterial m_Material = new DielectricMaterial(DielectricMaterialType.Common, 0.5f, 1.0f);
[Serializable]
public struct DielectricMaterial
{
public DielectricMaterialType type;
public float range;
public float indexOfRefraction;
public DielectricMaterial(DielectricMaterialType type, float range, float indexOfRefraction)
{
this.type = type;
this.range = range;
this.indexOfRefraction = indexOfRefraction;
}
}
[DielectricSpecularControl()]
public DielectricMaterial material
{
get { return m_Material; }
set
{
if ((value.type == m_Material.type) && (value.range == m_Material.range) && (value.indexOfRefraction == m_Material.indexOfRefraction))
return;
DielectricMaterialType previousType = m_Material.type;
m_Material = value;
if (value.type != previousType)
Dirty(ModificationScope.Graph);
else
Dirty(ModificationScope.Node);
}
}
static Dictionary<DielectricMaterialType, string> m_MaterialList = new Dictionary<DielectricMaterialType, string>
{
{DielectricMaterialType.RustedMetal, "0.030"},
{DielectricMaterialType.Water, "0.020"},
{DielectricMaterialType.Ice, "0.018"},
{DielectricMaterialType.Glass, "0.040"}
};
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Out";
public override bool hasPreview { get { return true; } }
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
{
switch (material.type)
{
case DielectricMaterialType.Custom:
sb.AppendLine("$precision _{0}_IOR = {1};", GetVariableNameForNode(), material.indexOfRefraction);
break;
case DielectricMaterialType.Common:
sb.AppendLine("$precision _{0}_Range = {1};", GetVariableNameForNode(), material.range);
break;
default:
break;
}
}
switch (material.type)
{
case DielectricMaterialType.Common:
sb.AppendLine("$precision {0} = lerp(0.034, 0.048, _{1}_Range);", GetVariableNameForSlot(kOutputSlotId), GetVariableNameForNode());
break;
case DielectricMaterialType.Custom:
sb.AppendLine("$precision {0} = pow(_{1}_IOR - 1, 2) / pow(_{1}_IOR + 1, 2);", GetVariableNameForSlot(kOutputSlotId), GetVariableNameForNode());
break;
default:
sb.AppendLine("$precision {0} = {1};", GetVariableNameForSlot(kOutputSlotId), m_MaterialList[material.type].ToString(CultureInfo.InvariantCulture));
break;
}
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
base.CollectPreviewMaterialProperties(properties);
if (material.type == DielectricMaterialType.Common)
{
properties.Add(new PreviewProperty(PropertyType.Float)
{
name = string.Format("_{0}_Range", GetVariableNameForNode()),
floatValue = material.range
});
}
else if (material.type == DielectricMaterialType.Custom)
{
properties.Add(new PreviewProperty(PropertyType.Float)
{
name = string.Format("_{0}_IOR", GetVariableNameForNode()),
floatValue = material.indexOfRefraction
});
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
if (!generationMode.IsPreview())
return;
base.CollectShaderProperties(properties, generationMode);
if (material.type == DielectricMaterialType.Common)
{
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_Range", GetVariableNameForNode()),
generatePropertyBlock = false
});
}
else if (material.type == DielectricMaterialType.Custom)
{
properties.AddShaderProperty(new Vector1ShaderProperty()
{
overrideReferenceName = string.Format("_{0}_IOR", GetVariableNameForNode()),
generatePropertyBlock = false
});
}
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f33e635e375c6b841bf3452a8da24be6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,79 @@
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
enum MetalMaterialType
{
Iron,
Silver,
Aluminium,
Gold,
Copper,
Chromium,
Nickel,
Titanium,
Cobalt,
Platinum
};
[Title("Input", "PBR", "Metal Reflectance")]
class MetalReflectanceNode : AbstractMaterialNode, IGeneratesBodyCode
{
public MetalReflectanceNode()
{
name = "Metal Reflectance";
UpdateNodeAfterDeserialization();
}
[SerializeField]
private MetalMaterialType m_Material = MetalMaterialType.Iron;
[EnumControl("Material")]
public MetalMaterialType material
{
get { return m_Material; }
set
{
if (m_Material == value)
return;
m_Material = value;
Dirty(ModificationScope.Graph);
}
}
static Dictionary<MetalMaterialType, string> m_MaterialList = new Dictionary<MetalMaterialType, string>
{
{MetalMaterialType.Iron, "(0.560, 0.570, 0.580)"},
{MetalMaterialType.Silver, "(0.972, 0.960, 0.915)"},
{MetalMaterialType.Aluminium, "(0.913, 0.921, 0.925)"},
{MetalMaterialType.Gold, "(1.000, 0.766, 0.336)"},
{MetalMaterialType.Copper, "(0.955, 0.637, 0.538)"},
{MetalMaterialType.Chromium, "(0.550, 0.556, 0.554)"},
{MetalMaterialType.Nickel, "(0.660, 0.609, 0.526)"},
{MetalMaterialType.Titanium, "(0.542, 0.497, 0.449)"},
{MetalMaterialType.Cobalt, "(0.662, 0.655, 0.634)"},
{MetalMaterialType.Platinum, "(0.672, 0.637, 0.585)"}
};
private const int kOutputSlotId = 0;
private const string kOutputSlotName = "Out";
public override bool hasPreview { get { return true; } }
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { kOutputSlotId });
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
sb.AppendLine(string.Format("$precision3 {0} = $precision3{1};", GetVariableNameForSlot(kOutputSlotId), m_MaterialList[material].ToString(CultureInfo.InvariantCulture)));
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ba3db6b7663a26244a3efba1203bad6e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,284 @@
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
using UnityEditor.ShaderGraph.Serialization;
namespace UnityEditor.ShaderGraph
{
[Serializable]
[Title("Input", "Property")]
class PropertyNode : AbstractMaterialNode, IGeneratesBodyCode, IOnAssetEnabled
{
public PropertyNode()
{
name = "Property";
UpdateNodeAfterDeserialization();
}
public override void UpdateNodeAfterDeserialization()
{
base.UpdateNodeAfterDeserialization();
if (owner == null)
return;
if (property is Vector1ShaderProperty vector1ShaderProperty && vector1ShaderProperty.floatType == FloatType.Slider)
{
// Previously, the Slider vector1 property allowed the min value to be greater than the max
// We no longer want to support that behavior so if such a property is encountered, swap the values
if (vector1ShaderProperty.rangeValues.x > vector1ShaderProperty.rangeValues.y)
{
vector1ShaderProperty.rangeValues = new Vector2(vector1ShaderProperty.rangeValues.y, vector1ShaderProperty.rangeValues.x);
Dirty(ModificationScope.Graph);
}
}
}
[SerializeField]
JsonRef<AbstractShaderProperty> m_Property;
public AbstractShaderProperty property
{
get { return m_Property; }
set
{
if (m_Property == value)
return;
m_Property = value;
// Set callback association for display name updates
m_Property.value.displayNameUpdateTrigger += UpdateNodeDisplayName;
AddOutputSlot();
Dirty(ModificationScope.Topological);
}
}
// this node's precision is always controlled by the property precision
public override bool canSetPrecision => false;
public void UpdateNodeDisplayName(string newDisplayName)
{
MaterialSlot foundSlot = FindSlot<MaterialSlot>(OutputSlotId);
if (foundSlot != null)
foundSlot.displayName = newDisplayName;
}
public void OnEnable()
{
AddOutputSlot();
}
public const int OutputSlotId = 0;
void AddOutputSlot()
{
if (property is MultiJsonInternal.UnknownShaderPropertyType uspt)
{
// keep existing slots, don't modify them
return;
}
switch (property.concreteShaderValueType)
{
case ConcreteSlotValueType.Boolean:
AddSlot(new BooleanMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, false));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Vector1:
AddSlot(new Vector1MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Vector2:
AddSlot(new Vector2MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Vector3:
AddSlot(new Vector3MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Vector4:
AddSlot(new Vector4MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output, Vector4.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Matrix2:
AddSlot(new Matrix2MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Matrix3:
AddSlot(new Matrix3MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Matrix4:
AddSlot(new Matrix4MaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Texture2D:
AddSlot(new Texture2DMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Texture2DArray:
AddSlot(new Texture2DArrayMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Texture3D:
AddSlot(new Texture3DMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Cubemap:
AddSlot(new CubemapMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.SamplerState:
AddSlot(new SamplerStateMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.Gradient:
AddSlot(new GradientMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
case ConcreteSlotValueType.VirtualTexture:
AddSlot(new VirtualTextureMaterialSlot(OutputSlotId, property.displayName, "Out", SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
break;
default:
throw new ArgumentOutOfRangeException();
}
}
public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode mode)
{
// preview is always generating a full shader, even when previewing within a subgraph
bool isGeneratingSubgraph = owner.isSubGraph && (mode != GenerationMode.Preview);
switch (property.propertyType)
{
case PropertyType.Boolean:
sb.AppendLine($"$precision {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Float:
sb.AppendLine($"$precision {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Vector2:
sb.AppendLine($"$precision2 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Vector3:
sb.AppendLine($"$precision3 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Vector4:
sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Color:
switch (property.sgVersion)
{
case 0:
case 2:
sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case 1:
case 3:
//Exposed color properties get put into the correct space automagikally by Unity UNLESS tagged as HDR, then they just get passed in as is.
//for consistency with other places in the editor, we assume HDR colors are in linear space, and correct for gamma space here
if ((property as ColorShaderProperty).colorMode == ColorMode.HDR)
{
sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = IsGammaSpace() ? LinearToSRGB({property.GetHLSLVariableName(isGeneratingSubgraph, mode)}) : {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
}
else
{
sb.AppendLine($"$precision4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
}
break;
default:
throw new Exception($"Unknown Color Property Version on property {property.displayName}");
}
break;
case PropertyType.Matrix2:
sb.AppendLine($"$precision2x2 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Matrix3:
sb.AppendLine($"$precision3x3 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Matrix4:
sb.AppendLine($"$precision4x4 {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Texture2D:
sb.AppendLine($"UnityTexture2D {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Texture3D:
sb.AppendLine($"UnityTexture3D {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Texture2DArray:
sb.AppendLine($"UnityTexture2DArray {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Cubemap:
sb.AppendLine($"UnityTextureCube {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.SamplerState:
sb.AppendLine($"UnitySamplerState {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
case PropertyType.Gradient:
if (mode == GenerationMode.Preview)
sb.AppendLine($"Gradient {GetVariableNameForSlot(OutputSlotId)} = {GradientUtil.GetGradientForPreview(property.GetHLSLVariableName(isGeneratingSubgraph, mode))};");
else
sb.AppendLine($"Gradient {GetVariableNameForSlot(OutputSlotId)} = {property.GetHLSLVariableName(isGeneratingSubgraph, mode)};");
break;
}
if (property.isConnectionTestable)
{
// If in a subgraph, the value will be read from a function parameter.
// If generating preview mode code, we always inline the value, according to code gen requirements.
// The parent graph always sets the explicit value to be passed to a subgraph function.
sb.AppendLine("bool {0} = {1};", GetConnectionStateVariableNameForSlot(OutputSlotId), (mode == GenerationMode.Preview || !isGeneratingSubgraph) ? (IsSlotConnected(OutputSlotId) ? "true" : "false") : property.GetConnectionStateHLSLVariableName());
}
}
public override string GetVariableNameForSlot(int slotId)
{
// TODO: we should switch VirtualTexture away from the macro-based variables and towards using the same approach as Texture2D
switch (property.propertyType)
{
case PropertyType.VirtualTexture:
return property.GetHLSLVariableName(owner.isSubGraph, GenerationMode.ForReals);
}
return base.GetVariableNameForSlot(slotId);
}
public string GetConnectionStateVariableNameForSlot(int slotId)
{
return ShaderInput.GetConnectionStateVariableName(GetVariableNameForSlot(slotId));
}
protected override void CalculateNodeHasError()
{
if (property == null || !owner.properties.Any(x => x == property))
{
owner.AddConcretizationError(objectId, "Property Node has no associated Blackboard property.");
}
else if (property is MultiJsonInternal.UnknownShaderPropertyType)
{
owner.AddValidationError(objectId, "Property is of unknown type, a package may be missing.", Rendering.ShaderCompilerMessageSeverity.Warning);
}
}
public override void UpdatePrecision(List<MaterialSlot> inputSlots)
{
// Get precision from Property
if (property == null)
{
owner.AddConcretizationError(objectId, string.Format("No matching poperty found on owner for node {0}", objectId));
hasError = true;
return;
}
// this node's precision is always controlled by the property precision
precision = property.precision;
graphPrecision = precision.ToGraphPrecision(GraphPrecision.Graph);
concretePrecision = graphPrecision.ToConcrete(owner.graphDefaultConcretePrecision);
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 93d9190b7b5ceb44ca24874c991b8da9
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: ad6f48f5ba4c9a24ab7b9df345b45d6f
folderAsset: yes
timeCreated: 1495527773
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,79 @@
using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Scene", "Camera")]
class CameraNode : AbstractMaterialNode, IMayRequireTransform
{
const string kOutputSlotName = "Position";
const string kOutputSlot1Name = "Direction";
const string kOutputSlot2Name = "Orthographic";
const string kOutputSlot3Name = "Near Plane";
const string kOutputSlot4Name = "Far Plane";
const string kOutputSlot5Name = "Z Buffer Sign";
const string kOutputSlot6Name = "Width";
const string kOutputSlot7Name = "Height";
public const int OutputSlotId = 0;
public const int OutputSlot1Id = 1;
public const int OutputSlot2Id = 2;
public const int OutputSlot3Id = 3;
public const int OutputSlot4Id = 4;
public const int OutputSlot5Id = 5;
public const int OutputSlot6Id = 6;
public const int OutputSlot7Id = 7;
public CameraNode()
{
name = "Camera";
synonyms = new string[] { "position", "direction", "orthographic", "near plane", "far plane", "width", "height" };
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero));
AddSlot(new Vector3MaterialSlot(OutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, Vector3.zero));
AddSlot(new Vector1MaterialSlot(OutputSlot2Id, kOutputSlot2Name, kOutputSlot2Name, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlot3Id, kOutputSlot3Name, kOutputSlot3Name, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlot4Id, kOutputSlot4Name, kOutputSlot4Name, SlotType.Output, 1));
AddSlot(new Vector1MaterialSlot(OutputSlot5Id, kOutputSlot5Name, kOutputSlot5Name, SlotType.Output, 1));
AddSlot(new Vector1MaterialSlot(OutputSlot6Id, kOutputSlot6Name, kOutputSlot6Name, SlotType.Output, 1));
AddSlot(new Vector1MaterialSlot(OutputSlot7Id, kOutputSlot7Name, kOutputSlot7Name, SlotType.Output, 1));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, OutputSlot1Id, OutputSlot2Id, OutputSlot3Id, OutputSlot4Id, OutputSlot5Id, OutputSlot6Id, OutputSlot7Id });
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlot1Id:
return "(-1 * mul((float3x3)UNITY_MATRIX_M, transpose(mul(UNITY_MATRIX_I_M, UNITY_MATRIX_I_V)) [2].xyz))";
case OutputSlot2Id:
return "unity_OrthoParams.w";
case OutputSlot3Id:
return "_ProjectionParams.y";
case OutputSlot4Id:
return "_ProjectionParams.z";
case OutputSlot5Id:
return "_ProjectionParams.x";
case OutputSlot6Id:
return "unity_OrthoParams.x";
case OutputSlot7Id:
return "unity_OrthoParams.y";
default:
return "_WorldSpaceCameraPos";
}
}
public NeededTransform[] RequiresTransform(ShaderStageCapability stageCapability = ShaderStageCapability.All)
{
return new[]
{
NeededTransform.ObjectToWorld,
NeededTransform.WorldToObject
};
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: dd27728b9ce314209beef46e595204c5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,35 @@
using System.Reflection;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Scene", "Eye Index")]
class EyeIndexNode : CodeFunctionNode
{
public override bool hasPreview { get { return false; } }
public EyeIndexNode()
{
name = "Eye Index";
synonyms = new string[] { "stereo", "3d" };
}
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("UnityGetEyeIndex", BindingFlags.Static | BindingFlags.NonPublic);
}
static string UnityGetEyeIndex([Slot(0, Binding.None)] out Vector1 Out)
{
return
@"
{
#if defined(UNITY_SINGLE_PASS_STEREO) || defined(UNITY_STEREO_INSTANCING_ENABLED) || defined(UNITY_STEREO_MULTIVIEW_ENABLED)
Out = unity_StereoEyeIndex;
#else
Out = 0;
#endif
}
";
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8ef30ebbb2a5c6c4989bfa74ad4600bf
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,35 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Scene", "Fog")]
class FogNode : CodeFunctionNode
{
public FogNode()
{
name = "Fog";
}
public override bool hasPreview { get { return false; } }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_Fog", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_Fog(
[Slot(2, Binding.ObjectSpacePosition)] Vector3 Position,
[Slot(0, Binding.None)] out Vector4 Color,
[Slot(1, Binding.None)] out Vector1 Density)
{
Color = Vector4.zero;
return
@"
{
SHADERGRAPH_FOG(Position, Color, Density);
}
";
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f934acb3f675022448ac439d87d84a80
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,44 @@
using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Scene", "Object")]
sealed class ObjectNode : AbstractMaterialNode, IMayRequireTransform
{
const string kOutputSlotName = "Position";
const string kOutputSlot1Name = "Scale";
public const int OutputSlotId = 0;
public const int OutputSlot1Id = 1;
public ObjectNode()
{
name = "Object";
synonyms = new string[] { "position", "scale" };
UpdateNodeAfterDeserialization();
}
public override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero));
AddSlot(new Vector3MaterialSlot(OutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, OutputSlot1Id });
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlot1Id:
return @"$precision3(length($precision3(UNITY_MATRIX_M[0].x, UNITY_MATRIX_M[1].x, UNITY_MATRIX_M[2].x)),
length($precision3(UNITY_MATRIX_M[0].y, UNITY_MATRIX_M[1].y, UNITY_MATRIX_M[2].y)),
length($precision3(UNITY_MATRIX_M[0].z, UNITY_MATRIX_M[1].z, UNITY_MATRIX_M[2].z)))";
default:
return "SHADERGRAPH_OBJECT_POSITION";
}
}
public NeededTransform[] RequiresTransform(ShaderStageCapability stageCapability = ShaderStageCapability.All) => new[] { NeededTransform.ObjectToWorld };
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 081b8aed5e33ba1418a6a80f7693b9b4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,48 @@
using System.Reflection;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Scene", "Scene Color")]
sealed class SceneColorNode : CodeFunctionNode, IMayRequireCameraOpaqueTexture
{
const string kScreenPositionSlotName = "UV";
const string kOutputSlotName = "Out";
public const int ScreenPositionSlotId = 0;
public const int OutputSlotId = 1;
public SceneColorNode()
{
name = "Scene Color";
synonyms = new string[] { "screen buffer" };
UpdateNodeAfterDeserialization();
}
public override bool hasPreview { get { return false; } }
protected override MethodInfo GetFunctionToConvert()
{
return GetType().GetMethod("Unity_SceneColor", BindingFlags.Static | BindingFlags.NonPublic);
}
static string Unity_SceneColor(
[Slot(0, Binding.ScreenPosition)] Vector4 UV,
[Slot(1, Binding.None, ShaderStageCapability.Fragment)] out Vector3 Out)
{
Out = Vector3.one;
return
@"
{
Out = SHADERGRAPH_SAMPLE_SCENE_COLOR(UV.xy);
}
";
}
public bool RequiresCameraOpaqueTexture(ShaderStageCapability stageCapability)
{
return true;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c4ba33edde21e400685cf0fb5c8f2551
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,113 @@
using System.Reflection;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
enum DepthSamplingMode
{
Linear01,
Raw,
Eye
};
[Title("Input", "Scene", "Scene Depth")]
sealed class SceneDepthNode : CodeFunctionNode, IMayRequireDepthTexture
{
const string kScreenPositionSlotName = "UV";
const string kOutputSlotName = "Out";
public const int ScreenPositionSlotId = 0;
public const int OutputSlotId = 1;
[SerializeField]
private DepthSamplingMode m_DepthSamplingMode = DepthSamplingMode.Linear01;
[EnumControl("Sampling Mode")]
public DepthSamplingMode depthSamplingMode
{
get { return m_DepthSamplingMode; }
set
{
if (m_DepthSamplingMode == value)
return;
m_DepthSamplingMode = value;
Dirty(ModificationScope.Graph);
}
}
public SceneDepthNode()
{
name = "Scene Depth";
synonyms = new string[] { "zbuffer", "zdepth" };
UpdateNodeAfterDeserialization();
}
public override bool hasPreview { get { return false; } }
protected override MethodInfo GetFunctionToConvert()
{
switch (m_DepthSamplingMode)
{
case DepthSamplingMode.Raw:
return GetType().GetMethod("Unity_SceneDepth_Raw", BindingFlags.Static | BindingFlags.NonPublic);
case DepthSamplingMode.Eye:
return GetType().GetMethod("Unity_SceneDepth_Eye", BindingFlags.Static | BindingFlags.NonPublic);
case DepthSamplingMode.Linear01:
default:
return GetType().GetMethod("Unity_SceneDepth_Linear01", BindingFlags.Static | BindingFlags.NonPublic);
}
}
static string Unity_SceneDepth_Linear01(
[Slot(0, Binding.ScreenPosition)] Vector4 UV,
[Slot(1, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out)
{
return
@"
{
Out = Linear01Depth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy), _ZBufferParams);
}
";
}
static string Unity_SceneDepth_Raw(
[Slot(0, Binding.ScreenPosition)] Vector4 UV,
[Slot(1, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out)
{
return
@"
{
Out = SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy);
}
";
}
static string Unity_SceneDepth_Eye(
[Slot(0, Binding.ScreenPosition)] Vector4 UV,
[Slot(1, Binding.None, ShaderStageCapability.Fragment)] out Vector1 Out)
{
return
@"
{
if (unity_OrthoParams.w == 1.0)
{
Out = LinearEyeDepth(ComputeWorldSpacePosition(UV.xy, SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy), UNITY_MATRIX_I_VP), UNITY_MATRIX_V);
}
else
{
Out = LinearEyeDepth(SHADERGRAPH_SAMPLE_SCENE_DEPTH(UV.xy), _ZBufferParams);
}
}
";
}
public bool RequiresDepthTexture(ShaderStageCapability stageCapability)
{
return true;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f8e0a75d065844105a06ca48151adb7b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,39 @@
using UnityEditor.Graphing;
using UnityEngine;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Scene", "Screen")]
sealed class ScreenNode : AbstractMaterialNode
{
const string kOutputSlotName = "Width";
const string kOutputSlot1Name = "Height";
public const int OutputSlotId = 0;
public const int OutputSlot1Id = 1;
public ScreenNode()
{
name = "Screen";
UpdateNodeAfterDeserialization();
}
public override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0));
AddSlot(new Vector1MaterialSlot(OutputSlot1Id, kOutputSlot1Name, kOutputSlot1Name, SlotType.Output, 0));
RemoveSlotsNameNotMatching(new[] { OutputSlotId, OutputSlot1Id });
}
public override string GetVariableNameForSlot(int slotId)
{
switch (slotId)
{
case OutputSlot1Id:
return "_ScreenParams.y";
default:
return "_ScreenParams.x";
}
}
}
}

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 94b2801c66359164e93dc371fc6762e2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View file

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 07cc6493671f2344089936cf4a0ab49b
folderAsset: yes
timeCreated: 1495528572
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,120 @@
using System.Linq;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
using UnityEditor.ShaderGraph.Drawing.Controls;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Texture", "Calculate Level Of Detail Texture 2D")]
class CalculateLevelOfDetailTexture2DNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
{
[SerializeField]
bool m_Clamp = true;
[ToggleControl]
public ToggleData clamp
{
get => new ToggleData(m_Clamp);
set
{
m_Clamp = value.isOn;
Dirty(ModificationScope.Node);
}
}
public const int OutputSlotLODId = 0;
public const int TextureInputId = 1;
public const int UVInput = 2;
public const int SamplerInput = 3;
const string kOutputSlotLODName = "LOD";
const string kTextureInputName = "Texture";
const string kUVInputName = "UV";
const string kSamplerInputName = "Sampler";
public override bool hasPreview { get { return true; } }
public CalculateLevelOfDetailTexture2DNode()
{
name = "Calculate Level Of Detail Texture 2D";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector1MaterialSlot(OutputSlotLODId, kOutputSlotLODName, kOutputSlotLODName, SlotType.Output, 0, ShaderStageCapability.Fragment));
AddSlot(new Texture2DInputMaterialSlot(TextureInputId, kTextureInputName, kTextureInputName));
AddSlot(new UVMaterialSlot(UVInput, kUVInputName, kUVInputName, UVChannel.UV0));
AddSlot(new SamplerStateMaterialSlot(SamplerInput, kSamplerInputName, kSamplerInputName, SlotType.Input));
RemoveSlotsNameNotMatching(new[] { OutputSlotLODId, TextureInputId, UVInput, SamplerInput });
}
public override void Setup()
{
base.Setup();
var textureSlot = FindInputSlot<Texture2DInputMaterialSlot>(TextureInputId);
textureSlot.defaultType = Texture2DShaderProperty.DefaultType.White;
}
// Node generations
public virtual void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var uvName = GetSlotValue(UVInput, generationMode);
//Sampler input slot
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerInput);
var edgesSampler = owner.GetEdges(samplerSlot.slotReference);
var id = GetSlotValue(TextureInputId, generationMode);
sb.AppendLine("#if (SHADER_TARGET >= 41)");
{
var func = m_Clamp ? "CalculateLevelOfDetail" : "CalculateLevelOfDetailUnclamped";
sb.AppendLine(string.Format("$precision {0} = {1}.tex.{2}({3}.samplerstate, {4});"
, GetVariableNameForSlot(OutputSlotLODId)
, id
, func
, edgesSampler.Any() ? GetSlotValue(SamplerInput, generationMode) : id
, uvName));
}
sb.AppendLine("#else");
{
var dUVdx = string.Format("ddx({0} * {1}.texelSize.zw)", uvName, id);
var dUVdy = string.Format("ddy({0} * {1}.texelSize.zw)", uvName, id);
var delta_max_sqr = string.Format("max(dot({0}, {0}), dot({1}, {1}))", dUVdx, dUVdy);
sb.AppendLine(string.Format("$precision {0};", GetVariableNameForSlot(OutputSlotLODId)));
sb.AppendLine(string.Format("{0} = 0.5f*log2({1});", GetVariableNameForSlot(OutputSlotLODId), delta_max_sqr));
sb.AppendLine(string.Format("{0} = max({0}, 0);", GetVariableNameForSlot(OutputSlotLODId)));
if (m_Clamp)
{
sb.AppendLine("#if defined(MIP_COUNT_SUPPORTED)");
sb.AppendLine(string.Format("{0} = min({0}, GetMipCount(TEXTURE2D_ARGS({1}.tex, {2}.samplerstate))-1);", GetVariableNameForSlot(OutputSlotLODId), id, edgesSampler.Any() ? GetSlotValue(SamplerInput, generationMode) : id));
sb.AppendLine("#endif");
}
}
sb.AppendLine("#endif");
}
public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability)
{
using (var tempSlots = PooledList<MaterialSlot>.Get())
{
GetInputSlots(tempSlots);
var result = false;
foreach (var slot in tempSlots)
{
if (slot.RequiresMeshUV(channel))
{
result = true;
break;
}
}
tempSlots.Clear();
return result;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 03cdc5d395730c74ebabff3988c5110d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,100 @@
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Texture", "Cubemap Asset")]
[HasDependencies(typeof(MinimalCubemapAssetNode))]
class CubemapAssetNode : AbstractMaterialNode, IPropertyFromNode
{
public const int OutputSlotId = 0;
const string kOutputSlotName = "Out";
public CubemapAssetNode()
{
name = "Cubemap Asset";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new CubemapMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
}
[SerializeField]
private SerializableCubemap m_Cubemap = new SerializableCubemap();
[CubemapControl("")]
public Cubemap cubemap
{
get { return m_Cubemap.cubemap; }
set
{
if (m_Cubemap.cubemap == value)
return;
m_Cubemap.cubemap = value;
Dirty(ModificationScope.Node);
}
}
string GetTexturePropertyName()
{
return base.GetVariableNameForSlot(OutputSlotId);
}
public override string GetVariableNameForSlot(int slotId)
{
return $"UnityBuildTextureCubeStruct({GetTexturePropertyName()})";
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
properties.AddShaderProperty(new CubemapShaderProperty()
{
overrideReferenceName = GetTexturePropertyName(),
generatePropertyBlock = true,
value = m_Cubemap,
modifiable = false
});
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.Cubemap)
{
name = GetTexturePropertyName(),
cubemapValue = cubemap
});
}
public AbstractShaderProperty AsShaderProperty()
{
var prop = new CubemapShaderProperty { value = m_Cubemap };
if (cubemap != null)
prop.displayName = cubemap.name;
return prop;
}
public int outputSlotId { get { return OutputSlotId; } }
}
class MinimalCubemapAssetNode : IHasDependencies
{
[SerializeField]
private SerializableCubemap m_Cubemap = null;
public void GetSourceAssetDependencies(AssetCollection assetCollection)
{
var guidString = m_Cubemap.guid;
if (!string.IsNullOrEmpty(guidString) && GUID.TryParse(guidString, out var guid))
{
assetCollection.AddAssetDependency(guid, AssetCollection.Flags.IncludeInExportPackage);
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 968ed0a541658844486b1ac5ab57ee2d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,131 @@
using System.Linq;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
[Title("Input", "Texture", "Gather Texture 2D")]
class GatherTexture2DNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireMeshUV
{
public const int OutputSlotRGBAId = 0;
public const int OutputSlotRId = 5;
public const int OutputSlotGId = 6;
public const int OutputSlotBId = 7;
public const int OutputSlotAId = 8;
public const int TextureInputId = 1;
public const int UVInput = 2;
public const int SamplerInput = 3;
public const int OffsetInput = 4;
const string kOutputSlotRGBAName = "RGBA";
const string kOutputSlotRName = "R";
const string kOutputSlotGName = "G";
const string kOutputSlotBName = "B";
const string kOutputSlotAName = "A";
const string kTextureInputName = "Texture";
const string kUVInputName = "UV";
const string kSamplerInputName = "Sampler";
const string kOffsetInputName = "Offset";
public override bool hasPreview { get { return true; } }
public GatherTexture2DNode()
{
name = "Gather Texture 2D";
UpdateNodeAfterDeserialization();
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new Vector4MaterialSlot(OutputSlotRGBAId, kOutputSlotRGBAName, kOutputSlotRGBAName, SlotType.Output, Vector4.zero, ShaderStageCapability.All));
AddSlot(new Vector1MaterialSlot(OutputSlotRId, kOutputSlotRName, kOutputSlotRName, SlotType.Output, 0, ShaderStageCapability.All));
AddSlot(new Vector1MaterialSlot(OutputSlotGId, kOutputSlotGName, kOutputSlotGName, SlotType.Output, 0, ShaderStageCapability.All));
AddSlot(new Vector1MaterialSlot(OutputSlotBId, kOutputSlotBName, kOutputSlotBName, SlotType.Output, 0, ShaderStageCapability.All));
AddSlot(new Vector1MaterialSlot(OutputSlotAId, kOutputSlotAName, kOutputSlotAName, SlotType.Output, 0, ShaderStageCapability.All));
AddSlot(new Texture2DInputMaterialSlot(TextureInputId, kTextureInputName, kTextureInputName));
AddSlot(new UVMaterialSlot(UVInput, kUVInputName, kUVInputName, UVChannel.UV0));
AddSlot(new SamplerStateMaterialSlot(SamplerInput, kSamplerInputName, kSamplerInputName, SlotType.Input));
AddSlot(new Vector2MaterialSlot(OffsetInput, kOffsetInputName, kOffsetInputName, SlotType.Input, Vector2.zero, ShaderStageCapability.All, null, null, false, true));
RemoveSlotsNameNotMatching(new[] { OutputSlotRGBAId, OutputSlotRId, OutputSlotGId, OutputSlotBId, OutputSlotAId, TextureInputId, UVInput, SamplerInput, OffsetInput });
}
public override void Setup()
{
base.Setup();
var textureSlot = FindInputSlot<Texture2DInputMaterialSlot>(TextureInputId);
textureSlot.defaultType = Texture2DShaderProperty.DefaultType.White;
}
// Node generations
public virtual void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode)
{
var uvName = GetSlotValue(UVInput, generationMode);
//Sampler input slot
var samplerSlot = FindInputSlot<MaterialSlot>(SamplerInput);
var edgesSampler = owner.GetEdges(samplerSlot.slotReference);
var id = GetSlotValue(TextureInputId, generationMode);
var offset = GetSlotValue(OffsetInput, generationMode);
sb.AppendLine("#if (SHADER_TARGET >= 41)");
{
sb.AppendLine(string.Format("$precision4 {0} = {1}.tex.Gather({2}.samplerstate, {3}, {4});"
, GetVariableNameForSlot(OutputSlotRGBAId)
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInput, generationMode) : id
, uvName
, offset));
sb.AppendLine(string.Format("$precision {0} = {1}.r;", GetVariableNameForSlot(OutputSlotRId), GetVariableNameForSlot(OutputSlotRGBAId)));
sb.AppendLine(string.Format("$precision {0} = {1}.g;", GetVariableNameForSlot(OutputSlotGId), GetVariableNameForSlot(OutputSlotRGBAId)));
sb.AppendLine(string.Format("$precision {0} = {1}.b;", GetVariableNameForSlot(OutputSlotBId), GetVariableNameForSlot(OutputSlotRGBAId)));
sb.AppendLine(string.Format("$precision {0} = {1}.a;", GetVariableNameForSlot(OutputSlotAId), GetVariableNameForSlot(OutputSlotRGBAId)));
}
sb.AppendLine("#else");
{
// Gather offsets defined in this order:
// (-,+),(+,+),(+,-),(-,-)
var uvR = string.Format("(floor({0} * {1}.texelSize.zw + $precision2(-0.5, 0.5)) + trunc({2}) + $precision2(0.5, 0.5)) * {1}.texelSize.xy", uvName, id, offset);
var uvG = string.Format("(floor({0} * {1}.texelSize.zw + $precision2(0.5, 0.5)) + trunc({2}) + $precision2(0.5, 0.5)) * {1}.texelSize.xy", uvName, id, offset);
var uvB = string.Format("(floor({0} * {1}.texelSize.zw + $precision2(0.5, -0.5)) + trunc({2}) + $precision2(0.5, 0.5)) * {1}.texelSize.xy", uvName, id, offset);
var uvA = string.Format("(floor({0} * {1}.texelSize.zw + $precision2(-0.5, -0.5)) + trunc({2}) + $precision2(0.5, 0.5)) * {1}.texelSize.xy", uvName, id, offset);
sb.AppendLine(string.Format("$precision {0} = SAMPLE_TEXTURE2D_LOD({1}.tex, {2}.samplerstate, {3}, 0).r;", GetVariableNameForSlot(OutputSlotRId), id, edgesSampler.Any() ? GetSlotValue(SamplerInput, generationMode) : id, uvR));
sb.AppendLine(string.Format("$precision {0} = SAMPLE_TEXTURE2D_LOD({1}.tex, {2}.samplerstate, {3}, 0).r;", GetVariableNameForSlot(OutputSlotGId), id, edgesSampler.Any() ? GetSlotValue(SamplerInput, generationMode) : id, uvG));
sb.AppendLine(string.Format("$precision {0} = SAMPLE_TEXTURE2D_LOD({1}.tex, {2}.samplerstate, {3}, 0).r;", GetVariableNameForSlot(OutputSlotBId), id, edgesSampler.Any() ? GetSlotValue(SamplerInput, generationMode) : id, uvB));
sb.AppendLine(string.Format("$precision {0} = SAMPLE_TEXTURE2D_LOD({1}.tex, {2}.samplerstate, {3}, 0).r;", GetVariableNameForSlot(OutputSlotAId), id, edgesSampler.Any() ? GetSlotValue(SamplerInput, generationMode) : id, uvA));
sb.AppendLine(string.Format("$precision4 {0} = $precision4({1},{2},{3},{4});"
, GetVariableNameForSlot(OutputSlotRGBAId)
, GetVariableNameForSlot(OutputSlotRId)
, GetVariableNameForSlot(OutputSlotGId)
, GetVariableNameForSlot(OutputSlotBId)
, GetVariableNameForSlot(OutputSlotAId)));
}
sb.AppendLine("#endif");
}
public bool RequiresMeshUV(UVChannel channel, ShaderStageCapability stageCapability)
{
using (var tempSlots = PooledList<MaterialSlot>.Get())
{
GetInputSlots(tempSlots);
var result = false;
foreach (var slot in tempSlots)
{
if (slot.RequiresMeshUV(channel))
{
result = true;
break;
}
}
tempSlots.Clear();
return result;
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e52355d9fc877154b9403531b2837081
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,136 @@
using System.Collections.Generic;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Internal;
namespace UnityEditor.ShaderGraph
{
#if PROCEDURAL_VT_IN_GRAPH
[Title("Input", "Texture", "Procedural Virtual Texture")]
class ProceduralVirtualTextureNode : AbstractMaterialNode
{
public const int OutputSlotId = 0;
const string kOutputSlotName = "Out";
public ProceduralVirtualTextureNode()
{
UpdateNodeAfterDeserialization();
SetLayerCount(2);
vtProperty.displayName = "ProceduralVirtualTexture";
vtProperty.overrideReferenceName = "MyPVT";
vtProperty.value.procedural = true;
vtProperty.value.shaderDeclaration = HLSLDeclaration.UnityPerMaterial;
UpdateName();
}
void UpdateName()
{
name = "Procedural Virtual Texture: " + vtProperty.overrideReferenceName;
}
public sealed override void UpdateNodeAfterDeserialization()
{
AddSlot(new VirtualTextureMaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output));
RemoveSlotsNameNotMatching(new[] { OutputSlotId });
SetLayerCount(layers);
vtProperty.generatePropertyBlock = true;
vtProperty.hidden = true;
}
public override int latestVersion => 1;
public override void OnAfterMultiDeserialize(string json)
{
if (sgVersion == 0)
{
// version 0 was implicitly declaring PVT stacks as Global shader properties
shaderDeclaration = HLSLDeclaration.Global;
ChangeVersion(1);
}
}
[SerializeField]
private VirtualTextureShaderProperty vtProperty = new VirtualTextureShaderProperty();
void SetLayerCount(int layers)
{
var uniqueName = objectId;
vtProperty.value.layers.Clear();
layers = System.Math.Max(System.Math.Min(layers, SampleVirtualTextureNode.kMaxLayers), SampleVirtualTextureNode.kMinLayers);
for (int x = 0; x < layers; x++)
{
vtProperty.value.layers.Add(new SerializableVirtualTextureLayer("Layer" + x + "_" + uniqueName, "Layer" + x + "_" + uniqueName, null));
}
}
[IdentifierControl("Name")]
public string vtName
{
get { return vtProperty.overrideReferenceName; }
set
{
if (vtProperty.overrideReferenceName == value)
return;
vtProperty.overrideReferenceName = value;
UpdateName();
Dirty(ModificationScope.Graph);
}
}
[IntegerControl("Layers")]
public int layers
{
get { return vtProperty.value.layers.Count; }
set
{
if (vtProperty.value.layers.Count == value)
return;
SetLayerCount(value);
Dirty(ModificationScope.Topological);
//Hack to handle downstream SampleVirtualTextureNodes
owner.ValidateGraph();
}
}
internal HLSLDeclaration shaderDeclaration
{
get { return vtProperty.value.shaderDeclaration; }
set
{
if (vtProperty.value.shaderDeclaration == value)
return;
vtProperty.value.shaderDeclaration = value;
Dirty(ModificationScope.Graph);
}
}
public override void CollectShaderProperties(PropertyCollector properties, GenerationMode generationMode)
{
properties.AddShaderProperty(vtProperty);
}
public override void CollectPreviewMaterialProperties(List<PreviewProperty> properties)
{
properties.Add(new PreviewProperty(PropertyType.VirtualTexture)
{
name = GetVariableNameForSlot(OutputSlotId),
vtProperty = vtProperty
});
}
public AbstractShaderProperty AsShaderProperty()
{
return vtProperty;
}
// to show Shader Declaration in the node settings, as if this node was itself a real AbstractShaderProperty
internal bool AllowHLSLDeclaration(HLSLDeclaration decl) =>
(decl == HLSLDeclaration.Global || decl == HLSLDeclaration.UnityPerMaterial);
}
#endif // PROCEDURAL_VT_IN_GRAPH
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 49a3a90a50f5fbf4ba608b8e4afe373a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Some files were not shown because too many files have changed in this diff Show more