Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
15c6805
Add ST to texture params
Nov 4, 2020
c76e53b
Working with Universal / Texture2D (but not CFN yet)
Nov 9, 2020
464c730
CustomFunctionNode Texture2D working, allows full bare/non-bare selec…
Nov 10, 2020
6def478
Started on Cubemap/Array/3D
Nov 10, 2020
7564cec
Partial fixes fore 3d/array/cubemap
Nov 10, 2020
6d95d2b
Fix for texelSize node
Nov 10, 2020
a1acbb3
Texture2D nodes all working
Nov 10, 2020
5529870
Fixes for cubemap nodes, Texture2DArray nodes, Texture3d nodes
Nov 11, 2020
2f57ecb
Fix for HDRP
Nov 11, 2020
51cd85a
Fixes for GLES2
Nov 11, 2020
59fd40d
Fixes for NormalFromTextureNode, Texture2dAssetNode
Nov 11, 2020
32c4aed
Added SamplerState handling, cleaned up code to remove macro usage
Nov 12, 2020
c6a191f
Fix for ParallaxOcclusionMappingNode
Nov 12, 2020
857ffb5
Fix for NormalFromTextureNode, cleanup, adding changelog
Nov 12, 2020
9025101
Fix for old Texture2DArray and Texture3D inputs to CustomFunctionNodes
Nov 13, 2020
152ab5d
Fix for ParallaxMapping and Triplanar nodes handling of SamplerState …
Nov 13, 2020
1d1cbed
Cleanup, removing unused code and _ST values (for now)
Nov 13, 2020
4451e34
Fix samplerstates on SampleRawCubemap and SampleTexture2DLOD nodes
Nov 13, 2020
5028e08
Fix for VFX support, additional cleanup
Nov 13, 2020
1dcee04
Fix for decals
Nov 14, 2020
c7eb890
Fix for tests
Nov 16, 2020
3507116
Fix VFX path generation issues with textures
Nov 16, 2020
aa1db2d
Improved backwards compatibility, added graphics tests, addressing fe…
Nov 23, 2020
228c1f8
Merge branch '10.x.x/release' into 10.x.x/sg/fix/textures
Nov 23, 2020
796dc2d
Fix for GLES2 compilation
Nov 23, 2020
6452658
Fix for OpenGL Core
Nov 24, 2020
babacdd
Adding GLCore support for LOAD_TEXTURE3D and LOAD_TEXTURE3D_LOD
Nov 24, 2020
3347c9a
Fix for consoles
Nov 24, 2020
684e3bb
Disallow creating v0 of custom function node (which will upgrade inco…
Nov 25, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 110 additions & 19 deletions TestProjects/ShaderGraph/Assets/CommonAssets/Editor/ImportUpdateTests.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using NUnit.Framework;
using System.Collections;
using System.IO;
using System.Linq;
using UnityEditor.Graphing.Util;
using UnityEditor.ShaderGraph.Serialization;
using UnityEngine;
Expand All @@ -10,63 +11,116 @@ namespace UnityEditor.ShaderGraph.UnitTests
[TestFixture]
class ImportUpdateTests
{
public class ImportCases : IEnumerable
public class SingleImportCases : IEnumerable
{
private const string kGraphsLocation = "PreviousGraphVersions/";
public IEnumerator GetEnumerator()
{
return Directory.GetFiles(Application.dataPath + "/../" + kGraphsLocation, "*", SearchOption.AllDirectories).GetEnumerator();
var versionDirs = Directory.GetDirectories(Application.dataPath + "/../" + kGraphsLocation, "*", SearchOption.TopDirectoryOnly);
foreach (var dir in versionDirs)
foreach (var assetPath in Directory.GetFiles(dir, "*", SearchOption.TopDirectoryOnly))
yield return assetPath;
}
}

public class MultiImportDirectories : IEnumerable
{
private const string kGraphsLocation = "PreviousGraphVersions/";
public IEnumerator GetEnumerator()
{
var versionDirs = Directory.GetDirectories(Application.dataPath + "/../" + kGraphsLocation, "*", SearchOption.TopDirectoryOnly);
foreach (var dir in versionDirs)
foreach (var multiDir in Directory.GetDirectories(dir, "*", SearchOption.TopDirectoryOnly))
yield return multiDir;
}
}

[OneTimeSetUp]
public void Setup()
{
if(!AssetDatabase.IsValidFolder("Assets/Testing/ImportTests"))
if (!Directory.Exists(Application.dataPath + "Testing/ImportTests"))
Directory.CreateDirectory(Application.dataPath + "Testing/ImportTests");
AssetDatabase.Refresh();

if (!AssetDatabase.IsValidFolder("Assets/Testing/ImportTests"))
{
AssetDatabase.CreateFolder("Assets/Testing", "ImportTests");
}
}

[TestCaseSource(typeof(ImportCases))]
public void CopyOverAndImport(string assetPath)
[TestCaseSource(typeof(SingleImportCases))]
public void ImportSingle(string assetPath)
{
string fileName = Path.GetFileName(assetPath);
string fileNameNoExtension = Path.GetFileNameWithoutExtension(assetPath);
string fileContents = File.ReadAllText(assetPath);
string fileExtension = Path.GetExtension(assetPath).ToLower();
bool isSubgraph = (fileExtension == "shadersubgraph");

string localFilePath = "Assets/Testing/ImportTests/" + fileName;
string localFilePathNoExtension = "Assets/Testing/ImportTests/" + fileNameNoExtension;
string targetPath = Application.dataPath + "/Testing/ImportTests/" + fileName;
File.WriteAllText(targetPath, fileContents);

File.WriteAllText(Application.dataPath + "/Testing/ImportTests/" + fileName, fileContents);
AssetDatabase.ImportAsset(localFilePath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer);
var graphGuid = AssetDatabase.AssetPathToGUID(localFilePath);
string unityLocalPath = "Assets/Testing/ImportTests/" + fileName;
TestImportAsset(unityLocalPath, targetPath);
}

[TestCaseSource(typeof(MultiImportDirectories))]
public void ImportMulti(string directory)
{
string sourceDir = Path.GetFullPath(directory).TrimEnd(Path.DirectorySeparatorChar);
string dirName = Path.GetFileName(sourceDir);

string targetDir = Application.dataPath + "/Testing/ImportTests/" + dirName;
DirectoryCopy(sourceDir, targetDir, true, true);

foreach (var assetFullPath in Directory.GetFiles(targetDir, "*.shader*", SearchOption.TopDirectoryOnly))
{
if (!assetFullPath.EndsWith(".meta"))
{
string relativeFilePath = assetFullPath.Substring(targetDir.Length);
string unityLocalPath = "Assets/Testing/ImportTests/" + dirName + relativeFilePath;
TestImportAsset(unityLocalPath, assetFullPath);
}
}
}

public void TestImportAsset(string unityLocalPath, string fullPath)
{
unityLocalPath = unityLocalPath.Replace("\\", "/");
Debug.Log("Testing file: " + unityLocalPath);

// invoke an import
AssetDatabase.ImportAsset(unityLocalPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer);

// double check we can load it up and validate it
string fileContents = File.ReadAllText(fullPath);
Assert.Greater(fileContents.Length, 0);

var graphGuid = AssetDatabase.AssetPathToGUID(unityLocalPath);
var messageManager = new MessageManager();
GraphData graphData = new GraphData() { assetGuid = graphGuid, messageManager = messageManager };
MultiJson.Deserialize(graphData, fileContents);
graphData.OnEnable();
graphData.ValidateGraph();

string fileExtension = Path.GetExtension(fullPath).ToLower();
bool isSubgraph = (fileExtension == "shadersubgraph");
if (isSubgraph)
{
// check that the SubGraphAsset is the same after versioning twice
// this is important to ensure we're not importing subgraphs non-deterministically when they are out-of-date on disk
AssetDatabase.ImportAsset(localFilePath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer);
var subGraph = AssetDatabase.LoadAssetAtPath<SubGraphAsset>(localFilePath);
AssetDatabase.ImportAsset(unityLocalPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer);
var subGraph = AssetDatabase.LoadAssetAtPath<SubGraphAsset>(unityLocalPath);
var serialized = EditorJsonUtility.ToJson(subGraph);

AssetDatabase.ImportAsset(localFilePath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer);
var subGraph2 = AssetDatabase.LoadAssetAtPath<SubGraphAsset>(localFilePath);
AssetDatabase.ImportAsset(unityLocalPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer);
var subGraph2 = AssetDatabase.LoadAssetAtPath<SubGraphAsset>(unityLocalPath);
var serialized2 = EditorJsonUtility.ToJson(subGraph2);

Assert.AreEqual(serialized, serialized2, $"Importing the subgraph {localFilePath} twice resulted in different subgraph assets.");
Assert.AreEqual(serialized, serialized2, $"Importing the subgraph {unityLocalPath} twice resulted in different subgraph assets.");
}
else
{
// check that the generated shader is the same after versioning twice
// this is important to ensure we're not importing shaders non-deterministically when they are out-of-date on disk
string fileNameNoExtension = Path.GetFileNameWithoutExtension(fullPath);
var generator = new Generator(graphData, graphData.outputNode, GenerationMode.ForReals, fileNameNoExtension, null);
string shader = generator.generatedShader;

Expand All @@ -78,18 +132,55 @@ public void CopyOverAndImport(string assetPath)
var generator2 = new Generator(graphData2, graphData2.outputNode, GenerationMode.ForReals, fileNameNoExtension, null);
string shader2 = generator2.generatedShader;

Assert.AreEqual(shader, shader2, $"Importing the graph {localFilePath} twice resulted in different generated shaders.");
Assert.AreEqual(shader, shader2, $"Importing the graph {unityLocalPath} twice resulted in different generated shaders.");
}
}

[OneTimeTearDown]
public void Cleanup()
{
AssetDatabase.Refresh();
foreach (string assetGuid in AssetDatabase.FindAssets("*", new string[] { "Assets/Testing/ImportTests" }))
{
Debug.Log(AssetDatabase.GUIDToAssetPath(assetGuid));
AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(assetGuid));
}
}

private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs, bool overwriteFiles)
{
// Get the subdirectories for the specified directory.
DirectoryInfo dir = new DirectoryInfo(sourceDirName);

if (!dir.Exists)
{
throw new DirectoryNotFoundException(
"Source directory does not exist or could not be found: "
+ sourceDirName);
}

DirectoryInfo[] dirs = dir.GetDirectories();

// If the destination directory doesn't exist, create it.
Directory.CreateDirectory(destDirName);

// Get the files in the directory and copy them to the new location.
FileInfo[] files = dir.GetFiles();
foreach (FileInfo file in files)
{
string tempPath = Path.Combine(destDirName, file.Name);
file.CopyTo(tempPath, overwriteFiles);
}

// If copying subdirectories, copy them and their contents to new location.
if (copySubDirs)
{
foreach (DirectoryInfo subdir in dirs)
{
string tempPath = Path.Combine(destDirName, subdir.Name);
DirectoryCopy(subdir.FullName, tempPath, copySubDirs, overwriteFiles);
}
}
}
}
}
Git LFS file not shown

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading