Skip to content

Commit 84d0230

Browse files
author
Chris Tchou
authored
[ShaderGraph] [Backport 10.3] Fix texture associated state (samplerstate, TexelSize) for subgraphs, CFNs (#2577)
* Add ST to texture params * Working with Universal / Texture2D (but not CFN yet) * CustomFunctionNode Texture2D working, allows full bare/non-bare selection of types, warns when using bare output types * Started on Cubemap/Array/3D * Partial fixes fore 3d/array/cubemap * Fix for texelSize node * Texture2D nodes all working * Fixes for cubemap nodes, Texture2DArray nodes, Texture3d nodes * Fix for HDRP * Fixes for GLES2 * Fixes for NormalFromTextureNode, Texture2dAssetNode * Added SamplerState handling, cleaned up code to remove macro usage * Fix for ParallaxOcclusionMappingNode * Fix for NormalFromTextureNode, cleanup, adding changelog * Fix for old Texture2DArray and Texture3D inputs to CustomFunctionNodes * Fix for ParallaxMapping and Triplanar nodes handling of SamplerState types * Cleanup, removing unused code and _ST values (for now) * Fix samplerstates on SampleRawCubemap and SampleTexture2DLOD nodes * Fix for VFX support, additional cleanup * Fix for decals * Fix for tests * Fix VFX path generation issues with textures * Improved backwards compatibility, added graphics tests, addressing feedback * Fix for GLES2 compilation * Fix for OpenGL Core * Adding GLCore support for LOAD_TEXTURE3D and LOAD_TEXTURE3D_LOD * Fix for consoles * Disallow creating v0 of custom function node (which will upgrade incorrectly when saved/loaded)
1 parent 3c10713 commit 84d0230

File tree

81 files changed

+15180
-569
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+15180
-569
lines changed
Lines changed: 110 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using NUnit.Framework;
22
using System.Collections;
33
using System.IO;
4+
using System.Linq;
45
using UnityEditor.Graphing.Util;
56
using UnityEditor.ShaderGraph.Serialization;
67
using UnityEngine;
@@ -10,63 +11,116 @@ namespace UnityEditor.ShaderGraph.UnitTests
1011
[TestFixture]
1112
class ImportUpdateTests
1213
{
13-
public class ImportCases : IEnumerable
14+
public class SingleImportCases : IEnumerable
1415
{
1516
private const string kGraphsLocation = "PreviousGraphVersions/";
1617
public IEnumerator GetEnumerator()
1718
{
18-
return Directory.GetFiles(Application.dataPath + "/../" + kGraphsLocation, "*", SearchOption.AllDirectories).GetEnumerator();
19+
var versionDirs = Directory.GetDirectories(Application.dataPath + "/../" + kGraphsLocation, "*", SearchOption.TopDirectoryOnly);
20+
foreach (var dir in versionDirs)
21+
foreach (var assetPath in Directory.GetFiles(dir, "*", SearchOption.TopDirectoryOnly))
22+
yield return assetPath;
23+
}
24+
}
25+
26+
public class MultiImportDirectories : IEnumerable
27+
{
28+
private const string kGraphsLocation = "PreviousGraphVersions/";
29+
public IEnumerator GetEnumerator()
30+
{
31+
var versionDirs = Directory.GetDirectories(Application.dataPath + "/../" + kGraphsLocation, "*", SearchOption.TopDirectoryOnly);
32+
foreach (var dir in versionDirs)
33+
foreach (var multiDir in Directory.GetDirectories(dir, "*", SearchOption.TopDirectoryOnly))
34+
yield return multiDir;
1935
}
2036
}
2137

2238
[OneTimeSetUp]
2339
public void Setup()
2440
{
25-
if(!AssetDatabase.IsValidFolder("Assets/Testing/ImportTests"))
41+
if (!Directory.Exists(Application.dataPath + "Testing/ImportTests"))
42+
Directory.CreateDirectory(Application.dataPath + "Testing/ImportTests");
43+
AssetDatabase.Refresh();
44+
45+
if (!AssetDatabase.IsValidFolder("Assets/Testing/ImportTests"))
2646
{
2747
AssetDatabase.CreateFolder("Assets/Testing", "ImportTests");
2848
}
2949
}
3050

31-
[TestCaseSource(typeof(ImportCases))]
32-
public void CopyOverAndImport(string assetPath)
51+
[TestCaseSource(typeof(SingleImportCases))]
52+
public void ImportSingle(string assetPath)
3353
{
3454
string fileName = Path.GetFileName(assetPath);
35-
string fileNameNoExtension = Path.GetFileNameWithoutExtension(assetPath);
3655
string fileContents = File.ReadAllText(assetPath);
37-
string fileExtension = Path.GetExtension(assetPath).ToLower();
38-
bool isSubgraph = (fileExtension == "shadersubgraph");
3956

40-
string localFilePath = "Assets/Testing/ImportTests/" + fileName;
41-
string localFilePathNoExtension = "Assets/Testing/ImportTests/" + fileNameNoExtension;
57+
string targetPath = Application.dataPath + "/Testing/ImportTests/" + fileName;
58+
File.WriteAllText(targetPath, fileContents);
4259

43-
File.WriteAllText(Application.dataPath + "/Testing/ImportTests/" + fileName, fileContents);
44-
AssetDatabase.ImportAsset(localFilePath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer);
45-
var graphGuid = AssetDatabase.AssetPathToGUID(localFilePath);
60+
string unityLocalPath = "Assets/Testing/ImportTests/" + fileName;
61+
TestImportAsset(unityLocalPath, targetPath);
62+
}
63+
64+
[TestCaseSource(typeof(MultiImportDirectories))]
65+
public void ImportMulti(string directory)
66+
{
67+
string sourceDir = Path.GetFullPath(directory).TrimEnd(Path.DirectorySeparatorChar);
68+
string dirName = Path.GetFileName(sourceDir);
69+
70+
string targetDir = Application.dataPath + "/Testing/ImportTests/" + dirName;
71+
DirectoryCopy(sourceDir, targetDir, true, true);
72+
73+
foreach (var assetFullPath in Directory.GetFiles(targetDir, "*.shader*", SearchOption.TopDirectoryOnly))
74+
{
75+
if (!assetFullPath.EndsWith(".meta"))
76+
{
77+
string relativeFilePath = assetFullPath.Substring(targetDir.Length);
78+
string unityLocalPath = "Assets/Testing/ImportTests/" + dirName + relativeFilePath;
79+
TestImportAsset(unityLocalPath, assetFullPath);
80+
}
81+
}
82+
}
83+
84+
public void TestImportAsset(string unityLocalPath, string fullPath)
85+
{
86+
unityLocalPath = unityLocalPath.Replace("\\", "/");
87+
Debug.Log("Testing file: " + unityLocalPath);
88+
89+
// invoke an import
90+
AssetDatabase.ImportAsset(unityLocalPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer);
91+
92+
// double check we can load it up and validate it
93+
string fileContents = File.ReadAllText(fullPath);
94+
Assert.Greater(fileContents.Length, 0);
95+
96+
var graphGuid = AssetDatabase.AssetPathToGUID(unityLocalPath);
4697
var messageManager = new MessageManager();
4798
GraphData graphData = new GraphData() { assetGuid = graphGuid, messageManager = messageManager };
4899
MultiJson.Deserialize(graphData, fileContents);
49100
graphData.OnEnable();
50101
graphData.ValidateGraph();
51102

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

60-
AssetDatabase.ImportAsset(localFilePath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer);
61-
var subGraph2 = AssetDatabase.LoadAssetAtPath<SubGraphAsset>(localFilePath);
113+
AssetDatabase.ImportAsset(unityLocalPath, ImportAssetOptions.ForceSynchronousImport | ImportAssetOptions.ForceUpdate | ImportAssetOptions.DontDownloadFromCacheServer);
114+
var subGraph2 = AssetDatabase.LoadAssetAtPath<SubGraphAsset>(unityLocalPath);
62115
var serialized2 = EditorJsonUtility.ToJson(subGraph2);
63116

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

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

81-
Assert.AreEqual(shader, shader2, $"Importing the graph {localFilePath} twice resulted in different generated shaders.");
135+
Assert.AreEqual(shader, shader2, $"Importing the graph {unityLocalPath} twice resulted in different generated shaders.");
82136
}
83137
}
84138

85139
[OneTimeTearDown]
86140
public void Cleanup()
87141
{
142+
AssetDatabase.Refresh();
88143
foreach (string assetGuid in AssetDatabase.FindAssets("*", new string[] { "Assets/Testing/ImportTests" }))
89144
{
90145
Debug.Log(AssetDatabase.GUIDToAssetPath(assetGuid));
91146
AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(assetGuid));
92147
}
93148
}
149+
150+
private static void DirectoryCopy(string sourceDirName, string destDirName, bool copySubDirs, bool overwriteFiles)
151+
{
152+
// Get the subdirectories for the specified directory.
153+
DirectoryInfo dir = new DirectoryInfo(sourceDirName);
154+
155+
if (!dir.Exists)
156+
{
157+
throw new DirectoryNotFoundException(
158+
"Source directory does not exist or could not be found: "
159+
+ sourceDirName);
160+
}
161+
162+
DirectoryInfo[] dirs = dir.GetDirectories();
163+
164+
// If the destination directory doesn't exist, create it.
165+
Directory.CreateDirectory(destDirName);
166+
167+
// Get the files in the directory and copy them to the new location.
168+
FileInfo[] files = dir.GetFiles();
169+
foreach (FileInfo file in files)
170+
{
171+
string tempPath = Path.Combine(destDirName, file.Name);
172+
file.CopyTo(tempPath, overwriteFiles);
173+
}
174+
175+
// If copying subdirectories, copy them and their contents to new location.
176+
if (copySubDirs)
177+
{
178+
foreach (DirectoryInfo subdir in dirs)
179+
{
180+
string tempPath = Path.Combine(destDirName, subdir.Name);
181+
DirectoryCopy(subdir.FullName, tempPath, copySubDirs, overwriteFiles);
182+
}
183+
}
184+
}
94185
}
95186
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:2c2f3a88b52643dcdd288ab5d616577b8d9fbe686a4d2a09dc9f325bbb135cf9
3+
size 189915

TestProjects/ShaderGraph/Assets/TestbedAssets/Textures/Textures/Numbers.psd.meta

Lines changed: 144 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)