浏览代码
Maths Part 3
Maths Part 3
- Cleanup after merge - Started on Maths/Vector - Fixed Log and Exponential outputs - Partial Derivative is WIP/main
Matt Dean
7 年前
当前提交
d085dca3
共有 17 个文件被更改,包括 494 次插入 和 389 次删除
-
8MaterialGraphProject/Assets/NewNodes/Editor/CommonMatrixType.cs
-
30MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/ConstantNode.cs
-
5MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/ConstantNode.cs.meta
-
43MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Advanced/LogNode.cs
-
34MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Basic/ExponentialNode.cs
-
48MaterialGraphProject/GeneratedShader.shader
-
31MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/CrossProductNode.cs
-
156MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/PartialDerivativeNode.cs
-
11MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/PartialDerivativeNode.cs.meta
-
199MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TransformNode.cs
-
60MaterialGraphProject/Assets/NewNodes/Editor/Keep/ConstantsNode.cs
-
227MaterialGraphProject/Assets/NewNodes/Editor/Keep/TransformNode.cs
-
31MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/CrossNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/CrossProductNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TangentToWorldNode.cs
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TangentToWorldNode.cs.meta
-
0/MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TransformNode.cs.meta
|
|||
using System.Reflection; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Vector/Cross Product")] |
|||
public class CrossProductNode : CodeFunctionNode |
|||
{ |
|||
public CrossProductNode() |
|||
{ |
|||
name = "Cross Product"; |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_CrossProduct", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string Unity_CrossProduct( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector A, |
|||
[Slot(1, Binding.None)] DynamicDimensionVector B, |
|||
[Slot(2, Binding.None)] out DynamicDimensionVector Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
Out = cross(A, B); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
using System.Reflection; |
|||
using UnityEditor.MaterialGraph.Drawing.Controls; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Vector/Partial Derivative")] |
|||
public class PartialDerivativeNode : CodeFunctionNode |
|||
{ |
|||
public enum Precision |
|||
{ |
|||
Coarse, |
|||
Default, |
|||
Fine |
|||
}; |
|||
|
|||
public enum Coordinate |
|||
{ |
|||
X, |
|||
Y |
|||
}; |
|||
|
|||
public PartialDerivativeNode() |
|||
{ |
|||
name = "Partial Derivative"; |
|||
} |
|||
|
|||
[SerializeField] |
|||
private Precision m_Precision = Precision.Default; |
|||
|
|||
[EnumControl("Precision")] |
|||
public Precision _precision |
|||
{ |
|||
get { return m_Precision; } |
|||
set |
|||
{ |
|||
if (m_Precision == value) |
|||
return; |
|||
|
|||
m_Precision = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
string GetCurrentPrecision() |
|||
{ |
|||
return System.Enum.GetName(typeof(Precision), m_Precision); |
|||
} |
|||
|
|||
[SerializeField] |
|||
private Coordinate m_Coordinate = Coordinate.X; |
|||
|
|||
[EnumControl("Respect Coordinate")] |
|||
public Coordinate coordinate |
|||
{ |
|||
get { return m_Coordinate; } |
|||
set |
|||
{ |
|||
if (m_Coordinate == value) |
|||
return; |
|||
|
|||
m_Coordinate = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
string GetCurrentCoordinate() |
|||
{ |
|||
return System.Enum.GetName(typeof(Coordinate), m_Coordinate); |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod(string.Format("Unity_DD{0}_{1}", GetCurrentCoordinate(), GetCurrentPrecision()), |
|||
BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string Unity_DDX_Default( |
|||
[Slot(0, Binding.None)] Vector1 In, |
|||
[Slot(1, Binding.None)] out Vector1 Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
Out = ddx(In); |
|||
} |
|||
";
|
|||
} |
|||
|
|||
static string Unity_DDX_Coarse( |
|||
[Slot(0, Binding.None)] Vector1 In, |
|||
[Slot(1, Binding.None)] out Vector1 Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
Out = ddx_coarse(In); |
|||
} |
|||
";
|
|||
} |
|||
|
|||
static string Unity_DDX_Fine( |
|||
[Slot(0, Binding.None)] Vector1 In, |
|||
[Slot(1, Binding.None)] out Vector1 Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
Out = ddx_fine(In); |
|||
} |
|||
";
|
|||
} |
|||
|
|||
static string Unity_DDY_Default( |
|||
[Slot(0, Binding.None)] Vector1 In, |
|||
[Slot(1, Binding.None)] out Vector1 Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
Out = ddy(In); |
|||
} |
|||
";
|
|||
} |
|||
|
|||
static string Unity_DDY_Coarse( |
|||
[Slot(0, Binding.None)] Vector1 In, |
|||
[Slot(1, Binding.None)] out Vector1 Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
Out = ddy_coarse(In); |
|||
} |
|||
";
|
|||
} |
|||
|
|||
static string Unity_DDY_Fine( |
|||
[Slot(0, Binding.None)] Vector1 In, |
|||
[Slot(1, Binding.None)] out Vector1 Out) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
Out = ddy_fine(In); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: e1fc64adb3d116647b70ce39fb0a01fd |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine.Graphing; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.MaterialGraph.Drawing.Controls; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Vector/Transform")] |
|||
public class TransformNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireTangent, IMayRequireBitangent, IMayRequireNormal |
|||
{ |
|||
[SerializeField] |
|||
private CoordinateSpace m_spaceListFrom; |
|||
[SerializeField] |
|||
private CoordinateSpace m_spaceListTo; |
|||
|
|||
private const int InputSlotId = 0; |
|||
private const int OutputSlotId = 1; |
|||
private const string kInputSlotName = "In"; |
|||
private const string kOutputSlotName = "Out"; |
|||
|
|||
public TransformNode() |
|||
{ |
|||
name = "Transform"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
[EnumControl("From")] |
|||
public CoordinateSpace spaceFrom |
|||
{ |
|||
get { return m_spaceListFrom; } |
|||
set |
|||
{ |
|||
if (m_spaceListFrom == value) |
|||
return; |
|||
|
|||
m_spaceListFrom = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
[EnumControl("To")] |
|||
public CoordinateSpace spaceTo |
|||
{ |
|||
get { return m_spaceListTo; } |
|||
set |
|||
{ |
|||
if (m_spaceListTo == value) |
|||
return; |
|||
|
|||
m_spaceListTo = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return true; } |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(GetInputSlot()); |
|||
AddSlot(GetOutputSlot()); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] {InputSlotId, OutputSlotId}; } |
|||
} |
|||
|
|||
protected virtual MaterialSlot GetInputSlot() |
|||
{ |
|||
return new Vector3MaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector3.zero); |
|||
} |
|||
|
|||
protected virtual MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector4.zero); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlotId }, new[] { OutputSlotId }); |
|||
string inputValue = GetSlotValue(InputSlotId, generationMode); |
|||
string transformString = ""; |
|||
bool requiresTangentTransform = false; |
|||
|
|||
if (spaceFrom == CoordinateSpace.World) |
|||
{ |
|||
if (spaceTo == CoordinateSpace.World) |
|||
{ |
|||
transformString = inputValue; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.Object) |
|||
{ |
|||
transformString = "mul(unity_WorldToObject, float4(" + inputValue + ", 0)).xyz"; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.Tangent) |
|||
{ |
|||
requiresTangentTransform = true; |
|||
transformString = "mul(tangentTransform, " + inputValue + ").xyz"; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.View) |
|||
{ |
|||
transformString = "mul( UNITY_MATRIX_V, float4(" + inputValue + ", 0)).xyz"; |
|||
} |
|||
} |
|||
else if (spaceFrom == CoordinateSpace.Object) |
|||
{ |
|||
if (spaceTo == CoordinateSpace.World) |
|||
{ |
|||
transformString = "mul(unity_ObjectToWorld, float4(" + inputValue + ", 0)).xyz"; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.Object) |
|||
{ |
|||
transformString = inputValue; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.Tangent) |
|||
{ |
|||
requiresTangentTransform = true; |
|||
transformString = "mul( tangentTransform, mul( unity_ObjectToWorld, float4(" + inputValue + ", 0) ).xyz).xyz"; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.View) |
|||
{ |
|||
transformString = "mul( UNITY_MATRIX_MV, float4(" + inputValue + ", 0)).xyz"; |
|||
} |
|||
} |
|||
else if (spaceFrom == CoordinateSpace.Tangent) |
|||
{ |
|||
requiresTangentTransform = true; |
|||
if (spaceTo == CoordinateSpace.World) |
|||
{ |
|||
transformString = "mul( " + inputValue + ", tangentTransform ).xyz"; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.Object) |
|||
{ |
|||
transformString = "mul( unity_WorldToObject, float4(mul(" + inputValue + ", tangentTransform ),0) ).xyz"; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.Tangent) |
|||
{ |
|||
transformString = inputValue; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.View) |
|||
{ |
|||
transformString = "mul( UNITY_MATRIX_V, float4(mul(" + inputValue + ", tangentTransform ),0) ).xyz"; |
|||
} |
|||
} |
|||
else if (spaceFrom == CoordinateSpace.View) |
|||
{ |
|||
if (spaceTo == CoordinateSpace.World) |
|||
{ |
|||
transformString = "mul( float4(" + inputValue + ", 0), UNITY_MATRIX_V ).xyz"; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.Object) |
|||
{ |
|||
transformString = "mul( float4(" + inputValue + ", 0), UNITY_MATRIX_MV ).xyz"; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.Tangent) |
|||
{ |
|||
requiresTangentTransform = true; |
|||
transformString = "mul( tangentTransform, mul( float4(" + inputValue + ", 0), UNITY_MATRIX_V ).xyz ).xyz"; |
|||
} |
|||
else if (spaceTo == CoordinateSpace.View) |
|||
{ |
|||
transformString = inputValue; |
|||
} |
|||
} |
|||
|
|||
if (requiresTangentTransform) |
|||
visitor.AddShaderChunk("float3x3 tangentTransform = float3x3("+ spaceFrom.ToString() + "SpaceTangent, "+ spaceFrom.ToString() + "SpaceBiTangent, "+ spaceFrom.ToString() + "SpaceNormal);", false); |
|||
|
|||
visitor.AddShaderChunk(string.Format("{0} {1} = {2};", |
|||
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), |
|||
GetVariableNameForSlot(OutputSlotId), |
|||
transformString), true); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresTangent() |
|||
{ |
|||
return spaceFrom.ToNeededCoordinateSpace(); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresBitangent() |
|||
{ |
|||
return spaceFrom.ToNeededCoordinateSpace(); |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresNormal() |
|||
{ |
|||
return spaceFrom.ToNeededCoordinateSpace(); |
|||
} |
|||
} |
|||
} |
|
|||
using System.Collections.Generic; |
|||
using UnityEditor.MaterialGraph.Drawing.Controls; |
|||
using UnityEngine.MaterialGraph; |
|||
using UnityEngine.Graphing; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Constants")] |
|||
public class ConstantsNode : 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 = "Constant"; |
|||
|
|||
[EnumControl("")] |
|||
public ConstantType constant |
|||
{ |
|||
get { return m_constant; } |
|||
set |
|||
{ |
|||
if (m_constant == value) |
|||
return; |
|||
|
|||
m_constant = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public ConstantsNode() |
|||
{ |
|||
name = "MathConstant"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(new Vector1MaterialSlot(kOutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, 0)); |
|||
RemoveSlotsNameNotMatching(new[] { kOutputSlotId }); |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_constantList[constant] + ";", true); |
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine.Graphing; |
|||
using System.Collections.Generic; |
|||
using UnityEditor.MaterialGraph.Drawing.Controls; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Vector/Transform")] |
|||
public class TransformNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequireTangent, IMayRequireBitangent, IMayRequireNormal |
|||
{ |
|||
[SerializeField] |
|||
private SimpleMatrixType m_spaceListFrom; |
|||
[SerializeField] |
|||
private SimpleMatrixType m_spaceListTo; |
|||
|
|||
private const int InputSlotId = 0; |
|||
private const int OutputSlotId = 1; |
|||
private const string kInputSlotName = "Input"; |
|||
private const string kOutputSlotName = "Output"; |
|||
|
|||
[EnumControl("From")] |
|||
public SimpleMatrixType spaceFrom |
|||
{ |
|||
get { return m_spaceListFrom; } |
|||
set |
|||
{ |
|||
if (m_spaceListFrom == value) |
|||
return; |
|||
|
|||
m_spaceListFrom = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public override bool hasPreview |
|||
{ |
|||
get { return false; } |
|||
} |
|||
|
|||
[EnumControl("To")] |
|||
public SimpleMatrixType spaceTo |
|||
{ |
|||
get { return m_spaceListTo; } |
|||
set |
|||
{ |
|||
if (m_spaceListTo == value) |
|||
return; |
|||
|
|||
m_spaceListTo = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public TransformNode() |
|||
{ |
|||
name = "Transform"; |
|||
UpdateNodeAfterDeserialization(); |
|||
} |
|||
|
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
{ |
|||
AddSlot(GetInputSlot()); |
|||
AddSlot(GetOutputSlot()); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] {InputSlotId, OutputSlotId}; } |
|||
} |
|||
|
|||
protected virtual MaterialSlot GetInputSlot() |
|||
{ |
|||
return new Vector3MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotName, SlotType.Input, Vector3.zero); |
|||
} |
|||
|
|||
protected virtual MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new Vector3MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotName, SlotType.Output, Vector4.zero); |
|||
} |
|||
|
|||
protected virtual string GetInputSlotName() |
|||
{ |
|||
return "Input"; |
|||
} |
|||
|
|||
protected virtual string GetOutputSlotName() |
|||
{ |
|||
return "Output"; |
|||
} |
|||
|
|||
public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode) |
|||
{ |
|||
NodeUtils.SlotConfigurationExceptionIfBadConfiguration(this, new[] { InputSlotId }, new[] { OutputSlotId }); |
|||
string inputValue = GetSlotValue(InputSlotId, generationMode); |
|||
string transformString = ""; |
|||
bool requiresTangentTransform = false; |
|||
|
|||
if (spaceFrom == SimpleMatrixType.World) |
|||
{ |
|||
if (spaceTo == SimpleMatrixType.World) |
|||
{ |
|||
transformString = inputValue; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.Local) |
|||
{ |
|||
transformString = "mul(unity_WorldToObject, float4(" + inputValue + ", 0)).xyz"; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.Tangent) |
|||
{ |
|||
requiresTangentTransform = true; |
|||
transformString = "mul(tangentTransform, " + inputValue + ").xyz"; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.View) |
|||
{ |
|||
transformString = "mul( UNITY_MATRIX_V, float4(" + inputValue + ", 0)).xyz"; |
|||
} |
|||
} |
|||
else if (spaceFrom == SimpleMatrixType.Local) |
|||
{ |
|||
if (spaceTo == SimpleMatrixType.World) |
|||
{ |
|||
transformString = "mul(unity_ObjectToWorld, float4(" + inputValue + ", 0)).xyz"; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.Local) |
|||
{ |
|||
transformString = inputValue; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.Tangent) |
|||
{ |
|||
requiresTangentTransform = true; |
|||
transformString = "mul( tangentTransform, mul( unity_ObjectToWorld, float4(" + inputValue + ", 0) ).xyz).xyz"; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.View) |
|||
{ |
|||
transformString = "mul( UNITY_MATRIX_MV, float4(" + inputValue + ", 0)).xyz"; |
|||
} |
|||
} |
|||
else if (spaceFrom == SimpleMatrixType.Tangent) |
|||
{ |
|||
requiresTangentTransform = true; |
|||
if (spaceTo == SimpleMatrixType.World) |
|||
{ |
|||
transformString = "mul( " + inputValue + ", tangentTransform ).xyz"; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.Local) |
|||
{ |
|||
transformString = "mul( unity_WorldToObject, float4(mul(" + inputValue + ", tangentTransform ),0) ).xyz"; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.Tangent) |
|||
{ |
|||
transformString = inputValue; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.View) |
|||
{ |
|||
transformString = "mul( UNITY_MATRIX_V, float4(mul(" + inputValue + ", tangentTransform ),0) ).xyz"; |
|||
} |
|||
} |
|||
else if (spaceFrom == SimpleMatrixType.View) |
|||
{ |
|||
if (spaceTo == SimpleMatrixType.World) |
|||
{ |
|||
transformString = "mul( float4(" + inputValue + ", 0), UNITY_MATRIX_V ).xyz"; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.Local) |
|||
{ |
|||
transformString = "mul( float4(" + inputValue + ", 0), UNITY_MATRIX_MV ).xyz"; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.Tangent) |
|||
{ |
|||
requiresTangentTransform = true; |
|||
transformString = "mul( tangentTransform, mul( float4(" + inputValue + ", 0), UNITY_MATRIX_V ).xyz ).xyz"; |
|||
} |
|||
else if (spaceTo == SimpleMatrixType.View) |
|||
{ |
|||
transformString = inputValue; |
|||
} |
|||
} |
|||
|
|||
if (requiresTangentTransform) |
|||
visitor.AddShaderChunk("float3x3 tangentTransform = float3x3( worldSpaceTangent, worldSpaceBitangent, worldSpaceNormal);", false); |
|||
|
|||
visitor.AddShaderChunk(string.Format("{0} {1} = {2};", |
|||
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType), |
|||
GetVariableNameForSlot(OutputSlotId), |
|||
transformString), true); |
|||
} |
|||
|
|||
//float3x3 tangentTransform = float3x3( i.tangentDir, i.bitangentDir, i.normalDir);------
|
|||
|
|||
//mul(unity_WorldToObject, float4(i.posWorld.rgb,0) ).xyz - world to local---------
|
|||
//mul( tangentTransform, i.posWorld.rgb ).xyz - world to tangent-----------------
|
|||
//mul( UNITY_MATRIX_V, float4(i.posWorld.rgb,0) ).xyz - world to view-------------
|
|||
|
|||
//mul( unity_ObjectToWorld, float4(i.posWorld.rgb,0) ).xyz - local to world--------
|
|||
//mul( tangentTransform, mul( unity_ObjectToWorld, float4(i.posWorld.rgb,0) ).xyz - local to tangent------------
|
|||
//mul( UNITY_MATRIX_MV, float4(i.posWorld.rgb,0) ).xyz - local to view--------------
|
|||
|
|||
//mul( i.posWorld.rgb, tangentTransform ).xyz - tangent to world---------
|
|||
//mul( unity_WorldToObject, float4(mul( i.posWorld.rgb, tangentTransform ),0) ).xyz - tangent to local-----
|
|||
//mul( UNITY_MATRIX_V, float4(mul( i.posWorld.rgb, tangentTransform ),0) ).xyz - tangent to view-------
|
|||
|
|||
//mul( float4(i.posWorld.rgb,0), UNITY_MATRIX_V ).xyz - view to world
|
|||
//mul( float4(i.posWorld.rgb,0), UNITY_MATRIX_MV ).xyz - view to local
|
|||
//mul( tangentTransform, mul( float4(i.posWorld.rgb,0), UNITY_MATRIX_V ).xyz ).xyz - view to tangent
|
|||
|
|||
public NeededCoordinateSpace RequiresTangent() |
|||
{ |
|||
return NeededCoordinateSpace.World; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresBitangent() |
|||
{ |
|||
return NeededCoordinateSpace.World; |
|||
} |
|||
|
|||
public NeededCoordinateSpace RequiresNormal() |
|||
{ |
|||
return NeededCoordinateSpace.World; |
|||
} |
|||
} |
|||
} |
|
|||
using System.Reflection; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
{ |
|||
[Title("Math/Vector/Cross Product")] |
|||
public class CrossNode : CodeFunctionNode |
|||
{ |
|||
public CrossNode() |
|||
{ |
|||
name = "CrossProduct"; |
|||
} |
|||
|
|||
protected override MethodInfo GetFunctionToConvert() |
|||
{ |
|||
return GetType().GetMethod("Unity_CrossProduct", BindingFlags.Static | BindingFlags.NonPublic); |
|||
} |
|||
|
|||
static string Unity_CrossProduct( |
|||
[Slot(0, Binding.None)] DynamicDimensionVector first, |
|||
[Slot(1, Binding.None)] DynamicDimensionVector second, |
|||
[Slot(2, Binding.None)] out DynamicDimensionVector result) |
|||
{ |
|||
return |
|||
@"
|
|||
{ |
|||
result = cross(first, second); |
|||
} |
|||
";
|
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue