浏览代码

[FIX] #159 Added a utility node method for converting float to shader value. To catch Infinity text string.

/main
Martin Thorzen 7 年前
当前提交
29920efb
共有 10 个文件被更改,包括 36 次插入10 次删除
  1. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector1MaterialSlot.cs
  3. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2MaterialSlot.cs
  4. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3MaterialSlot.cs
  5. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4MaterialSlot.cs
  6. 15
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Implementation/NodeUtils.cs
  7. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector1Node.cs
  8. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector2Node.cs
  9. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector3Node.cs
  10. 9
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector4Node.cs

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/DynamicVectorMaterialSlot.cs


protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
var channelCount = SlotValueHelper.GetChannelCount(concreteValueType);
var values = value.x.ToString();
string values = NodeUtils.FloatToShaderValue(value.x);
if (channelCount == 1)
return values;
for (var i = 1; i < channelCount; i++)

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector1MaterialSlot.cs


protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return value.ToString();
return NodeUtils.FloatToShaderValue(value);
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector2MaterialSlot.cs


protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "2 (" + value.x + "," + value.y + ")";
return precision + "2 (" + NodeUtils.FloatToShaderValue(value.x) + "," + NodeUtils.FloatToShaderValue(value.y) + ")";
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector3MaterialSlot.cs


protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "3 (" + value.x + "," + value.y + "," + value.z + ")";
return precision + "3 (" + NodeUtils.FloatToShaderValue(value.x) + "," + NodeUtils.FloatToShaderValue(value.y) + "," + NodeUtils.FloatToShaderValue(value.z) + ")";
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Graphs/Vector4MaterialSlot.cs


protected override string ConcreteSlotValueAsVariable(AbstractMaterialNode.OutputPrecision precision)
{
return precision + "4 (" + value.x + "," + value.y + "," + value.z + "," + value.w + ")";
return precision + "4 (" + NodeUtils.FloatToShaderValue(value.x) + "," + NodeUtils.FloatToShaderValue(value.y) + "," + NodeUtils.FloatToShaderValue(value.z) + "," + NodeUtils.FloatToShaderValue(value.w) + ")";
}
public override void AddDefaultProperty(PropertyCollector properties, GenerationMode generationMode)

15
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Implementation/NodeUtils.cs


using System.Collections.Generic;
using System.Linq;
using UnityEditor.ShaderGraph;
using UnityEngine;
namespace UnityEditor.Graphing
{

var toPrint = missingSlots.Select(x => x.ToString());
throw new SlotConfigurationException(string.Format("Missing slots {0} on node {1}", string.Join(", ", toPrint.ToArray()), node));
throw new SlotConfigurationException(String.Format("Missing slots {0} on node {1}", String.Join(", ", toPrint.ToArray()), node));
}
public static IEnumerable<IEdge> GetAllEdges(INode node)

char[] arr = input.ToCharArray();
arr = Array.FindAll<char>(arr, (c => (Char.IsLetterOrDigit(c))));
return new string(arr);
}
public static string FloatToShaderValue(float value)
{
if (Single.IsPositiveInfinity(value))
return "1.#INF";
else if (Single.IsNegativeInfinity(value))
return "-1.#INF";
else if (Single.IsNaN(value))
return "NAN";
else
return value.ToString();
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector1Node.cs


if (generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_Value + ";", true);
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + NodeUtils.FloatToShaderValue(m_Value) + ";", true);
}
public override string GetVariableNameForSlot(int slotId)

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector2Node.cs


if (generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "2 " + GetVariableNameForNode() + " = " + precision + "2" + m_Value + ";", true);
visitor.AddShaderChunk(string.Format("{0}2 {1} = {0}2({2},{3});", precision, GetVariableNameForNode(), NodeUtils.FloatToShaderValue(m_Value.x), NodeUtils.FloatToShaderValue(m_Value.y)), true);
}
public override string GetVariableNameForSlot(int slotId)

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector3Node.cs


if (generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "3 " + GetVariableNameForNode() + " = " + precision + "3" + m_Value + ";", true);
var s = string.Format("{0}3 {1} = {0}3({2},{3},{4});",
precision,
GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Value.x),
NodeUtils.FloatToShaderValue(m_Value.y),
NodeUtils.FloatToShaderValue(m_Value.z));
visitor.AddShaderChunk(s, true);
}
public override string GetVariableNameForSlot(int slotId)

9
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Data/Nodes/Input/Basic/Vector4Node.cs


if (generationMode.IsPreview())
return;
visitor.AddShaderChunk(precision + "4 " + GetVariableNameForNode() + " = " + precision + "4" + m_Value + ";", true);
var s = string.Format("{0}4 {1} = {0}4({2},{3},{4},{5});",
precision,
GetVariableNameForNode(),
NodeUtils.FloatToShaderValue(m_Value.x),
NodeUtils.FloatToShaderValue(m_Value.y),
NodeUtils.FloatToShaderValue(m_Value.z),
NodeUtils.FloatToShaderValue(m_Value.w));
visitor.AddShaderChunk(s, true);
}
public override string GetVariableNameForSlot(int slotId)

正在加载...
取消
保存