浏览代码

[material graph] Fix newline issues.

/main
Tim Cooper 8 年前
当前提交
95b250d2
共有 23 个文件被更改,包括 72 次插入68 次删除
  1. 3
      MaterialGraphProject/Assets/Canvas2D/Editor/Canvas2D.cs
  2. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/AbstractMaterialNodeUI.cs
  3. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs
  4. 17
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs
  5. 19
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs
  6. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialNodeTests.cs
  7. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs
  8. 8
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PixelShaderNodeTests.cs
  9. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs
  10. 3
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs
  11. 10
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Light/BaseLightFunction.cs
  12. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AddNode.cs
  13. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/BlendNode.cs
  14. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/CombineNode.cs
  15. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/DivNode.cs
  16. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/FresnelNode.cs
  17. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MultiplyNode.cs
  18. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/QuantizeNode.cs
  19. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ReflectNode.cs
  20. 2
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubtractNode.cs
  21. 4
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs
  22. 6
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyGenerator.cs
  23. 19
      MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs

3
MaterialGraphProject/Assets/Canvas2D/Editor/Canvas2D.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

{
if (logEvent)
{
m_DebugEventName += " handled by capture session\n";
m_DebugEventName += " handled by capture session" + Environment.NewLine;
}
evt.Use();
return true;

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Drawing/NodeDrawers/AbstractMaterialNodeUI.cs


return false;
var resultShader = GetPreviewShaderString();
Debug.Log("RecreateShaderAndMaterial : " + m_Node.GetVariableNameForNode() + "\n" + resultShader);
Debug.Log("RecreateShaderAndMaterial : " + m_Node.GetVariableNameForNode() + Environment.NewLine + resultShader);
if (string.IsNullOrEmpty(resultShader))
return false;

17
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function1InputTests.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
}

[Test]
public void TestGenerateNodeCodeGeneratesCorrectCode()
{
string expected = string.Format("half {0} = unity_test_half ({1});"
string expected = string.Format("half {0} = unity_test_half ({1});{2}"
, Environment.NewLine
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim());
Assert.AreEqual(expected, visitor.GetShaderString(0));
}
[Test]

"inline half unity_test_half (half arg)\r\n"
+ "{\r\n"
+ "\treturn arg;\r\n"
+ "}";
"inline half unity_test_half (half arg)" + Environment.NewLine
+ "{" + Environment.NewLine
+ "\treturn arg;" + Environment.NewLine
+ "}" + Environment.NewLine;
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim());
Assert.AreEqual(expected, visitor.GetShaderString(0));
}
}
}

17
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function2InputTests.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
}

[Test]
public void TestGenerateNodeCodeGeneratesCorrectCode()
{
string expected = string.Format("half {0} = unity_test_half ({1}, {2});"
string expected = string.Format("half {0} = unity_test_half ({1}, {2});{3}"
, Environment.NewLine
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim());
Assert.AreEqual(expected, visitor.GetShaderString(0));
}
[Test]

"inline half unity_test_half (half arg1, half arg2)\r\n"
+ "{\r\n"
+ "\treturn arg1 + arg2;\r\n"
+ "}";
"inline half unity_test_half (half arg1, half arg2)" + Environment.NewLine
+ "{" + Environment.NewLine
+ "\treturn arg1 + arg2;" + Environment.NewLine
+ "}" + Environment.NewLine;
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim());
Assert.AreEqual(expected, visitor.GetShaderString(0));
}
}
}

19
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/Function3InputTests.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
}

[Test]
public void TestGenerateNodeCodeGeneratesCorrectCode()
{
string expected = string.Format("half {0} = unity_test_half ({1}, {2}, {3});"
string expected = string.Format("half {0} = unity_test_half ({1}, {2}, {3});{4}"
, m_InputThree.GetVariableNameForSlot(Vector1Node.OutputSlotId));
, m_InputThree.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, Environment.NewLine);
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim());
Assert.AreEqual(expected, visitor.GetShaderString(0));
}
[Test]

"inline half unity_test_half (half arg1, half arg2, half arg3)\r\n"
+ "{\r\n"
+ "\treturn arg1 + arg2 + arg3;\r\n"
+ "}";
"inline half unity_test_half (half arg1, half arg2, half arg3)" + Environment.NewLine
+ "{" + Environment.NewLine
+ "\treturn arg1 + arg2 + arg3;" + Environment.NewLine
+ "}" + Environment.NewLine;
Assert.AreEqual(expected, visitor.GetShaderString(0).Trim());
Assert.AreEqual(expected, visitor.GetShaderString(0));
}
}
}

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialNodeTests.cs


[Test]
public void NodeGenerateCorrectPreviewPropertyUsages()
{
string expected = string.Format("{0} {1};\r\n", AbstractMaterialNode.OutputPrecision.@fixed, m_NodeA.GetVariableNameForSlot(TestNode.V1In));
string expected = string.Format("{0} {1};{2}", AbstractMaterialNode.OutputPrecision.@fixed, m_NodeA.GetVariableNameForSlot(TestNode.V1In), Environment.NewLine);
expected = string.Format("{0} {1};\r\n", AbstractMaterialNode.OutputPrecision.@float, m_NodeA.GetVariableNameForSlot(TestNode.V1In));
expected = string.Format("{0} {1};{2}", AbstractMaterialNode.OutputPrecision.@float, m_NodeA.GetVariableNameForSlot(TestNode.V1In), Environment.NewLine);
expected = string.Format("{0} {1};\r\n", AbstractMaterialNode.OutputPrecision.half, m_NodeA.GetVariableNameForSlot(TestNode.V1In));
expected = string.Format("{0} {1};{2}", AbstractMaterialNode.OutputPrecision.half, m_NodeA.GetVariableNameForSlot(TestNode.V1In), Environment.NewLine);
visitor = new ShaderGenerator();
m_NodeA.precision = AbstractMaterialNode.OutputPrecision.half;
m_NodeA.GeneratePropertyUsages(visitor, GenerationMode.Preview2D);

2
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/MaterialSlotTests.cs


[Test]
public void MaterialSlotCanGeneratePropertyUsagesForPreview()
{
string expected = string.Format("{0} {1};\r\n", m_NodeA.precision, m_NodeA.GetVariableNameForSlot(TestNode.V1In));
string expected = string.Format("{0} {1};{2}", m_NodeA.precision, m_NodeA.GetVariableNameForSlot(TestNode.V1In), Environment.NewLine);
var slot = m_NodeA.slot;
var visitor = new ShaderGenerator();

8
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PixelShaderNodeTests.cs


[Test]
public void TestNodeGeneratesCorrectNodeCode()
{
string expected = string.Format("half {0} = 0.2;\r\n"
+ "o.Normal = {0};\r\n"
+ "half {1} = abs ({0});\r\n"
+ "o.Albedo = {1};\r\n"
string expected = string.Format("half {0} = 0.2;" + Environment.NewLine
+ "o.Normal = {0};" + Environment.NewLine
+ "half {1} = abs ({0});" + Environment.NewLine
+ "o.Albedo = {1};" + Environment.NewLine
, m_InputOne.GetVariableNameForSlot(Vector1Node.OutputSlotId)
, m_Abs.GetVariableNameForSlot(Function1Input.OutputSlotId));

6
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/PropertyNodeTests.cs


using System;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEngine;

+ m_Vector1Node.description
+ "\", Float) = "
+ m_Vector1Node.value
+ "\n";
+ Environment.NewLine;
m_Vector1Node.exposedState = PropertyNode.ExposedState.Exposed;
m_Vector1Node.GeneratePropertyBlock(generator, GenerationMode.SurfaceShader);

var expected = m_Vector1Node.precision
+ " "
+ m_Vector1Node.propertyName
+ ";\r\n";
+";"
+ Environment.NewLine;
m_Vector1Node.exposedState = PropertyNode.ExposedState.Exposed;
m_Vector1Node.GeneratePropertyUsages(generator, GenerationMode.SurfaceShader);

3
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/UnitTests/ShaderGeneratorTests.cs


var result = ShaderGenerator.AdaptNodeOutput(node, TestNode.V4Out, ConcreteSlotValueType.Vector4);
Assert.AreEqual(string.Format("{0}", node.GetVariableNameForSlot(TestNode.V4Out)), result);
}
}
}

10
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Light/BaseLightFunction.cs


public const string kNormalSlotName = "Normal";
public const int NormalSlotId = 1;
public virtual string lightFunctionName
{
get { return ""; }
}
public abstract string lightFunctionName { get; }
public virtual string surfaceOutputStructureName
{
get { return ""; }
}
public abstract string surfaceOutputStructureName { get; }
public virtual void GenerateLightFunctionBody(ShaderGenerator visitor) {}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/AddNode.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/BlendNode.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/CombineNode.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
public void GenerateNodeFunction(ShaderGenerator visitor, GenerationMode generationMode)

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/DivNode.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/FresnelNode.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/MultiplyNode.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/QuantizeNode.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/ReflectNode.cs


outputString.Deindent();
outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
}
}

2
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Nodes/SubtractNode.cs


outputString.AddShaderChunk("}", false);
visitor.AddShaderChunk(outputString.GetShaderString(0), true);
visitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
}
}

4
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/SubGraph/SubGraphNode.cs


var bodyGenerator = new ShaderGenerator();
subGraph.GenerateNodeCode(bodyGenerator, GenerationMode.SurfaceShader);
var subGraphOutputNode = subGraphAsset.subGraph.outputNode;
outputString.AddShaderChunk(bodyGenerator.GetShaderString(0), false);
outputString.AddShaderChunk(bodyGenerator.GetShaderString(0), false, false);
// Step 5...
// Copy the outputs to the parent context name);

outputString.AddShaderChunk("}", false);
outputString.AddShaderChunk("// Subgraph ends", false);
shaderBodyVisitor.AddShaderChunk(outputString.GetShaderString(0), true);
shaderBodyVisitor.AddShaderChunk(outputString.GetShaderString(0), true, false);
}
public override void GeneratePropertyBlock(PropertyGenerator visitor, GenerationMode generationMode)

6
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/PropertyGenerator.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

foreach (var prop in m_Properties)
{
for (var i = 0; i < baseIndentLevel; i++)
{
}
sb.Append(prop.GetPropertyString());
sb.Append("\n");
sb.AppendLine(prop.GetPropertyString());
}
return sb.ToString();
}

19
MaterialGraphProject/Assets/UnityShaderEditor/Runtime/Util/ShaderGenerator.cs


{
private struct ShaderChunk
{
public ShaderChunk(int indentLevel, string shaderChunkString)
public ShaderChunk(int indentLevel, string shaderChunkString, bool appendNewLineAfter)
m_AppendNewLineAfter = appendNewLineAfter;
private readonly bool m_AppendNewLineAfter;
public bool appendNewLineAfter { get { return m_AppendNewLineAfter; } }
}
private readonly List<ShaderChunk> m_ShaderChunks = new List<ShaderChunk>();

return m_Pragma;
}
public void AddShaderChunk(string s, bool unique)
public void AddShaderChunk(string s, bool unique, bool appendNewLineAfter = true)
m_ShaderChunks.Add(new ShaderChunk(m_IndentLevel, s));
m_ShaderChunks.Add(new ShaderChunk(m_IndentLevel, s, appendNewLineAfter));
}
public void Indent() { m_IndentLevel++; }

var sb = new StringBuilder();
foreach (var shaderChunk in m_ShaderChunks)
{
var replaceString = "\n";
{
replaceString += "\t";
}
sb.AppendLine(shaderChunk.chunkString.Replace("\n", replaceString));
if (shaderChunk.appendNewLineAfter)
sb.AppendLine(shaderChunk.chunkString);
else
sb.Append(shaderChunk.chunkString);
}
return sb.ToString();
}

正在加载...
取消
保存