浏览代码

Transform node fixes

/main
Matt Dean 7 年前
当前提交
9fcf8bc7
共有 1 个文件被更改,包括 37 次插入28 次删除
  1. 65
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TransformNode.cs

65
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TransformNode.cs


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);
AddSlot(new Vector3MaterialSlot(InputSlotId, kInputSlotName, kInputSlotName, SlotType.Input, Vector3.zero));
AddSlot(new Vector3MaterialSlot(OutputSlotId, kOutputSlotName, kOutputSlotName, SlotType.Output, Vector3.zero));
RemoveSlotsNameNotMatching(new[] { InputSlotId, OutputSlotId });
string inputValue = GetSlotValue(InputSlotId, generationMode);
string inputValue = string.Format("{0}.xyz", GetSlotValue(InputSlotId, generationMode));
string targetTransformString = "tangentTransform_" + conversion.from.ToString();
string transposeTargetTransformString = "transposeTangent";
string tangentTransformSpace = conversion.from.ToString();
bool requiresTransposeTangentTransform = false;
if (conversion.from == CoordinateSpace.World)
{

else if (conversion.to == CoordinateSpace.Tangent)
{
requiresTangentTransform = true;
transformString = "mul(tangentTransform, " + inputValue + ").xyz";
transformString = "mul(" + inputValue + ", " + targetTransformString + ").xyz";
}
else if (conversion.to == CoordinateSpace.View)
{

else if (conversion.to == CoordinateSpace.Tangent)
{
requiresTangentTransform = true;
transformString = "mul( tangentTransform, mul( unity_ObjectToWorld, float4(" + inputValue + ", 0) ).xyz).xyz";
transformString = "mul(float4(" + inputValue + ", 0).xyz, " + targetTransformString + ").xyz";
}
else if (conversion.to == CoordinateSpace.View)
{

else if (conversion.from == CoordinateSpace.Tangent)
{
requiresTangentTransform = true;
transformString = "mul( " + inputValue + ", tangentTransform ).xyz";
requiresTransposeTangentTransform = true;
transformString = "mul( " + inputValue + ", " + transposeTargetTransformString + " ).xyz";
transformString = "mul( unity_WorldToObject, float4(mul(" + inputValue + ", tangentTransform ),0) ).xyz";
requiresTransposeTangentTransform = true;
transformString = "mul( unity_WorldToObject, float4(mul(" + inputValue + ", " + transposeTargetTransformString + " ),0) ).xyz";
}
else if (conversion.to == CoordinateSpace.Tangent)
{

{
transformString = "mul( UNITY_MATRIX_V, float4(mul(" + inputValue + ", tangentTransform ),0) ).xyz";
requiresTransposeTangentTransform = true;
transformString = "mul( UNITY_MATRIX_V, float4(mul(" + inputValue + ", " + transposeTargetTransformString + " ),0) ).xyz";
}
}
else if (conversion.from == CoordinateSpace.View)

else if (conversion.to == CoordinateSpace.Tangent)
{
requiresTangentTransform = true;
transformString = "mul( tangentTransform, mul( float4(" + inputValue + ", 0), UNITY_MATRIX_V ).xyz ).xyz";
tangentTransformSpace = CoordinateSpace.World.ToString();
transformString = "mul( mul( float4(" + inputValue + ", 0), UNITY_MATRIX_V ).xyz, " + targetTransformString + ").xyz";
}
else if (conversion.to == CoordinateSpace.View)
{

if (requiresTangentTransform)
visitor.AddShaderChunk("float3x3 tangentTransform = float3x3(" + conversion.from.ToString() + "SpaceTangent, " + conversion.from.ToString() + "SpaceBiTangent, " + conversion.from.ToString() + "SpaceNormal);", false);
if (requiresTransposeTangentTransform)
visitor.AddShaderChunk("float3x3 " + transposeTargetTransformString + " = transpose(float3x3(" + CoordinateSpace.World.ToString() + "SpaceTangent, " + CoordinateSpace.World.ToString() + "SpaceBiTangent, " + CoordinateSpace.World.ToString() + "SpaceNormal));", true);
else if (requiresTangentTransform)
visitor.AddShaderChunk("float3x3 " + targetTransformString + " = float3x3(" + tangentTransformSpace + "SpaceTangent, " + tangentTransformSpace + "SpaceBiTangent, " + tangentTransformSpace + "SpaceNormal);", true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2};",
ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType),

bool RequiresWorldSpaceTangentTransform()
{
if (conversion.from == CoordinateSpace.View && conversion.to == CoordinateSpace.Tangent
|| conversion.from == CoordinateSpace.Tangent)
return true;
else
return false;
}
if(RequiresWorldSpaceTangentTransform())
return NeededCoordinateSpace.World;
if (RequiresWorldSpaceTangentTransform())
return NeededCoordinateSpace.World;
if (RequiresWorldSpaceTangentTransform())
return NeededCoordinateSpace.World;
return conversion.from.ToNeededCoordinateSpace();
}
}
正在加载...
取消
保存