|
|
|
|
|
|
using UnityEngine; |
|
|
|
using Object = UnityEngine.Object; |
|
|
|
using System.Text; |
|
|
|
using NUnit.Framework.Internal; |
|
|
|
using UnityEditor.ShaderGraph.Drawing; |
|
|
|
|
|
|
|
namespace UnityEditor.ShaderGraph.IntegrationTests |
|
|
|
|
|
|
{ |
|
|
|
get |
|
|
|
{ |
|
|
|
var filePaths = Directory.GetFiles(s_Path).Select(x => new FileInfo(x)) |
|
|
|
.Where(x => x.Extension == ".ShaderGraph"); |
|
|
|
var filePaths = Directory.GetFiles(s_Path, "*.ShaderGraph", SearchOption.AllDirectories).Select(x => new FileInfo(x)); |
|
|
|
name = p.Name, |
|
|
|
name = p.FullName.Replace(s_Path + Path.DirectorySeparatorChar, "").Replace(Path.DirectorySeparatorChar, '/').Replace(".ShaderGraph", ""), |
|
|
|
info = p, |
|
|
|
threshold = 0.05f |
|
|
|
}; |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
[Test, TestCaseSource(typeof(CollectGraphs), "graphs")] |
|
|
|
public void ShaderGeneratorOutput(TestInfo testInfo) |
|
|
|
public void Graph(TestInfo testInfo) |
|
|
|
var filePath = Path.Combine(s_Path, file.Name); |
|
|
|
var filePath = file.FullName; |
|
|
|
|
|
|
|
var textGraph = File.ReadAllText(filePath, Encoding.UTF8); |
|
|
|
var graph = JsonUtility.FromJson<MaterialGraph>(textGraph); |
|
|
|
|
|
|
//
|
|
|
|
var rootPath = Path.Combine(Path.Combine(DefaultShaderIncludes.GetRepositoryPath(), "Testing"), "IntegrationTests"); |
|
|
|
var shaderTemplatePath = Path.Combine(rootPath, ".ShaderTemplates"); |
|
|
|
var textTemplateFilePath = Path.Combine(shaderTemplatePath, string.Format("{0}.{1}", testInfo.name, "shader")); |
|
|
|
//Assert.IsNotNull(graphAsset, "Graph asset not found");
|
|
|
|
//var materialGraph = graphAsset.graph as UnityEngine.MaterialGraph.MaterialGraph;
|
|
|
|
//Assert.IsNotNull(materialGraph);
|
|
|
|
List<PropertyCollector.TextureInfo> configuredTextures = new List<PropertyCollector.TextureInfo>(); |
|
|
|
|
|
|
|
if (!File.Exists(textTemplateFilePath)) |
|
|
|
{ |
|
|
|
Directory.CreateDirectory(Directory.GetParent(textTemplateFilePath).FullName); |
|
|
|
File.WriteAllText(textTemplateFilePath, ShaderGraphImporter.GetShaderText(filePath, out configuredTextures)); |
|
|
|
configuredTextures.Clear(); |
|
|
|
} |
|
|
|
List<PropertyCollector.TextureInfo> configuredTextures = new List<PropertyCollector.TextureInfo>(); |
|
|
|
var rootPath = Path.Combine(Path.Combine(DefaultShaderIncludes.GetRepositoryPath(), "Testing"), "IntegrationTests"); |
|
|
|
var shaderTemplatePath = Path.Combine(rootPath, ".ShaderTemplates"); |
|
|
|
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); |
|
|
|
var textsAreEqual = string.Compare(shaderString, textTemplate, CultureInfo.CurrentCulture, CompareOptions.IgnoreSymbols); |
|
|
|
|
|
|
|
if (0 != textsAreEqual) |
|
|
|
var textTemplate = File.ReadAllText(textTemplateFilePath); |
|
|
|
var textsAreEqual = string.Compare(shaderString, textTemplate, CultureInfo.CurrentCulture, CompareOptions.IgnoreSymbols); |
|
|
|
|
|
|
|
if (0 != textsAreEqual) |
|
|
|
{ |
|
|
|
var failedPath = Path.Combine(rootPath, ".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")); |
|
|
|
File.WriteAllText(misMatchLocationResult, shaderString); |
|
|
|
File.WriteAllText(misMatchLocationTemplate, textTemplate); |
|
|
|
var failedPath = Path.Combine(rootPath, ".Failed"); |
|
|
|
var misMatchLocationResult = Path.Combine(failedPath, string.Format("{0}.{1}", testInfo.name, "shader")); |
|
|
|
var misMatchLocationTemplate = Path.Combine(failedPath, string.Format("{0}.template.{1}", testInfo.name, "shader")); |
|
|
|
Directory.CreateDirectory(Directory.GetParent(misMatchLocationResult).FullName); |
|
|
|
File.WriteAllText(misMatchLocationResult, shaderString); |
|
|
|
File.WriteAllText(misMatchLocationTemplate, textTemplate); |
|
|
|
Assert.Fail("Shader text from graph {0}, did not match .template file.", file); |
|
|
|
} |
|
|
|
Assert.Fail("Shader text from graph {0}, did not match .template file.", file); |
|
|
|
} |
|
|
|
|
|
|
|
m_Shader = ShaderUtil.CreateShaderAsset(shaderString); |
|
|
|
|
|
|
Object.DestroyImmediate(renderTexture, true); |
|
|
|
|
|
|
|
// find the reference image
|
|
|
|
var dumpFileLocation = Path.Combine(shaderTemplatePath, string.Format("{0}.{1}", file.Name, "png")); |
|
|
|
var dumpFileLocation = Path.Combine(shaderTemplatePath, string.Format("{0}.{1}", testInfo.name, "png")); |
|
|
|
Directory.CreateDirectory(Directory.GetParent(dumpFileLocation).FullName); |
|
|
|
// no reference exists, create it
|
|
|
|
var generated = m_Captured.EncodeToPNG(); |
|
|
|
File.WriteAllBytes(dumpFileLocation, generated); |
|
|
|
|
|
|
if (rmse > testInfo.threshold) |
|
|
|
{ |
|
|
|
var failedPath = Path.Combine(rootPath, ".Failed"); |
|
|
|
Directory.CreateDirectory(failedPath); |
|
|
|
var misMatchLocationResult = Path.Combine(failedPath, string.Format("{0}.{1}", file.Name, "png")); |
|
|
|
var misMatchLocationResult = Path.Combine(failedPath, string.Format("{0}.{1}", testInfo.name, "png")); |
|
|
|
Path.Combine(failedPath, string.Format("{0}.template.{1}", file.Name, "png")); |
|
|
|
Path.Combine(failedPath, string.Format("{0}.template.{1}", testInfo.name, "png")); |
|
|
|
Directory.CreateDirectory(Directory.GetParent(misMatchLocationResult).FullName); |
|
|
|
File.WriteAllBytes(misMatchLocationResult, generated); |
|
|
|
File.WriteAllBytes(misMatchLocationTemplate, template); |
|
|
|
|
|
|
|