浏览代码

Merge pull request #187 from Unity-Technologies/node-bugfixes

Node bugfixes
/main
GitHub 7 年前
当前提交
df1a52fd
共有 3 个文件被更改,包括 16 次插入18 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/ScreenPositionNode.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/FogNode.cs
  3. 30
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TransformNode.cs

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Geometry/ScreenPositionNode.cs


visitor.AddShaderChunk(string.Format("{0}4 {1} = {2};", precision, GetVariableNameForSlot(kOutputSlotId),
string.Format("float4((IN.{0}.xy / IN.{0}.w) * 2 - 1, 0, 0)", ShaderGeneratorNames.ScreenPosition)), true);
visitor.AddShaderChunk(string.Format("{0} = {1};", GetVariableNameForSlot(kOutputSlotId),
string.Format("float4({0}.x * _ScreenParams.x / _ScreenParams.y, {0}.y, 0, 0)", GetVariableNameForSlot(kOutputSlotId))), true);
string.Format("frac(float4({0}.x * _ScreenParams.x / _ScreenParams.y, {0}.y, 0, 0))", GetVariableNameForSlot(kOutputSlotId))), true);
break;
default:
visitor.AddShaderChunk(string.Format("{0}4 {1} = {2};", precision, GetVariableNameForSlot(kOutputSlotId),

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Scene/FogNode.cs


{
s.AppendLine("Color = unity_FogColor;");
s.AppendLine("{0} clipZ_01 = UNITY_Z_0_FAR_FROM_CLIPSPACE(UnityObjectToClipPos(ObjectSpacePosition).z);", precision);
s.AppendLine("{0} clipZ_01 = UNITY_Z_0_FAR_FROM_CLIPSPACE(mul(GetWorldToHClipMatrix(), mul(GetObjectToWorldMatrix(), ObjectSpacePosition)).z);", precision);
s.AppendLine("#if defined(FOG_LINEAR)");
using (s.IndentScope())
{

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


}
else if (conversion.to == CoordinateSpace.Object)
{
transformString = "mul(unity_WorldToObject, float4(" + inputValue + ", 0)).xyz";
transformString = string.Format("TransformWorldToObject({0})", inputValue);
transformString = "mul(" + inputValue + ", " + targetTransformString + ").xyz";
transformString = string.Format("TransformWorldToTangent({0}, {1})", inputValue, targetTransformString);
transformString = "mul( UNITY_MATRIX_V, float4(" + inputValue + ", 0)).xyz";
transformString = string.Format("TransformWorldToView({0})", inputValue);
}
}
else if (conversion.from == CoordinateSpace.Object)

transformString = "mul(unity_ObjectToWorld, float4(" + inputValue + ", 0)).xyz";
transformString = string.Format("TransformObjectToWorld({0})", inputValue);
}
else if (conversion.to == CoordinateSpace.Object)
{

{
requiresTangentTransform = true;
transformString = "mul(float4(" + inputValue + ", 0).xyz, " + targetTransformString + ").xyz";
transformString = string.Format("TransformWorldToTangent(TransformObjectToWorld({0}), {1})", inputValue, targetTransformString);
transformString = "mul( UNITY_MATRIX_MV, float4(" + inputValue + ", 0)).xyz";
transformString = string.Format("TransformWorldToView(TransformObjectToWorld({0}))", inputValue);
}
}
else if (conversion.from == CoordinateSpace.Tangent)

requiresTransposeTangentTransform = true;
transformString = "mul( " + inputValue + ", " + transposeTargetTransformString + " ).xyz";
transformString = string.Format("mul({0}, {1}).xyz", inputValue, transposeTargetTransformString);
transformString = "mul( unity_WorldToObject, float4(mul(" + inputValue + ", " + transposeTargetTransformString + " ),0) ).xyz";
transformString = string.Format("TransformWorldToObject(mul({0}, {1}).xyz)", inputValue, transposeTargetTransformString);
}
else if (conversion.to == CoordinateSpace.Tangent)
{

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

transformString = "mul( float4(" + inputValue + ", 0), UNITY_MATRIX_V ).xyz";
transformString = string.Format("mul(UNITY_MATRIX_I_V, float4({0}, 1)).xyz", inputValue);
transformString = "mul( float4(" + inputValue + ", 0), UNITY_MATRIX_MV ).xyz";
transformString = string.Format("TransformWorldToObject(mul(UNITY_MATRIX_I_V, float4({0}, 1) ).xyz)", inputValue);
transformString = "mul( mul( float4(" + inputValue + ", 0), UNITY_MATRIX_V ).xyz, " + targetTransformString + ").xyz";
transformString = string.Format("TransformWorldToTangent(mul(UNITY_MATRIX_I_V, float4({0}, 1) ).xyz, {1})", inputValue, targetTransformString);
}
else if (conversion.to == CoordinateSpace.View)
{

visitor.AddShaderChunk("float3x3 " + transposeTargetTransformString + " = transpose(float3x3(" + CoordinateSpace.World.ToString() + "SpaceTangent, " + CoordinateSpace.World.ToString() + "SpaceBiTangent, " + CoordinateSpace.World.ToString() + "SpaceNormal));", true);
visitor.AddShaderChunk(string.Format("float3x3 {0} = transpose(float3x3(IN.{1}SpaceTangent, IN.{1}SpaceBiTangent, IN.{1}SpaceNormal));", transposeTargetTransformString, CoordinateSpace.World.ToString()), true);
visitor.AddShaderChunk("float3x3 " + targetTransformString + " = float3x3(" + tangentTransformSpace + "SpaceTangent, " + tangentTransformSpace + "SpaceBiTangent, " + tangentTransformSpace + "SpaceNormal);", true);
visitor.AddShaderChunk(string.Format("float3x3 {0} = CreateWorldToTangent(IN.{1}SpaceNormal, IN.{1}SpaceTangent, 1);", targetTransformString, tangentTransformSpace), true);
visitor.AddShaderChunk(string.Format("{0} {1} = {2};", NodeUtils.ConvertConcreteSlotValueTypeToString(precision, FindOutputSlot<MaterialSlot>(OutputSlotId).concreteValueType),
GetVariableNameForSlot(OutputSlotId),
transformString), true);

正在加载...
取消
保存