浏览代码

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

Node bugfixes
/main
GitHub 7 年前
当前提交
91b5a7ad
共有 7 个文件被更改,包括 131 次插入43 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Math/Vector/TransformNode.cs
  2. 128
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/UV/TriplanarNode.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/IsNanNode.cs
  4. 11
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/GraphEditorView.uss
  5. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss
  6. 14
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/PortInputView.uss
  7. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/ShaderPort.uss

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


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

128
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/UV/TriplanarNode.cs


namespace UnityEditor.ShaderGraph
{
[Title("UV", "Triplanar")]
public class TriplanarNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequirePosition, IMayRequireNormal
public class TriplanarNode : AbstractMaterialNode, IGeneratesBodyCode, IMayRequirePosition, IMayRequireNormal, IMayRequireTangent, IMayRequireBitangent
{
public const int OutputSlotId = 0;
public const int TextureInputId = 1;

sb.AppendLine("{0}3 {1}_UV = {2} * {3};", precision, GetVariableNameForNode(),
GetSlotValue(PositionInputId, generationMode), GetSlotValue(TileInputId, generationMode));
sb.AppendLine("{0}3 {1}_Blend = pow(abs({2}), {3});", precision, GetVariableNameForNode(),
GetSlotValue(NormalInputId, generationMode), GetSlotValue(BlendInputId, generationMode));
sb.AppendLine("{0}_Blend /= dot({0}_Blend, 1.0);", GetVariableNameForNode());
sb.AppendLine("{0}4 {1}_X = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.yz);"
, precision
, GetVariableNameForNode()
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
sb.AppendLine("{0}4 {1}_Y = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.xz);"
, precision
, GetVariableNameForNode()
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
switch(textureType)
{
// Whiteout blend method
// https://medium.com/@bgolus/normal-mapping-for-a-triplanar-shader-10bf39dca05a
case TextureType.Normal:
sb.AppendLine("{0}3 {1}_Blend = max(pow(abs({2}), {3}), 0);", precision, GetVariableNameForNode(),
GetSlotValue(NormalInputId, generationMode), GetSlotValue(BlendInputId, generationMode));
sb.AppendLine("{0}_Blend /= ({0}_Blend.x + {0}_Blend.y + {0}_Blend.z ).xxx;", GetVariableNameForNode());
sb.AppendLine("{0}3 {1}_X = UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.zy));"
, precision
, GetVariableNameForNode()
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
sb.AppendLine("{0}3 {1}_Y = UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.xz));"
, precision
, GetVariableNameForNode()
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
sb.AppendLine("{0}4 {1}_Z = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.xy);"
, precision
, GetVariableNameForNode()
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
sb.AppendLine("{0}3 {1}_Z = UnpackNormalmapRGorAG(SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.xy));"
, precision
, GetVariableNameForNode()
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
sb.AppendLine("{0}4 {1} = {2}_X * {2}_Blend.x + {2}_Y * {2}_Blend.y + {2}_Z * {2}_Blend.z;"
, precision
, GetVariableNameForSlot(OutputSlotId)
, GetVariableNameForNode());
sb.AppendLine("{0}_X = {1}3({0}_X.xy + {2}.zy, abs({0}_X.z) * {2}.x);"
, GetVariableNameForNode()
, precision
, GetSlotValue(NormalInputId, generationMode));
if (textureType == TextureType.Normal)
sb.AppendLine("{0}.rgb = UnpackNormalmapRGorAG({0});", GetVariableNameForSlot(OutputSlotId));
sb.AppendLine("{0}_Y = {1}3({0}_Y.xy + {2}.xz, abs({0}_Y.z) * {2}.y);"
, GetVariableNameForNode()
, precision
, GetSlotValue(NormalInputId, generationMode));
sb.AppendLine("{0}_Z = {1}3({0}_Z.xy + {2}.xy, abs({0}_Z.z) * {2}.z);"
, GetVariableNameForNode()
, precision
, GetSlotValue(NormalInputId, generationMode));
sb.AppendLine("{0}4 {1} = {0}4(normalize({2}_X.zyx * {2}_Blend.x + {2}_Y.xzy * {2}_Blend.y + {2}_Z.xyz * {2}_Blend.z), 1);"
, precision
, GetVariableNameForSlot(OutputSlotId)
, GetVariableNameForNode());
sb.AppendLine("float3x3 {0}_Transform = float3x3(IN.WorldSpaceTangent, IN.WorldSpaceBiTangent, IN.WorldSpaceNormal);", GetVariableNameForNode());
sb.AppendLine("{0}.rgb = TransformWorldToTangent({0}.rgb, {1}_Transform);"
, GetVariableNameForSlot(OutputSlotId)
, GetVariableNameForNode());
break;
default:
sb.AppendLine("{0}3 {1}_Blend = pow(abs({2}), {3});", precision, GetVariableNameForNode(),
GetSlotValue(NormalInputId, generationMode), GetSlotValue(BlendInputId, generationMode));
sb.AppendLine("{0}_Blend /= dot({0}_Blend, 1.0);", GetVariableNameForNode());
sb.AppendLine("{0}4 {1}_X = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.zy);"
, precision
, GetVariableNameForNode()
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
sb.AppendLine("{0}4 {1}_Y = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.xz);"
, precision
, GetVariableNameForNode()
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
sb.AppendLine("{0}4 {1}_Z = SAMPLE_TEXTURE2D({2}, {3}, {1}_UV.xy);"
, precision
, GetVariableNameForNode()
, id
, edgesSampler.Any() ? GetSlotValue(SamplerInputId, generationMode) : "sampler" + id);
sb.AppendLine("{0}4 {1} = {2}_X * {2}_Blend.x + {2}_Y * {2}_Blend.y + {2}_Z * {2}_Blend.z;"
, precision
, GetVariableNameForSlot(OutputSlotId)
, GetVariableNameForNode());
break;
}
public NeededCoordinateSpace RequiresPosition()
{
return CoordinateSpace.World.ToNeededCoordinateSpace();

{
return CoordinateSpace.World.ToNeededCoordinateSpace();
}
public NeededCoordinateSpace RequiresTangent()
{
switch(m_TextureType)
{
case TextureType.Normal:
return CoordinateSpace.World.ToNeededCoordinateSpace();
default:
return NeededCoordinateSpace.None;
}
}
public NeededCoordinateSpace RequiresBitangent()
{
switch(m_TextureType)
{
case TextureType.Normal:
return CoordinateSpace.World.ToNeededCoordinateSpace();
default:
return NeededCoordinateSpace.None;
}
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Utility/Logic/IsNanNode.cs


return
@"
{
Out = isnan(In);
Out = (In < 0.0 || In > 0.0 || In == 0.0) ? 0 : 1;
}
";
}

11
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/GraphEditorView.uss


edge-input-color: #8FC1DF;
}
.edge.fromTexture2D {
.edge.fromTexture2D, .edge.fromCubemap {
.edge.toTexture2D {
.edge.toTexture2D, .edge.toCubemap {
edge-input-color: #FF8B8B;
}

}
.edge.toVector1 {
edge-input-color: #84E4E7;
}
.edge.fromBoolean {
edge-output-color: #9481E6;
}
.edge.toBoolean {
edge-input-color: #9481E6;
}
#resizeBorderFrame > .resize {

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/MaterialGraph.uss


ScreenPositionSlotControlView > EnumField {
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
width: 54;
}

14
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/PortInputView.uss


edge-color: #8FC1DF;
}
PortInputView.typeTexture2D > #container > #slot > #dot {
PortInputView.typeTexture2D > #container > #slot > #dot,
PortInputView.typeCubemap > #container > #slot > #dot {
PortInputView.typeTexture2D {
PortInputView.typeTexture2D,
PortInputView.typeCubemap {
edge-color: #FF8B8B;
}

PortInputView.typeVector1 {
edge-color: #84E4E7;
}
PortInputView.typeBoolean > #container > #slot > #dot {
background-color: #9481E6;
}
PortInputView.typeBoolean {
edge-color: #9481E6;
}

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Resources/Styles/ShaderPort.uss


/* THIS FILE IS FROM GRAPHVIEW BUT CONTAINS MODIFICATIONS */
ShaderPort {
height: 24;
align-items: center;

port-color:#FF8B8B;
}
ShaderPort.typeCubemap {
/* Same as typeTexture */
port-color:#FF8B8B;
}
ShaderPort.typeGraphScript {
/* Todo: there is no such type in Unity atm */
port-color:#E681BA;

port-color:#9481E6;
}
ShaderPort.typeBool {
ShaderPort.typeBoolean {
port-color:#9481E6;
}

正在加载...
取消
保存