initial commit
This commit is contained in:
parent
6715289efe
commit
788c3389af
37645 changed files with 2526849 additions and 80 deletions
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 25ded6c13e7523d48935f8bd1b9afcb6
|
||||
timeCreated: 1481041579
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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
|
||||
}
|
||||
";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 215e6221fbd6f9a4bbd14e951c9575d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 5b34601661908b3499c4c5e2ecd61f75
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 137f6921c5ee7ca4dbffb34de10f52f5
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: e204c7999bfa0ee42a18d8a560a36244
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 9e8bd6ff1eba8ea4589ec534a00f4767
|
||||
timeCreated: 1480080968
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 1c05002dbfc8cd14cb3b544630cf1017
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 923cdcd772822d84b9d79807e27d502b
|
||||
timeCreated: 1481123160
|
||||
licenseType: Pro
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8cc9905543f080945b4250dfa558e604
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 30cf94a5e32cd254eb6eadf45e5cdfe3
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
|
@ -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);
|
||||
}
|
||||
";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 7b36a91e8a7cf304b81905da7b233f23
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
Loading…
Add table
Add a link
Reference in a new issue