浏览代码

Update shader generation tests.

/main
Tim Cooper 7 年前
当前提交
b1e5c75f
共有 4 个文件被更改,包括 18 次插入34 次删除
  1. 46
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/ShaderGenerationTest.cs
  2. 2
      ShaderTemplates/Add.ShaderGraph.shader
  3. 2
      ShaderTemplates/Multiply.ShaderGraph.shader
  4. 2
      ShaderTemplates/TextureSample.ShaderGraph.shader

46
MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/ShaderGenerationTest.cs


{
name = p.Name,
info = p,
threshold = 0.02f
threshold = 0.05f
};
}
}

{
var failedPath = Path.Combine(rootPath.ToString(), "Failed");
Directory.CreateDirectory(failedPath);
var misMatchLocationResult =
Path.Combine(failedPath, string.Format("{0}.{1}", file.Name, "shader"));
var misMatchLocationTemplate =
Path.Combine(failedPath, string.Format("{0}.template.{1}", file.Name, "shader"));
var misMatchLocationResult = Path.Combine(failedPath, string.Format("{0}.{1}", file.Name, "shader"));
var misMatchLocationTemplate = Path.Combine(failedPath, string.Format("{0}.template.{1}", file.Name, "shader"));
Assert.Fail("Shader text from graph {0}, did not match .template file.", file);
Assert.IsTrue(textsAreEqual == 0);
}
m_Shader = ShaderUtil.CreateShaderAsset(shaderString);

m_FromDisk = new Texture2D(2, 2);
m_FromDisk.LoadImage(template, false);
var areEqual = CompareTextures(m_FromDisk, m_Captured, testInfo.threshold);
var rmse = CompareTextures(m_FromDisk, m_Captured);
if (!areEqual)
if (rmse > testInfo.threshold)
{
var failedPath = Path.Combine(rootPath.ToString(), "Failed");
Directory.CreateDirectory(failedPath);

var generated = m_Captured.EncodeToPNG();
File.WriteAllBytes(misMatchLocationResult, generated);
File.WriteAllBytes(misMatchLocationTemplate, template);
Assert.Fail("Shader image from graph {0}, did not match .template file.", file);
Assert.IsTrue(areEqual, "Shader from graph {0}, did not match .template file.", file);
private bool CompareTextures(Texture2D fromDisk, Texture2D captured, float threshold)
private float CompareTextures(Texture2D fromDisk, Texture2D captured)
return false;
return 1f;
return false;
return 1f;
return false;
return 1f;
int numberOfPixels = pixels1.Length;
float sumOfSquaredColorDistances = 0;

sumOfSquaredColorDistances += (diff.r + diff.g + diff.b) / 3.0f;
}
float rmse = Mathf.Sqrt(sumOfSquaredColorDistances / numberOfPixels);
return rmse < threshold;
}
private bool CompareColor(Vector4 left, Vector4 right, float threshold)
{
Vector4 diff = left - right;
if (Mathf.Abs(diff.x) > threshold)
return false;
if (Mathf.Abs(diff.y) > threshold)
return false;
if (Mathf.Abs(diff.z) > threshold)
return false;
if (Mathf.Abs(diff.w) > threshold)
return false;
return true;
Debug.Log(rmse);
return rmse;
}
}
}

2
ShaderTemplates/Add.ShaderGraph.shader


Shader "Graph/UnityEngine.MaterialGraph.MetallicMasterNode619b20e6-2273-4e23-807b-84c0dab1f9b9"
Shader "Add"
{
Properties
{

2
ShaderTemplates/Multiply.ShaderGraph.shader


Shader "Graph/UnityEngine.MaterialGraph.MetallicMasterNode54a42f5e-c675-49a8-84b7-53d88fc52b4d"
Shader "Multiply"
{
Properties
{

2
ShaderTemplates/TextureSample.ShaderGraph.shader


Shader "Graph/UnityEngine.MaterialGraph.MetallicMasterNode8d0a8307-a3eb-4434-be6c-c952f4588d6c"
Shader "TextureSample"
{
Properties
{

正在加载...
取消
保存