浏览代码

Merge pull request #261 from Unity-Technologies/fix-constant-node

Fix Constant Node code gen
/main
GitHub 7 年前
当前提交
40495e65
共有 6 个文件被更改,包括 22 次插入11 次删除
  1. 10
      com.unity.shadergraph/Editor/Data/Nodes/Channel/SwizzleNode.cs
  2. 3
      com.unity.shadergraph/Editor/Data/Nodes/Input/Basic/ConstantNode.cs
  3. 3
      com.unity.shadergraph/Editor/Data/Nodes/Input/Matrix/TransformationMatrixNode.cs
  4. 3
      com.unity.shadergraph/Editor/Data/Nodes/Input/PBR/DielectricSpecularNode.cs
  5. 3
      com.unity.shadergraph/Editor/Data/Nodes/Input/PBR/MetalReflectanceNode.cs
  6. 11
      com.unity.shadergraph/Editor/Drawing/PreviewManager.cs

10
com.unity.shadergraph/Editor/Data/Nodes/Channel/SwizzleNode.cs


using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;

if (inputValueType == ConcreteSlotValueType.Vector1)
visitor.AddShaderChunk(string.Format("{0} {1} = {2};", outputSlotType, outputName, inputValue), false);
else if (generationMode == GenerationMode.ForReals)
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.{3}{4}{5}{6};", outputSlotType, outputName, inputValue, s_ComponentList[m_RedChannel], s_ComponentList[m_GreenChannel], s_ComponentList[m_BlueChannel], s_ComponentList[m_AlphaChannel]), false);
visitor.AddShaderChunk(string.Format("{0} {1} = {2}.{3}{4}{5}{6};",
outputSlotType,
outputName,
inputValue,
s_ComponentList[m_RedChannel].ToString(CultureInfo.InvariantCulture),
s_ComponentList[m_GreenChannel].ToString(CultureInfo.InvariantCulture),
s_ComponentList[m_BlueChannel].ToString(CultureInfo.InvariantCulture),
s_ComponentList[m_AlphaChannel].ToString(CultureInfo.InvariantCulture)), false);
else
visitor.AddShaderChunk(string.Format("{0} {1} = {0}({3}[((int){2} >> 0) & 3], {3}[((int){2} >> 2) & 3], {3}[((int){2} >> 4) & 3], {3}[((int){2} >> 6) & 3]);",
outputSlotType,

3
com.unity.shadergraph/Editor/Data/Nodes/Input/Basic/ConstantNode.cs


using System.Collections.Generic;
using System.Globalization;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;
using UnityEditor.Graphing;

public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_constantList[constant] + ";", true);
visitor.AddShaderChunk(precision + " " + GetVariableNameForNode() + " = " + m_constantList[constant].ToString(CultureInfo.InvariantCulture) + ";", true);
}
public override string GetVariableNameForSlot(int slotId)

3
com.unity.shadergraph/Editor/Data/Nodes/Input/Matrix/TransformationMatrixNode.cs


using UnityEditor.Graphing;
using System.Collections.Generic;
using System.Globalization;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;

public override string GetVariableNameForSlot(int slotId)
{
return m_matrixList[matrix];
return m_matrixList[matrix].ToString(CultureInfo.InvariantCulture);
}
public bool RequiresVertexColor()

3
com.unity.shadergraph/Editor/Data/Nodes/Input/PBR/DielectricSpecularNode.cs


using System;
using System.Collections.Generic;
using System.Globalization;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;
using UnityEngine;

sb.AppendLine("{0}3 {1} = pow(_{2}_IOR - 1, 2) / pow(_{2}_IOR + 1, 2);", precision, GetVariableNameForSlot(kOutputSlotId), GetVariableNameForNode());
break;
default:
sb.AppendLine("{0}3 {1} = {0}3{2};", precision, GetVariableNameForSlot(kOutputSlotId), m_MaterialList[material.type]);
sb.AppendLine("{0}3 {1} = {0}3{2};", precision, GetVariableNameForSlot(kOutputSlotId), m_MaterialList[material.type].ToString(CultureInfo.InvariantCulture));
break;
}
visitor.AddShaderChunk(sb.ToString(), false);

3
com.unity.shadergraph/Editor/Data/Nodes/Input/PBR/MetalReflectanceNode.cs


using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEditor.Graphing;
using UnityEditor.ShaderGraph.Drawing.Controls;

public void GenerateNodeCode(ShaderGenerator visitor, GenerationMode generationMode)
{
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3{2};", precision, GetVariableNameForSlot(kOutputSlotId), m_MaterialList[material]), true);
visitor.AddShaderChunk(string.Format("{0}3 {1} = {0}3{2};", precision, GetVariableNameForSlot(kOutputSlotId), m_MaterialList[material].ToString(CultureInfo.InvariantCulture)), true);
}
}
}

11
com.unity.shadergraph/Editor/Drawing/PreviewManager.cs


try
{
node = results.sourceMap.FindNode(error.line);
message.AppendLine("Shader compilation error in {3} at line {1} (on {2}):\n{0}", error.message, error.line, error.platform, node != null ? string.Format("node {0} ({1})", node.name, node.guid) : "graph");
message.AppendLine(error.messageDetails);
message.AppendNewLine();
catch (Exception e)
catch
Debug.LogException(e);
continue;
message.AppendLine("Shader compilation error in {3} at line {1} (on {2}):\n{0}", error.message, error.line, error.platform, "graph");
message.AppendLine("{0} in {3} at line {1} (on {2})", error.message, error.line, error.platform, node != null ? string.Format("node {0} ({1})", node.name, node.guid) : "graph");
message.AppendLine(error.messageDetails);
message.AppendNewLine();
}
Debug.LogWarning(message.ToString());
ShaderUtil.ClearShaderErrors(m_UberShader);

正在加载...
取消
保存