当前提交
45075517
共有 3 个文件被更改,包括 191 次插入 和 19 次删除
-
8MaterialGraphProject/Assets/Andre/Nodes/Editor/TransformNodePresenter.cs
-
194MaterialGraphProject/Assets/Andre/Nodes/TransformNode.cs
-
8MaterialGraphProject/Assets/Matt/CommonMatrixType.cs
|
|||
namespace UnityEngine.MaterialGraph |
|||
using UnityEngine.Graphing; |
|||
using System.Collections.Generic; |
|||
|
|||
namespace UnityEngine.MaterialGraph |
|||
public class TransformNode : Function1Input |
|||
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"; |
|||
|
|||
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; } |
|||
} |
|||
|
|||
public SimpleMatrixType spaceTo |
|||
{ |
|||
get { return m_spaceListTo; } |
|||
set |
|||
{ |
|||
if (m_spaceListTo == value) |
|||
return; |
|||
|
|||
m_spaceListTo = value; |
|||
if (onModified != null) |
|||
{ |
|||
onModified(this, ModificationScope.Graph); |
|||
} |
|||
} |
|||
} |
|||
|
|||
UpdateNodeAfterDeserialization (); |
|||
protected override string GetFunctionName () |
|||
public sealed override void UpdateNodeAfterDeserialization() |
|||
AddSlot(GetInputSlot()); |
|||
AddSlot(GetOutputSlot()); |
|||
RemoveSlotsNameNotMatching(validSlots); |
|||
} |
|||
//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
|
|||
protected int[] validSlots |
|||
{ |
|||
get { return new[] {InputSlotId, OutputSlotId}; } |
|||
} |
|||
//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
|
|||
protected virtual MaterialSlot GetInputSlot() |
|||
{ |
|||
return new MaterialSlot(InputSlotId, GetInputSlotName(), kInputSlotName, SlotType.Input, SlotValueType.Vector3, Vector3.zero); |
|||
} |
|||
//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
|
|||
protected virtual MaterialSlot GetOutputSlot() |
|||
{ |
|||
return new MaterialSlot(OutputSlotId, GetOutputSlotName(), kOutputSlotName, SlotType.Output, SlotValueType.Vector3, Vector4.zero); |
|||
} |
|||
//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
|
|||
protected virtual string GetInputSlotName() |
|||
{ |
|||
return "Input"; |
|||
} |
|||
return "exp"; |
|||
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(precision + outputDimension + " " + 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 string outputDimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType); } |
|||
} |
|||
private string inputDimension |
|||
{ |
|||
get { return ConvertConcreteSlotValueTypeToString(FindInputSlot<MaterialSlot>(InputSlotId).concreteValueType); } |
|||
} |
|||
|
|||
public bool RequiresTangent() |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
public bool RequiresBitangent() |
|||
{ |
|||
return true; |
|||
} |
|||
|
|||
public bool RequiresNormal(){ |
|||
return true; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue