浏览代码

Now using RMS for texture compare

Added Assert Fail if text template doesn't exist.
/main
Mads Ronnow 7 年前
当前提交
edd8c41d
共有 1 个文件被更改,包括 15 次插入8 次删除
  1. 23
      MaterialGraphProject/Assets/UnityShaderEditor/Editor/Testing/IntegrationTests/ShaderGenerationTest.cs

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


var textTemplateFilePath = Path.Combine(shaderTemplatePath, string.Format("{0}.{1}", file.Name, "shader"));
if (!File.Exists(textTemplateFilePath)) {
File.WriteAllText(textTemplateFilePath, shaderString);
Assert.Fail("Text template file not found for {0}, creating it.", file);
}
else {
var textTemplate = File.ReadAllText(textTemplateFilePath);

// no reference exists, create it
var generated = m_Captured.EncodeToPNG();
File.WriteAllBytes(dumpFileLocation, generated);
Assert.Fail("Template file not found for {0}, creating it.", file);
Assert.Fail("Image template file not found for {0}, creating it.", file);
}
var template = File.ReadAllBytes(dumpFileLocation);

Assert.IsTrue(areEqual, "Shader from graph {0}, did not match .template file.", file);
}
private bool CompareTextures(Texture2D fromDisk, Texture2D captured, float threshold)
// compare textures, use RMS for this
private bool CompareTextures(Texture2D fromDisk, Texture2D captured, float threshold)
if (fromDisk.width != captured.width
if (fromDisk.width != captured.width
for (int i = 0; i < pixels1.Length; i++)
int numberOfPixels = pixels1.Length;
float sumOfSquaredColorDistances = 0;
for (int i = 0; i < numberOfPixels; i++)
if (!CompareColor(pixels1[i], pixels2[i], threshold))
return false;
Color p1 = pixels1[i];
Color p2 = pixels2[i];
Color diff = p1 - p2;
diff = diff * diff;
sumOfSquaredColorDistances += (diff.r + diff.g + diff.b) / 3.0f;
return true;
float rmse = Mathf.Sqrt(sumOfSquaredColorDistances / numberOfPixels);
return rmse < threshold;
}
private bool CompareColor(Vector4 left, Vector4 right, float threshold)

正在加载...
取消
保存