diff --git a/TestProjects/ShaderGraph/Assets/CommonAssets/Editor/FileMoveTests.cs b/TestProjects/ShaderGraph/Assets/CommonAssets/Editor/FileMoveTests.cs new file mode 100644 index 00000000000..679fd1badab --- /dev/null +++ b/TestProjects/ShaderGraph/Assets/CommonAssets/Editor/FileMoveTests.cs @@ -0,0 +1,200 @@ +using System.Collections; +using NUnit.Framework; +using UnityEditor.Experimental.GraphView; +using UnityEditor.ShaderGraph; +using UnityEditor.ShaderGraph.Drawing; +using System.Reflection; +using UnityEngine; +using UnityEngine.TestTools; +using UnityEngine.UIElements; +using System.IO; +using System.Collections.Generic; +using System.Text.RegularExpressions; + +/* Changes: + * Made ShaderGraphImporterEditor.ShowGraphEditWindow public + * Made MaterialGraphEditWindow.graphEditorView public + * Altered MasterPreviewView.OnMouseDragPreviewMesh slightly + */ + +namespace UnityEditor.ShaderGraph.UnitTests +{ + [TestFixture] + internal class FileMoveTests + { + GraphEditorView m_GraphEditorView; + MaterialGraphEditWindow m_Window; + GraphData m_Graph; + + static string sourceDirectoryPath => Application.dataPath + "/../MoveTest"; + static string sourceDirectoryPathSub => Application.dataPath + "/../MoveTest/SubFolder"; + static string targetDirectoryPath => Application.dataPath + "/Testing/MoveTest"; + static string targetDirectoryPath2 => Application.dataPath + "/Testing/MoveTest2"; + static string targetDirectoryPathSub => Application.dataPath + "/Testing/MoveTest/SubFolder"; + static string targetUnityDirectoryPath => "Assets/Testing/MoveTest"; + static string targetUnityDirectoryPath2 => "Assets/Testing/MoveTest2"; + + [OneTimeSetUp] + public void Setup() + { + // recursive delete + if (Directory.Exists(targetDirectoryPath2)) + { + Directory.Delete(targetDirectoryPath2, true); + + // sync AssetDatabase + AssetDatabase.DeleteAsset(targetUnityDirectoryPath2); + } + + Directory.CreateDirectory(targetDirectoryPath); + Directory.CreateDirectory(targetDirectoryPathSub); + + try + { + AssetDatabase.StartAssetEditing(); + + // copy all files from source directory to target directory + string[] sourceFiles = Directory.GetFiles(sourceDirectoryPath, "*", SearchOption.TopDirectoryOnly); + foreach (var sourceFilePath in sourceFiles) + { + string fileName = Path.GetFileName(sourceFilePath); + File.Copy(sourceFilePath, targetDirectoryPath + "/" + fileName); + } + + // copy all files from source directory to target directory + sourceFiles = Directory.GetFiles(sourceDirectoryPathSub, "*", SearchOption.TopDirectoryOnly); + foreach (var sourceFilePath in sourceFiles) + { + string fileName = Path.GetFileName(sourceFilePath); + File.Copy(sourceFilePath, targetDirectoryPathSub + "/" + fileName); + } + } + finally + { + AssetDatabase.StopAssetEditing(); + } + + // after all files are copied, make sure everything in the directory is imported + AssetDatabase.ImportAsset(targetUnityDirectoryPath, ImportAssetOptions.ImportRecursive); + } + + public void OpenGraphWindow(string graphName) + { + // Open up the window + if (!ShaderGraphImporterEditor.ShowGraphEditWindow(graphName)) + { + Assert.Fail("ShaderGraphImporterEditor.ShowGraphEditWindow could not open " + graphName); + } + + m_Window = EditorWindow.GetWindow(); + + if (m_Window == null) + { + Assert.Fail("Could not open MaterialGraphEditWindow"); + } + + // EditorWindow.GetWindow will return a new window if one is not found. A new window will have graphObject == null. + if (m_Window.graphObject == null) + { + Assert.Fail("Existing Shader Graph window of " + graphName + " not found."); + } + + m_GraphEditorView = m_Window.graphEditorView; + } + + [TearDown] + public void CloseGraphWindow() + { + if (m_Window != null) + { + m_Window.graphObject = null; // Don't spawn ask-to-save dialog + m_Window.Close(); + } + m_Window = null; + m_GraphEditorView = null; + } + + [OneTimeTearDown] + public void Cleanup() + { + try + { + + AssetDatabase.StartAssetEditing(); + + // delete everything from target directory (via assetdatabase to clear anything relevant) + foreach (string assetGuid in AssetDatabase.FindAssets("*", new string[] { targetUnityDirectoryPath })) + { + AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(assetGuid)); + } + + foreach (string assetGuid in AssetDatabase.FindAssets("*", new string[] { targetUnityDirectoryPath2 })) + { + AssetDatabase.DeleteAsset(AssetDatabase.GUIDToAssetPath(assetGuid)); + } + + FileUtil.DeleteFileOrDirectory(targetDirectoryPath2); + } + finally + { + AssetDatabase.StopAssetEditing(); + } + + if (Directory.Exists(targetDirectoryPath2)) + { + Directory.Delete(targetDirectoryPath2, true); + + // sync AssetDatabase + AssetDatabase.DeleteAsset(targetUnityDirectoryPath2); + } + } + + // Tests that loading and saving a fully versioned graph file doesn't change the file on disk. + [UnityTest] + public IEnumerator MoveDirectoryTests() + { + yield return null; + + // rename the directory + AssetDatabase.MoveAsset(targetUnityDirectoryPath, targetUnityDirectoryPath2); + + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + + var graphPath = targetUnityDirectoryPath2 + "/ShaderGraph.shadergraph"; + OpenGraphWindow(graphPath); + + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + + // try adding the subgraph node -- see if the asset still works after the files have been moved + m_Graph = m_Window.graphObject.graph as GraphData; + var subgraph = AssetDatabase.LoadAssetAtPath(graphPath); + var node = new SubGraphNode { asset = subgraph }; + m_Graph.AddNode(node); + + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + yield return null; + + CloseGraphWindow(); + } + } +} diff --git a/com.unity.shadergraph/Editor/Interface/IShaderString.cs.meta b/TestProjects/ShaderGraph/Assets/CommonAssets/Editor/FileMoveTests.cs.meta similarity index 83% rename from com.unity.shadergraph/Editor/Interface/IShaderString.cs.meta rename to TestProjects/ShaderGraph/Assets/CommonAssets/Editor/FileMoveTests.cs.meta index 419612899cc..4a30d011f06 100644 --- a/com.unity.shadergraph/Editor/Interface/IShaderString.cs.meta +++ b/TestProjects/ShaderGraph/Assets/CommonAssets/Editor/FileMoveTests.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: c15047a36110c403dbeb2586093fff2a +guid: f3bcfe4b2789ba349adbf578f72c47d8 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/TestProjects/ShaderGraph/MoveTest/Shader Graphs_ShaderGraph.mat b/TestProjects/ShaderGraph/MoveTest/Shader Graphs_ShaderGraph.mat new file mode 100644 index 00000000000..2d09cba95a6 --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/Shader Graphs_ShaderGraph.mat @@ -0,0 +1,38 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!21 &2100000 +Material: + serializedVersion: 6 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: Shader Graphs_ShaderGraph + m_Shader: {fileID: -6465566751694194690, guid: e729d15e0112af8449c81fa47e54974d, + type: 3} + m_ShaderKeywords: + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: [] + m_Colors: [] + m_BuildTextureStacks: [] diff --git a/TestProjects/ShaderGraph/MoveTest/Shader Graphs_ShaderGraph.mat.meta b/TestProjects/ShaderGraph/MoveTest/Shader Graphs_ShaderGraph.mat.meta new file mode 100644 index 00000000000..bc00171f114 --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/Shader Graphs_ShaderGraph.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6ea30e39c0092c74b9c69a9d4361ef16 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/TestProjects/ShaderGraph/MoveTest/ShaderGraph.shadergraph b/TestProjects/ShaderGraph/MoveTest/ShaderGraph.shadergraph new file mode 100644 index 00000000000..e2b6ac15d47 --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/ShaderGraph.shadergraph @@ -0,0 +1,653 @@ +{ + "m_SGVersion": 2, + "m_Type": "UnityEditor.ShaderGraph.GraphData", + "m_ObjectId": "275982c90eba44939441bf0f7443f507", + "m_Properties": [], + "m_Keywords": [], + "m_Nodes": [ + { + "m_Id": "f62e09994d1d4057819c7d45d076f210" + }, + { + "m_Id": "a0bdaa47bc3b4570af3972710fbf075d" + }, + { + "m_Id": "7fe700ca8ba54869adebe13ab4c4a606" + }, + { + "m_Id": "d2963727d5484fe89f506679760f5ef8" + }, + { + "m_Id": "8f327dcca7584a34947a0cd47102f879" + }, + { + "m_Id": "5f81ac50e245475c8971b93d00d03832" + } + ], + "m_GroupDatas": [], + "m_StickyNoteDatas": [], + "m_Edges": [ + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "5f81ac50e245475c8971b93d00d03832" + }, + "m_SlotId": 4 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "d2963727d5484fe89f506679760f5ef8" + }, + "m_SlotId": 0 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "8f327dcca7584a34947a0cd47102f879" + }, + "m_SlotId": 1 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "5f81ac50e245475c8971b93d00d03832" + }, + "m_SlotId": 1 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "8f327dcca7584a34947a0cd47102f879" + }, + "m_SlotId": 2 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "5f81ac50e245475c8971b93d00d03832" + }, + "m_SlotId": 2 + } + } + ], + "m_VertexContext": { + "m_Position": { + "x": 0.0, + "y": 0.0 + }, + "m_Blocks": [ + { + "m_Id": "f62e09994d1d4057819c7d45d076f210" + }, + { + "m_Id": "a0bdaa47bc3b4570af3972710fbf075d" + }, + { + "m_Id": "7fe700ca8ba54869adebe13ab4c4a606" + } + ] + }, + "m_FragmentContext": { + "m_Position": { + "x": 0.0, + "y": 200.0 + }, + "m_Blocks": [ + { + "m_Id": "d2963727d5484fe89f506679760f5ef8" + } + ] + }, + "m_PreviewData": { + "serializedMesh": { + "m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}", + "m_Guid": "" + } + }, + "m_Path": "Shader Graphs", + "m_ConcretePrecision": 0, + "m_PreviewMode": 2, + "m_OutputNode": { + "m_Id": "" + }, + "m_ActiveTargets": [ + { + "m_Id": "d2019cdf6f854770bf611ab9340973c2" + } + ] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.UVMaterialSlot", + "m_ObjectId": "01ed5c2d524d4f869a42c99cec7eadc8", + "m_Id": 0, + "m_DisplayName": "UV", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "UV", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0 + }, + "m_Labels": [], + "m_Channel": 0 +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.TangentMaterialSlot", + "m_ObjectId": "13ccede99422486b9fe14793e7304ae1", + "m_Id": 0, + "m_DisplayName": "Tangent", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Tangent", + "m_StageCapability": 1, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [], + "m_Space": 0 +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "343a313961b24dadb56585d51735a832", + "m_Id": 1, + "m_DisplayName": "Out_Color1", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out_Color1", + "m_StageCapability": 2, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot", + "m_ObjectId": "42abfdabee224ddc8ff4922efaa89542", + "m_Id": 1, + "m_DisplayName": "Color A", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "ColorA", + "m_StageCapability": 3, + "m_Value": { + "x": 0.20000000298023225, + "y": 0.20000000298023225, + "z": 0.20000000298023225 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [], + "m_ColorMode": 0, + "m_DefaultColor": { + "r": 0.20000000298023225, + "g": 0.20000000298023225, + "b": 0.20000000298023225, + "a": 1.0 + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot", + "m_ObjectId": "5f47fea0efc94a5a80a21ed12763405e", + "m_Id": 2, + "m_DisplayName": "Color B", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "ColorB", + "m_StageCapability": 3, + "m_Value": { + "x": 0.699999988079071, + "y": 0.699999988079071, + "z": 0.699999988079071 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [], + "m_ColorMode": 0, + "m_DefaultColor": { + "r": 0.699999988079071, + "g": 0.699999988079071, + "b": 0.699999988079071, + "a": 1.0 + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.CheckerboardNode", + "m_ObjectId": "5f81ac50e245475c8971b93d00d03832", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Checkerboard", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -373.00006103515627, + "y": 144.99998474121095, + "width": 208.0, + "height": 350.0 + } + }, + "m_Slots": [ + { + "m_Id": "01ed5c2d524d4f869a42c99cec7eadc8" + }, + { + "m_Id": "42abfdabee224ddc8ff4922efaa89542" + }, + { + "m_Id": "5f47fea0efc94a5a80a21ed12763405e" + }, + { + "m_Id": "a67547c8a6d645dd96c16edec8083e22" + }, + { + "m_Id": "9d77ca3643384b3487ba5d79cbd0fa83" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.Rendering.Universal.ShaderGraph.UniversalUnlitSubTarget", + "m_ObjectId": "6a5eebb4f1d74b7fb4fd95c473693457" +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.BlockNode", + "m_ObjectId": "7fe700ca8ba54869adebe13ab4c4a606", + "m_Group": { + "m_Id": "" + }, + "m_Name": "VertexDescription.Tangent", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": 0.0, + "y": 0.0, + "width": 0.0, + "height": 0.0 + } + }, + "m_Slots": [ + { + "m_Id": "13ccede99422486b9fe14793e7304ae1" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SerializedDescriptor": "VertexDescription.Tangent" +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.SubGraphNode", + "m_ObjectId": "8f327dcca7584a34947a0cd47102f879", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Subgraph", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -722.0000610351563, + "y": 11.999994277954102, + "width": 208.0, + "height": 278.0 + } + }, + "m_Slots": [ + { + "m_Id": "c8c9c28b824640c385bab9f3769e7bb6" + }, + { + "m_Id": "343a313961b24dadb56585d51735a832" + }, + { + "m_Id": "d5aa7390c2034a899deef1cd864d70c1" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SerializedSubGraph": "{\n \"subGraph\": {\n \"fileID\": -5475051401550479605,\n \"guid\": \"54a019bb5910fe741ab3ab3840da4fed\",\n \"type\": 3\n }\n}", + "m_PropertyGuids": [ + "d13f5060-dc0f-482c-922b-c82c6802b655" + ], + "m_PropertyIds": [ + -986703847 + ] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot", + "m_ObjectId": "9d77ca3643384b3487ba5d79cbd0fa83", + "m_Id": 4, + "m_DisplayName": "Out", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 2, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.BlockNode", + "m_ObjectId": "a0bdaa47bc3b4570af3972710fbf075d", + "m_Group": { + "m_Id": "" + }, + "m_Name": "VertexDescription.Normal", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": 0.0, + "y": 0.0, + "width": 0.0, + "height": 0.0 + } + }, + "m_Slots": [ + { + "m_Id": "e80fc2b80cb043e2a12ff9e9f6bea0bb" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SerializedDescriptor": "VertexDescription.Normal" +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector2MaterialSlot", + "m_ObjectId": "a67547c8a6d645dd96c16edec8083e22", + "m_Id": 3, + "m_DisplayName": "Frequency", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Frequency", + "m_StageCapability": 3, + "m_Value": { + "x": 1.0, + "y": 1.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot", + "m_ObjectId": "c8a049613f34424185a883ced728a1e3", + "m_Id": 0, + "m_DisplayName": "Base Color", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "BaseColor", + "m_StageCapability": 2, + "m_Value": { + "x": 0.5, + "y": 0.5, + "z": 0.5 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [], + "m_ColorMode": 0, + "m_DefaultColor": { + "r": 0.5, + "g": 0.5, + "b": 0.5, + "a": 1.0 + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "c8c9c28b824640c385bab9f3769e7bb6", + "m_Id": -986703847, + "m_DisplayName": "Scale", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Vector1_521f7973434a4de4992e7a512ad41af5", + "m_StageCapability": 2, + "m_Value": 2.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.Rendering.Universal.ShaderGraph.UniversalTarget", + "m_ObjectId": "d2019cdf6f854770bf611ab9340973c2", + "m_ActiveSubTarget": { + "m_Id": "6a5eebb4f1d74b7fb4fd95c473693457" + }, + "m_SurfaceType": 0, + "m_AlphaMode": 0, + "m_TwoSided": false, + "m_AlphaClip": false, + "m_CustomEditorGUI": "" +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.BlockNode", + "m_ObjectId": "d2963727d5484fe89f506679760f5ef8", + "m_Group": { + "m_Id": "" + }, + "m_Name": "SurfaceDescription.BaseColor", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": 0.0, + "y": 0.0, + "width": 0.0, + "height": 0.0 + } + }, + "m_Slots": [ + { + "m_Id": "c8a049613f34424185a883ced728a1e3" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SerializedDescriptor": "SurfaceDescription.BaseColor" +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "d5aa7390c2034a899deef1cd864d70c1", + "m_Id": 2, + "m_DisplayName": "Out_Color2", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out_Color2", + "m_StageCapability": 2, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.NormalMaterialSlot", + "m_ObjectId": "e80fc2b80cb043e2a12ff9e9f6bea0bb", + "m_Id": 0, + "m_DisplayName": "Normal", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Normal", + "m_StageCapability": 1, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [], + "m_Space": 0 +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.BlockNode", + "m_ObjectId": "f62e09994d1d4057819c7d45d076f210", + "m_Group": { + "m_Id": "" + }, + "m_Name": "VertexDescription.Position", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": 0.0, + "y": 0.0, + "width": 0.0, + "height": 0.0 + } + }, + "m_Slots": [ + { + "m_Id": "f95c2a7483f44456bb8530815b4d8845" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SerializedDescriptor": "VertexDescription.Position" +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.PositionMaterialSlot", + "m_ObjectId": "f95c2a7483f44456bb8530815b4d8845", + "m_Id": 0, + "m_DisplayName": "Position", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Position", + "m_StageCapability": 1, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [], + "m_Space": 0 +} + diff --git a/TestProjects/ShaderGraph/MoveTest/ShaderGraph.shadergraph.meta b/TestProjects/ShaderGraph/MoveTest/ShaderGraph.shadergraph.meta new file mode 100644 index 00000000000..ef1d26301bc --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/ShaderGraph.shadergraph.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: e729d15e0112af8449c81fa47e54974d +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 625f186215c104763be7675aa2d941aa, type: 3} diff --git a/TestProjects/ShaderGraph/MoveTest/SubFolder.meta b/TestProjects/ShaderGraph/MoveTest/SubFolder.meta new file mode 100644 index 00000000000..bfe0e37cd70 --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/SubFolder.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: e189117de233b4e47a45ea376255a482 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/TestProjects/ShaderGraph/MoveTest/SubFolder/Subgraph2.shadersubgraph b/TestProjects/ShaderGraph/MoveTest/SubFolder/Subgraph2.shadersubgraph new file mode 100644 index 00000000000..552112804d4 --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/SubFolder/Subgraph2.shadersubgraph @@ -0,0 +1,539 @@ +{ + "m_SGVersion": 2, + "m_Type": "UnityEditor.ShaderGraph.GraphData", + "m_ObjectId": "3620971b6cb544f4b4a18c745ff096ba", + "m_Properties": [ + { + "m_Id": "778bf597d7144ffa9db4af89ae7d1580" + } + ], + "m_Keywords": [], + "m_Nodes": [ + { + "m_Id": "19fbd86bf60a4f0e92c0e137cffa01d7" + }, + { + "m_Id": "0a75bb2226014428be2998524985391b" + }, + { + "m_Id": "5c617bee56884278998ef59b6638be59" + }, + { + "m_Id": "af3b5ff66f164666bd77baa0e3521bee" + }, + { + "m_Id": "5ff8f89e6101492a94750da8c7dd44bc" + } + ], + "m_GroupDatas": [], + "m_StickyNoteDatas": [], + "m_Edges": [ + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "0a75bb2226014428be2998524985391b" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "af3b5ff66f164666bd77baa0e3521bee" + }, + "m_SlotId": 2 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "5c617bee56884278998ef59b6638be59" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "af3b5ff66f164666bd77baa0e3521bee" + }, + "m_SlotId": 1 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "5ff8f89e6101492a94750da8c7dd44bc" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "af3b5ff66f164666bd77baa0e3521bee" + }, + "m_SlotId": 3 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "af3b5ff66f164666bd77baa0e3521bee" + }, + "m_SlotId": 4 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "19fbd86bf60a4f0e92c0e137cffa01d7" + }, + "m_SlotId": 1 + } + } + ], + "m_VertexContext": { + "m_Position": { + "x": 0.0, + "y": 0.0 + }, + "m_Blocks": [] + }, + "m_FragmentContext": { + "m_Position": { + "x": 0.0, + "y": 0.0 + }, + "m_Blocks": [] + }, + "m_PreviewData": { + "serializedMesh": { + "m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}", + "m_Guid": "" + } + }, + "m_Path": "Sub Graphs", + "m_ConcretePrecision": 0, + "m_PreviewMode": 1, + "m_OutputNode": { + "m_Id": "19fbd86bf60a4f0e92c0e137cffa01d7" + }, + "m_ActiveTargets": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "05d9af751be54bb993808d91d63f8c95", + "m_Id": 0, + "m_DisplayName": "result", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "result", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 1, + "m_Type": "UnityEditor.ShaderGraph.CustomFunctionNode", + "m_ObjectId": "0a75bb2226014428be2998524985391b", + "m_Group": { + "m_Id": "" + }, + "m_Name": "includeFunc4 (Custom Function)", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -786.0, + "y": 0.0, + "width": 230.0, + "height": 278.0 + } + }, + "m_Slots": [ + { + "m_Id": "05d9af751be54bb993808d91d63f8c95" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SourceType": 0, + "m_FunctionName": "includeFunc4", + "m_FunctionSource": "ac472c0f65aed5041a3220f1438b9435", + "m_FunctionBody": "Enter function body here..." +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.SubGraphOutputNode", + "m_ObjectId": "19fbd86bf60a4f0e92c0e137cffa01d7", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Output", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": 0.0, + "y": 0.0, + "width": 0.0, + "height": 0.0 + } + }, + "m_Slots": [ + { + "m_Id": "59ce35a43c2849cfa81293adfe639c6e" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "IsFirstSlotValid": true +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot", + "m_ObjectId": "1eeab05a750748058ebfa0ffdb5d8b47", + "m_Id": 1, + "m_DisplayName": "Color A", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "ColorA", + "m_StageCapability": 3, + "m_Value": { + "x": 0.20000000298023225, + "y": 0.20000000298023225, + "z": 0.20000000298023225 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [], + "m_ColorMode": 0, + "m_DefaultColor": { + "r": 0.20000000298023225, + "g": 0.20000000298023225, + "b": 0.20000000298023225, + "a": 1.0 + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot", + "m_ObjectId": "29d56df2be6d4e1180c52cf3c7ae3482", + "m_Id": 4, + "m_DisplayName": "Out", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 2, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "34fb4267eda54c9ca56c26d4da3a5209", + "m_Id": 0, + "m_DisplayName": "Scale", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": 0.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector2MaterialSlot", + "m_ObjectId": "4aef14985cca439baff21266fc7ab203", + "m_Id": 3, + "m_DisplayName": "Frequency", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Frequency", + "m_StageCapability": 3, + "m_Value": { + "x": 2.0, + "y": 2.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "59ce35a43c2849cfa81293adfe639c6e", + "m_Id": 1, + "m_DisplayName": "Out_Vector4", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "OutVector4", + "m_StageCapability": 2, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 1, + "m_Type": "UnityEditor.ShaderGraph.CustomFunctionNode", + "m_ObjectId": "5c617bee56884278998ef59b6638be59", + "m_Group": { + "m_Id": "" + }, + "m_Name": "includeFunc3 (Custom Function)", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -786.0, + "y": -278.0, + "width": 222.0, + "height": 278.0 + } + }, + "m_Slots": [ + { + "m_Id": "cb4afb0acb12438d9b6804043f35e3ae" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SourceType": 0, + "m_FunctionName": "includeFunc3", + "m_FunctionSource": "ac472c0f65aed5041a3220f1438b9435", + "m_FunctionBody": "Enter function body here..." +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.PropertyNode", + "m_ObjectId": "5ff8f89e6101492a94750da8c7dd44bc", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Property", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -991.0, + "y": -93.0, + "width": 0.0, + "height": 0.0 + } + }, + "m_Slots": [ + { + "m_Id": "34fb4267eda54c9ca56c26d4da3a5209" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_Property": { + "m_Id": "778bf597d7144ffa9db4af89ae7d1580" + } +} + +{ + "m_SGVersion": 1, + "m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty", + "m_ObjectId": "778bf597d7144ffa9db4af89ae7d1580", + "m_Guid": { + "m_GuidSerialized": "71b744ba-2d7b-4e69-935b-b7a93d9bc1c9" + }, + "m_Name": "Scale", + "m_DefaultReferenceName": "Vector1_778bf597d7144ffa9db4af89ae7d1580", + "m_OverrideReferenceName": "", + "m_GeneratePropertyBlock": true, + "m_Precision": 0, + "overrideHLSLDeclaration": false, + "hlslDeclarationOverride": 0, + "m_Hidden": false, + "m_Value": 4.0, + "m_FloatType": 0, + "m_RangeValues": { + "x": 0.0, + "y": 1.0 + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.CheckerboardNode", + "m_ObjectId": "af3b5ff66f164666bd77baa0e3521bee", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Checkerboard", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -414.0, + "y": -156.0, + "width": 208.0, + "height": 350.0 + } + }, + "m_Slots": [ + { + "m_Id": "e736c6cad0414e5195563a93d7e8428e" + }, + { + "m_Id": "1eeab05a750748058ebfa0ffdb5d8b47" + }, + { + "m_Id": "fdcc130d756f4d0a9be3627262f5dfbd" + }, + { + "m_Id": "4aef14985cca439baff21266fc7ab203" + }, + { + "m_Id": "29d56df2be6d4e1180c52cf3c7ae3482" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "cb4afb0acb12438d9b6804043f35e3ae", + "m_Id": 0, + "m_DisplayName": "result", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "result", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.UVMaterialSlot", + "m_ObjectId": "e736c6cad0414e5195563a93d7e8428e", + "m_Id": 0, + "m_DisplayName": "UV", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "UV", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0 + }, + "m_Labels": [], + "m_Channel": 0 +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot", + "m_ObjectId": "fdcc130d756f4d0a9be3627262f5dfbd", + "m_Id": 2, + "m_DisplayName": "Color B", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "ColorB", + "m_StageCapability": 3, + "m_Value": { + "x": 0.699999988079071, + "y": 0.699999988079071, + "z": 0.699999988079071 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [], + "m_ColorMode": 0, + "m_DefaultColor": { + "r": 0.699999988079071, + "g": 0.699999988079071, + "b": 0.699999988079071, + "a": 1.0 + } +} + diff --git a/TestProjects/ShaderGraph/MoveTest/SubFolder/Subgraph2.shadersubgraph.meta b/TestProjects/ShaderGraph/MoveTest/SubFolder/Subgraph2.shadersubgraph.meta new file mode 100644 index 00000000000..5d7589129af --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/SubFolder/Subgraph2.shadersubgraph.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 349d7c7229cb34843a942bded55e7777 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3} diff --git a/TestProjects/ShaderGraph/MoveTest/SubFolder/includeFile2.hlsl b/TestProjects/ShaderGraph/MoveTest/SubFolder/includeFile2.hlsl new file mode 100644 index 00000000000..f52d9e35568 --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/SubFolder/includeFile2.hlsl @@ -0,0 +1,10 @@ + +void includeFunc3_float(out float4 result) +{ + result = float4(0.1f, 1.0f, 0.35f, 1.0f); +} + +void includeFunc4_float(out float4 result) +{ + result = float4(1.0f, 0.1f, 0.9f, 1.0f); +} diff --git a/TestProjects/ShaderGraph/MoveTest/SubFolder/includeFile2.hlsl.meta b/TestProjects/ShaderGraph/MoveTest/SubFolder/includeFile2.hlsl.meta new file mode 100644 index 00000000000..f5588b783f8 --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/SubFolder/includeFile2.hlsl.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: ac472c0f65aed5041a3220f1438b9435 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/TestProjects/ShaderGraph/MoveTest/Subgraph.shadersubgraph b/TestProjects/ShaderGraph/MoveTest/Subgraph.shadersubgraph new file mode 100644 index 00000000000..5225d847eea --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/Subgraph.shadersubgraph @@ -0,0 +1,666 @@ +{ + "m_SGVersion": 2, + "m_Type": "UnityEditor.ShaderGraph.GraphData", + "m_ObjectId": "0261eee70f304ee9adce195e40eee0dd", + "m_Properties": [ + { + "m_Id": "521f7973434a4de4992e7a512ad41af5" + } + ], + "m_Keywords": [], + "m_Nodes": [ + { + "m_Id": "2c8dbb9689d143b48a0a9791ab5a0566" + }, + { + "m_Id": "347cca5e7b924ada92e8abcee0033a75" + }, + { + "m_Id": "54fc61edc0ce43dbacb78189bb8d1391" + }, + { + "m_Id": "d18e47150426447b8668119f2b46c772" + }, + { + "m_Id": "6127dd9553c04fffb79be2ab42882bb2" + }, + { + "m_Id": "860edfd3f92b45b292c0945ad875cb02" + } + ], + "m_GroupDatas": [], + "m_StickyNoteDatas": [], + "m_Edges": [ + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "347cca5e7b924ada92e8abcee0033a75" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "d18e47150426447b8668119f2b46c772" + }, + "m_SlotId": 1 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "54fc61edc0ce43dbacb78189bb8d1391" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "d18e47150426447b8668119f2b46c772" + }, + "m_SlotId": 2 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "6127dd9553c04fffb79be2ab42882bb2" + }, + "m_SlotId": 0 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "d18e47150426447b8668119f2b46c772" + }, + "m_SlotId": 3 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "860edfd3f92b45b292c0945ad875cb02" + }, + "m_SlotId": 1 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "2c8dbb9689d143b48a0a9791ab5a0566" + }, + "m_SlotId": 2 + } + }, + { + "m_OutputSlot": { + "m_Node": { + "m_Id": "d18e47150426447b8668119f2b46c772" + }, + "m_SlotId": 4 + }, + "m_InputSlot": { + "m_Node": { + "m_Id": "2c8dbb9689d143b48a0a9791ab5a0566" + }, + "m_SlotId": 1 + } + } + ], + "m_VertexContext": { + "m_Position": { + "x": 0.0, + "y": 0.0 + }, + "m_Blocks": [] + }, + "m_FragmentContext": { + "m_Position": { + "x": 0.0, + "y": 0.0 + }, + "m_Blocks": [] + }, + "m_PreviewData": { + "serializedMesh": { + "m_SerializedMesh": "{\"mesh\":{\"instanceID\":0}}", + "m_Guid": "" + } + }, + "m_Path": "Sub Graphs", + "m_ConcretePrecision": 0, + "m_PreviewMode": 1, + "m_OutputNode": { + "m_Id": "2c8dbb9689d143b48a0a9791ab5a0566" + }, + "m_ActiveTargets": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot", + "m_ObjectId": "05a55f893ebe43049e445e0951562c7a", + "m_Id": 4, + "m_DisplayName": "Out", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 2, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector2MaterialSlot", + "m_ObjectId": "2075d8729b8f48448c7deb3bdba70c63", + "m_Id": 3, + "m_DisplayName": "Frequency", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Frequency", + "m_StageCapability": 3, + "m_Value": { + "x": 2.0, + "y": 2.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.SubGraphOutputNode", + "m_ObjectId": "2c8dbb9689d143b48a0a9791ab5a0566", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Output", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": 113.0, + "y": -143.0, + "width": 120.0, + "height": 77.0 + } + }, + "m_Slots": [ + { + "m_Id": "fbd9ef8166cd439681ef814265a555dd" + }, + { + "m_Id": "3dcebbdc227f4854829f682657b6ffdf" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "IsFirstSlotValid": true +} + +{ + "m_SGVersion": 1, + "m_Type": "UnityEditor.ShaderGraph.CustomFunctionNode", + "m_ObjectId": "347cca5e7b924ada92e8abcee0033a75", + "m_Group": { + "m_Id": "" + }, + "m_Name": "includeFunc (Custom Function)", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -574.0, + "y": -220.0, + "width": 222.0, + "height": 278.0 + } + }, + "m_Slots": [ + { + "m_Id": "a7537929289b41bc8782edb7b168e3e5" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SourceType": 0, + "m_FunctionName": "includeFunc", + "m_FunctionSource": "11f06b713a285c94d8ee36206d4f12e1", + "m_FunctionBody": "Enter function body here..." +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "3dcebbdc227f4854829f682657b6ffdf", + "m_Id": 2, + "m_DisplayName": "Out_Color2", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Out_Color2", + "m_StageCapability": 2, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "42d3e3fc06e34f20a513ce27929006a2", + "m_Id": 0, + "m_DisplayName": "Scale", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "Out", + "m_StageCapability": 3, + "m_Value": 0.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + +{ + "m_SGVersion": 1, + "m_Type": "UnityEditor.ShaderGraph.Internal.Vector1ShaderProperty", + "m_ObjectId": "521f7973434a4de4992e7a512ad41af5", + "m_Guid": { + "m_GuidSerialized": "d13f5060-dc0f-482c-922b-c82c6802b655" + }, + "m_Name": "Scale", + "m_DefaultReferenceName": "Vector1_521f7973434a4de4992e7a512ad41af5", + "m_OverrideReferenceName": "", + "m_GeneratePropertyBlock": true, + "m_Precision": 0, + "overrideHLSLDeclaration": false, + "hlslDeclarationOverride": 0, + "m_Hidden": false, + "m_Value": 2.0, + "m_FloatType": 0, + "m_RangeValues": { + "x": 0.0, + "y": 1.0 + } +} + +{ + "m_SGVersion": 1, + "m_Type": "UnityEditor.ShaderGraph.CustomFunctionNode", + "m_ObjectId": "54fc61edc0ce43dbacb78189bb8d1391", + "m_Group": { + "m_Id": "" + }, + "m_Name": "includeFunc2 (Custom Function)", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -574.0, + "y": 58.0, + "width": 229.0, + "height": 278.0 + } + }, + "m_Slots": [ + { + "m_Id": "c5282770d47f414b865653ff1f7308bc" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SourceType": 0, + "m_FunctionName": "includeFunc2", + "m_FunctionSource": "11f06b713a285c94d8ee36206d4f12e1", + "m_FunctionBody": "Enter function body here..." +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.PropertyNode", + "m_ObjectId": "6127dd9553c04fffb79be2ab42882bb2", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Property", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -789.3341674804688, + "y": 28.896644592285158, + "width": 0.0, + "height": 0.0 + } + }, + "m_Slots": [ + { + "m_Id": "42d3e3fc06e34f20a513ce27929006a2" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_Property": { + "m_Id": "521f7973434a4de4992e7a512ad41af5" + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.UVMaterialSlot", + "m_ObjectId": "67d3827495b44f11b3576d27a3ab8300", + "m_Id": 0, + "m_DisplayName": "UV", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "UV", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0 + }, + "m_Labels": [], + "m_Channel": 0 +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.SubGraphNode", + "m_ObjectId": "860edfd3f92b45b292c0945ad875cb02", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Subgraph2", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -202.0000457763672, + "y": 335.9999694824219, + "width": 208.0, + "height": 278.0 + } + }, + "m_Slots": [ + { + "m_Id": "a7be6e56093c4f3da8b64c8185c90d7f" + }, + { + "m_Id": "abe72f63b3d942f79a768f26aa0d90a2" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SerializedSubGraph": "{\n \"subGraph\": {\n \"fileID\": -5475051401550479605,\n \"guid\": \"349d7c7229cb34843a942bded55e7777\",\n \"type\": 3\n }\n}", + "m_PropertyGuids": [ + "71b744ba-2d7b-4e69-935b-b7a93d9bc1c9" + ], + "m_PropertyIds": [ + -338949606 + ] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "a7537929289b41bc8782edb7b168e3e5", + "m_Id": 0, + "m_DisplayName": "result", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "result", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "a7be6e56093c4f3da8b64c8185c90d7f", + "m_Id": -338949606, + "m_DisplayName": "Scale", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Vector1_778bf597d7144ffa9db4af89ae7d1580", + "m_StageCapability": 2, + "m_Value": 4.0, + "m_DefaultValue": 0.0, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "abe72f63b3d942f79a768f26aa0d90a2", + "m_Id": 1, + "m_DisplayName": "Out_Vector4", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "OutVector4", + "m_StageCapability": 2, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot", + "m_ObjectId": "b847008d598e4c2a832d4ad00eb7ed24", + "m_Id": 2, + "m_DisplayName": "Color B", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "ColorB", + "m_StageCapability": 3, + "m_Value": { + "x": 0.699999988079071, + "y": 0.699999988079071, + "z": 0.699999988079071 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [], + "m_ColorMode": 0, + "m_DefaultColor": { + "r": 0.699999988079071, + "g": 0.699999988079071, + "b": 0.699999988079071, + "a": 1.0 + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "c5282770d47f414b865653ff1f7308bc", + "m_Id": 0, + "m_DisplayName": "result", + "m_SlotType": 1, + "m_Hidden": false, + "m_ShaderOutputName": "result", + "m_StageCapability": 3, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.CheckerboardNode", + "m_ObjectId": "d18e47150426447b8668119f2b46c772", + "m_Group": { + "m_Id": "" + }, + "m_Name": "Checkerboard", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": -202.0, + "y": -98.0, + "width": 208.0, + "height": 350.0 + } + }, + "m_Slots": [ + { + "m_Id": "67d3827495b44f11b3576d27a3ab8300" + }, + { + "m_Id": "d9a352c98a28424881bee81821b492b4" + }, + { + "m_Id": "b847008d598e4c2a832d4ad00eb7ed24" + }, + { + "m_Id": "2075d8729b8f48448c7deb3bdba70c63" + }, + { + "m_Id": "05a55f893ebe43049e445e0951562c7a" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.ColorRGBMaterialSlot", + "m_ObjectId": "d9a352c98a28424881bee81821b492b4", + "m_Id": 1, + "m_DisplayName": "Color A", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "ColorA", + "m_StageCapability": 3, + "m_Value": { + "x": 0.20000000298023225, + "y": 0.20000000298023225, + "z": 0.20000000298023225 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0 + }, + "m_Labels": [], + "m_ColorMode": 0, + "m_DefaultColor": { + "r": 0.20000000298023225, + "g": 0.20000000298023225, + "b": 0.20000000298023225, + "a": 1.0 + } +} + +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector4MaterialSlot", + "m_ObjectId": "fbd9ef8166cd439681ef814265a555dd", + "m_Id": 1, + "m_DisplayName": "Out_Color1", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "Out_Color1", + "m_StageCapability": 2, + "m_Value": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_DefaultValue": { + "x": 0.0, + "y": 0.0, + "z": 0.0, + "w": 0.0 + }, + "m_Labels": [] +} + diff --git a/TestProjects/ShaderGraph/MoveTest/Subgraph.shadersubgraph.meta b/TestProjects/ShaderGraph/MoveTest/Subgraph.shadersubgraph.meta new file mode 100644 index 00000000000..868a5cb1c15 --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/Subgraph.shadersubgraph.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 54a019bb5910fe741ab3ab3840da4fed +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3} diff --git a/TestProjects/ShaderGraph/MoveTest/includeFile.hlsl b/TestProjects/ShaderGraph/MoveTest/includeFile.hlsl new file mode 100644 index 00000000000..2a93c7be3a7 --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/includeFile.hlsl @@ -0,0 +1,10 @@ + +void includeFunc_float(out float4 result) +{ + result = float4(1.0f, 0.5f, 0.25f, 1.0f); +} + +void includeFunc2_float(out float4 result) +{ + result = float4(0.1f, 0.2f, 0.9f, 1.0f); +} diff --git a/TestProjects/ShaderGraph/MoveTest/includeFile.hlsl.meta b/TestProjects/ShaderGraph/MoveTest/includeFile.hlsl.meta new file mode 100644 index 00000000000..739e0b3d1ab --- /dev/null +++ b/TestProjects/ShaderGraph/MoveTest/includeFile.hlsl.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 11f06b713a285c94d8ee36206d4f12e1 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + preprocessorOverride: 0 + userData: + assetBundleName: + assetBundleVariant: diff --git a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs index 0819d926422..855b733f434 100644 --- a/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs +++ b/com.unity.render-pipelines.high-definition/Editor/Material/ShaderGraph/HDSubTarget.cs @@ -140,22 +140,23 @@ protected SubShaderDescriptor PostProcessSubShader(SubShaderDescriptor subShader passDescriptor.requiredFields.Add(subShaderField); IncludeCollection finalIncludes = new IncludeCollection(); - var includeList = passDescriptor.includes.Select(include => include.descriptor).ToList(); // Replace include placeholders if necessary: foreach (var include in passDescriptor.includes) { - if (include.descriptor.value == CoreIncludes.kPassPlaceholder) - include.descriptor.value = subShaderInclude; - if (include.descriptor.value == CoreIncludes.kPostDecalsPlaceholder) - include.descriptor.value = postDecalsInclude; - if (include.descriptor.value == CoreIncludes.kRaytracingPlaceholder) - include.descriptor.value = raytracingInclude; - if (include.descriptor.value == CoreIncludes.kPathtracingPlaceholder) - include.descriptor.value = pathtracingInclude; - - if (!String.IsNullOrEmpty(include.descriptor.value)) - finalIncludes.Add(include.descriptor.value, include.descriptor.location, include.fieldConditions); + var path = include.path; + + if (path == CoreIncludes.kPassPlaceholder) + path = subShaderInclude; + if (path == CoreIncludes.kPostDecalsPlaceholder) + path = postDecalsInclude; + if (path == CoreIncludes.kRaytracingPlaceholder) + path = raytracingInclude; + if (path == CoreIncludes.kPathtracingPlaceholder) + path = pathtracingInclude; + + if (!String.IsNullOrEmpty(path)) + finalIncludes.Add(path, include.location, include.fieldConditions); } passDescriptor.includes = finalIncludes; diff --git a/com.unity.shadergraph/CHANGELOG.md b/com.unity.shadergraph/CHANGELOG.md index 8ba4d9f3c2c..1c60fb35d15 100644 --- a/com.unity.shadergraph/CHANGELOG.md +++ b/com.unity.shadergraph/CHANGELOG.md @@ -11,6 +11,7 @@ The version number for this package has increased due to a version update of a r ### Fixed - Fixed the Custom Editor GUI field in the Graph settings that was ignored. +- Node included HLSL files are now tracked more robustly, so they work after file moves and renames [1301915] (https://issuetracker.unity3d.com/product/unity/issues/guid/1301915/) ## [11.0.0] - 2020-10-21 diff --git a/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxMappingNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxMappingNode.cs index d889b848b27..1b86815ed7b 100644 --- a/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxMappingNode.cs +++ b/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxMappingNode.cs @@ -50,11 +50,6 @@ public sealed override void UpdateNodeAfterDeserialization() }); } - string GetFunctionName() - { - return $"Unity_ParallaxMapping_{concretePrecision.ToShaderString()}"; - } - public override void Setup() { base.Setup(); @@ -64,11 +59,7 @@ public override void Setup() public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode) { - var perPixelDisplacementInclude = @"#include ""Packages/com.unity.render-pipelines.core/ShaderLibrary/ParallaxMapping.hlsl"""; - registry.ProvideFunction(GetFunctionName(), s => - { - s.AppendLine(perPixelDisplacementInclude); - }); + registry.RequiresIncludePath("Packages/com.unity.render-pipelines.core/ShaderLibrary/ParallaxMapping.hlsl"); } public void GenerateNodeCode(ShaderStringBuilder sb, GenerationMode generationMode) diff --git a/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxOcclusionMappingNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxOcclusionMappingNode.cs index 704df7ba126..c1f7ff97dbf 100644 --- a/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxOcclusionMappingNode.cs +++ b/com.unity.shadergraph/Editor/Data/Nodes/UV/ParallaxOcclusionMappingNode.cs @@ -78,6 +78,8 @@ public override void Setup() public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode generationMode) { + // we don't declare this include via the registry include path + // because it uses macro magic, and can be included more than once, generating different functions string perPixelDisplacementInclude = @"#include ""Packages/com.unity.render-pipelines.core/ShaderLibrary/PerPixelDisplacement.hlsl"""; // Texture sample inputs diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Utility/CustomFunctionNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/Utility/CustomFunctionNode.cs index c18e4a26dae..02f4dfe32f4 100644 --- a/com.unity.shadergraph/Editor/Data/Nodes/Utility/CustomFunctionNode.cs +++ b/com.unity.shadergraph/Editor/Data/Nodes/Utility/CustomFunctionNode.cs @@ -249,18 +249,7 @@ public void GenerateNodeFunction(FunctionRegistry registry, GenerationMode gener if (string.IsNullOrEmpty(path)) path = functionSource; - string hash; - try - { - hash = AssetDatabase.GetAssetDependencyHash(path).ToString(); - } - catch - { - hash = "Failed to compute hash for include"; - } - - builder.AppendLine($"// {hash}"); - builder.AppendLine($"#include \"{path}\""); + registry.RequiresIncludePath(path); }); break; case HlslSourceType.String: @@ -422,9 +411,9 @@ public override void ValidateNode() base.ValidateNode(); } - public bool Reload(HashSet changedFileDependencies) + public bool Reload(HashSet changedFileDependencyGUIDs) { - if (changedFileDependencies.Contains(m_FunctionSource)) + if (changedFileDependencyGUIDs.Contains(m_FunctionSource)) { owner.ClearErrorsForNode(this); ValidateNode(); @@ -443,6 +432,8 @@ public static string UpgradeFunctionSource(string functionSource) Guid guid; if (!string.IsNullOrEmpty(functionSource) && !Guid.TryParse(functionSource, out guid)) { + // not sure why we don't use AssetDatabase.AssetPathToGUID... + // I guess we are testing that it actually exists and can be loaded here before converting? string guidString = string.Empty; TextAsset textAsset = AssetDatabase.LoadAssetAtPath(functionSource); if (textAsset != null) diff --git a/com.unity.shadergraph/Editor/Data/Nodes/Utility/SubGraphNode.cs b/com.unity.shadergraph/Editor/Data/Nodes/Utility/SubGraphNode.cs index 852e8a2779d..57dddd87179 100644 --- a/com.unity.shadergraph/Editor/Data/Nodes/Utility/SubGraphNode.cs +++ b/com.unity.shadergraph/Editor/Data/Nodes/Utility/SubGraphNode.cs @@ -250,9 +250,9 @@ public void OnEnable() UpdateSlots(); } - public bool Reload(HashSet changedFileDependencies) + public bool Reload(HashSet changedFileDependencyGUIDs) { - if (!changedFileDependencies.Contains(subGraphGuid)) + if (!changedFileDependencyGUIDs.Contains(subGraphGuid)) { return false; } @@ -263,7 +263,7 @@ public bool Reload(HashSet changedFileDependencies) return true; } - if (changedFileDependencies.Contains(asset.assetGuid) || asset.descendents.Any(changedFileDependencies.Contains)) + if (changedFileDependencyGUIDs.Contains(asset.assetGuid) || asset.descendents.Any(changedFileDependencyGUIDs.Contains)) { m_SubGraph = null; UpdateSlots(); @@ -564,6 +564,8 @@ public virtual void GenerateNodeFunction(FunctionRegistry registry, GenerationMo if (asset == null || hasError) return; + registry.RequiresIncludes(asset.includes); + foreach (var function in asset.functions) { registry.ProvideFunction(function.key, s => diff --git a/com.unity.shadergraph/Editor/Data/SubGraph/SubGraphAsset.cs b/com.unity.shadergraph/Editor/Data/SubGraph/SubGraphAsset.cs index 6a3e8aa2c1b..98df8c1214c 100644 --- a/com.unity.shadergraph/Editor/Data/SubGraph/SubGraphAsset.cs +++ b/com.unity.shadergraph/Editor/Data/SubGraph/SubGraphAsset.cs @@ -54,6 +54,8 @@ class SubGraphAsset : ScriptableObject, ISerializationCallbackReceiver public List functions = new List(); + public IncludeCollection includes; + public List vtFeedbackVariables = new List(); private SubGraphData m_SubGraphData; diff --git a/com.unity.shadergraph/Editor/Data/Util/FunctionRegistry.cs b/com.unity.shadergraph/Editor/Data/Util/FunctionRegistry.cs index ac8a07c6743..2c54976a16b 100644 --- a/com.unity.shadergraph/Editor/Data/Util/FunctionRegistry.cs +++ b/com.unity.shadergraph/Editor/Data/Util/FunctionRegistry.cs @@ -15,10 +15,12 @@ class FunctionRegistry Dictionary m_Sources = new Dictionary(); bool m_Validate = false; ShaderStringBuilder m_Builder; + IncludeCollection m_Includes; - public FunctionRegistry(ShaderStringBuilder builder, bool validate = false) + public FunctionRegistry(ShaderStringBuilder builder, IncludeCollection includes, bool validate = false) { m_Builder = builder; + m_Includes = includes; m_Validate = validate; } @@ -28,6 +30,16 @@ public FunctionRegistry(ShaderStringBuilder builder, bool validate = false) public List names { get; } = new List(); + public void RequiresIncludes(IncludeCollection includes) + { + m_Includes.Add(includes); + } + + public void RequiresIncludePath(string includePath) + { + m_Includes.Add(includePath, IncludeLocation.Pregraph); + } + public void ProvideFunction(string name, Action generator) { FunctionSource existingSource; diff --git a/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs b/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs index 00318ec96b1..eb8cd92813f 100644 --- a/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs +++ b/com.unity.shadergraph/Editor/Drawing/MaterialGraphEditWindow.cs @@ -40,7 +40,7 @@ class MaterialGraphEditWindow : EditorWindow string m_LastSerializedFileContents; [NonSerialized] - HashSet m_ChangedFileDependencies = new HashSet(); + HashSet m_ChangedFileDependencyGUIDs = new HashSet(); ColorSpace m_ColorSpace; RenderPipelineAsset m_RenderPipelineAsset; @@ -282,13 +282,13 @@ void Update() updateTitle = true; } - if (m_ChangedFileDependencies.Count > 0 && graphObject != null && graphObject.graph != null) + if (m_ChangedFileDependencyGUIDs.Count > 0 && graphObject != null && graphObject.graph != null) { bool reloadedSomething = false; var subGraphNodes = graphObject.graph.GetNodes(); foreach (var subGraphNode in subGraphNodes) { - var reloaded = subGraphNode.Reload(m_ChangedFileDependencies); + var reloaded = subGraphNode.Reload(m_ChangedFileDependencyGUIDs); reloadedSomething |= reloaded; } if (subGraphNodes.Count() > 0) @@ -300,7 +300,7 @@ void Update() } foreach (var customFunctionNode in graphObject.graph.GetNodes()) { - var reloaded = customFunctionNode.Reload(m_ChangedFileDependencies); + var reloaded = customFunctionNode.Reload(m_ChangedFileDependencyGUIDs); reloadedSomething |= reloaded; } @@ -308,7 +308,7 @@ void Update() if (reloadedSomething) updateTitle = true; - m_ChangedFileDependencies.Clear(); + m_ChangedFileDependencyGUIDs.Clear(); } var wasUndoRedoPerformed = graphObject.wasUndoRedoPerformed; @@ -343,11 +343,11 @@ void Update() } } - public void ReloadSubGraphsOnNextUpdate(List changedFiles) + public void ReloadSubGraphsOnNextUpdate(List changedFileGUIDs) { - foreach (var changedFile in changedFiles) + foreach (var changedFileGUID in changedFileGUIDs) { - m_ChangedFileDependencies.Add(changedFile); + m_ChangedFileDependencyGUIDs.Add(changedFileGUID); } } diff --git a/com.unity.shadergraph/Editor/Generation/Collections/DefineCollection.cs b/com.unity.shadergraph/Editor/Generation/Collections/DefineCollection.cs index 4b3471250cd..969f9e9b58b 100644 --- a/com.unity.shadergraph/Editor/Generation/Collections/DefineCollection.cs +++ b/com.unity.shadergraph/Editor/Generation/Collections/DefineCollection.cs @@ -6,7 +6,7 @@ namespace UnityEditor.ShaderGraph [GenerationAPI] internal class DefineCollection : IEnumerable { - public class Item : IConditional, IShaderString + public class Item : IConditional { public KeywordDescriptor descriptor { get; } public FieldCondition[] fieldConditions { get; } diff --git a/com.unity.shadergraph/Editor/Generation/Collections/IncludeCollection.cs b/com.unity.shadergraph/Editor/Generation/Collections/IncludeCollection.cs index 71935e065c4..d87c3d92ce8 100644 --- a/com.unity.shadergraph/Editor/Generation/Collections/IncludeCollection.cs +++ b/com.unity.shadergraph/Editor/Generation/Collections/IncludeCollection.cs @@ -1,61 +1,85 @@ +using System; using System.Collections; using System.Collections.Generic; +using UnityEngine; namespace UnityEditor.ShaderGraph { [GenerationAPI] - internal class IncludeCollection : IEnumerable + [Serializable] + internal class IncludeCollection : IEnumerable { - public class Item : IConditional, IShaderString - { - public IncludeDescriptor descriptor { get; } - public FieldCondition[] fieldConditions { get; } - public string value => $"#include \"{descriptor.value}\""; - - public Item(IncludeDescriptor descriptor, FieldCondition[] fieldConditions) - { - this.descriptor = descriptor; - this.fieldConditions = fieldConditions; - } - } - - readonly List m_Items; + [SerializeField] + List includes; public IncludeCollection() { - m_Items = new List(); + includes = new List(); } public IncludeCollection Add(IncludeCollection includes) { - foreach (IncludeCollection.Item item in includes) + if (includes != null) { - m_Items.Add(item); + foreach (var include in includes) + { + AddInternal(include.guid, include.path, include.location, include.fieldConditions); + } } return this; } - public IncludeCollection Add(string include, IncludeLocation location) + public IncludeCollection Add(string includePath, IncludeLocation location) { - m_Items.Add(new Item(new IncludeDescriptor() { value = include, location = location }, null)); - return this; + var guid = AssetDatabase.AssetPathToGUID(includePath); + return AddInternal(guid, includePath, location); } - public IncludeCollection Add(string include, IncludeLocation location, FieldCondition fieldCondition) + public IncludeCollection Add(string includePath, IncludeLocation location, FieldCondition fieldCondition) { - m_Items.Add(new Item(new IncludeDescriptor() { value = include, location = location }, new FieldCondition[] { fieldCondition })); - return this; + var guid = AssetDatabase.AssetPathToGUID(includePath); + return AddInternal(guid, includePath, location, new FieldCondition[] { fieldCondition }); } - public IncludeCollection Add(string include, IncludeLocation location, FieldCondition[] fieldConditions) + public IncludeCollection Add(string includePath, IncludeLocation location, FieldCondition[] fieldConditions) { - m_Items.Add(new Item(new IncludeDescriptor() { value = include, location = location }, fieldConditions)); + var guid = AssetDatabase.AssetPathToGUID(includePath); + return AddInternal(guid, includePath, location, fieldConditions); + } + + public IncludeCollection AddInternal(string includeGUID, string includePath, IncludeLocation location, FieldCondition[] fieldConditions = null) + { + if (string.IsNullOrEmpty(includeGUID)) + { + // either the file doesn't exist, or this is a placeholder + // de-duplicate by path + int existing = includes.FindIndex(i => i.path == includePath); + if (existing < 0) + includes.Add(new IncludeDescriptor(null, includePath, location, fieldConditions)); + return this; + } + else + { + // de-duplicate by GUID + int existing = includes.FindIndex(i => i.guid == includeGUID); + if (existing < 0) + { + // no duplicates, just add it + includes.Add(new IncludeDescriptor(includeGUID, includePath, location, fieldConditions)); + } + else + { + // duplicate file -- we could double check they are the same... + // they might have different field conditions that require merging, for example. + // But for now we'll just assume they are the same and drop the new one + } + } return this; } - public IEnumerator GetEnumerator() + public IEnumerator GetEnumerator() { - return m_Items.GetEnumerator(); + return includes.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() diff --git a/com.unity.shadergraph/Editor/Generation/Collections/KeywordCollection.cs b/com.unity.shadergraph/Editor/Generation/Collections/KeywordCollection.cs index 134ecc2066a..d3318d4f004 100644 --- a/com.unity.shadergraph/Editor/Generation/Collections/KeywordCollection.cs +++ b/com.unity.shadergraph/Editor/Generation/Collections/KeywordCollection.cs @@ -6,7 +6,7 @@ namespace UnityEditor.ShaderGraph [GenerationAPI] internal class KeywordCollection : IEnumerable { - public class Item : IConditional, IShaderString + public class Item : IConditional { public KeywordDescriptor descriptor { get; } public FieldCondition[] fieldConditions { get; } diff --git a/com.unity.shadergraph/Editor/Generation/Collections/PragmaCollection.cs b/com.unity.shadergraph/Editor/Generation/Collections/PragmaCollection.cs index f22714c1f37..bad1149161d 100644 --- a/com.unity.shadergraph/Editor/Generation/Collections/PragmaCollection.cs +++ b/com.unity.shadergraph/Editor/Generation/Collections/PragmaCollection.cs @@ -6,7 +6,7 @@ namespace UnityEditor.ShaderGraph [GenerationAPI] internal class PragmaCollection : IEnumerable { - public class Item : IConditional, IShaderString + public class Item : IConditional { public PragmaDescriptor descriptor { get; } public FieldCondition[] fieldConditions { get; } diff --git a/com.unity.shadergraph/Editor/Generation/Collections/RenderStateCollection.cs b/com.unity.shadergraph/Editor/Generation/Collections/RenderStateCollection.cs index 4c67092d4b4..6a0e35005ff 100644 --- a/com.unity.shadergraph/Editor/Generation/Collections/RenderStateCollection.cs +++ b/com.unity.shadergraph/Editor/Generation/Collections/RenderStateCollection.cs @@ -6,7 +6,7 @@ namespace UnityEditor.ShaderGraph [GenerationAPI] internal class RenderStateCollection : IEnumerable { - public class Item : IConditional, IShaderString + public class Item : IConditional { public RenderStateDescriptor descriptor { get; } public FieldCondition[] fieldConditions { get; } diff --git a/com.unity.shadergraph/Editor/Generation/Descriptors/IncludeDescriptor.cs b/com.unity.shadergraph/Editor/Generation/Descriptors/IncludeDescriptor.cs index b8652cc8b0a..579e22b4026 100644 --- a/com.unity.shadergraph/Editor/Generation/Descriptors/IncludeDescriptor.cs +++ b/com.unity.shadergraph/Editor/Generation/Descriptors/IncludeDescriptor.cs @@ -1,9 +1,49 @@ +using System; +using UnityEngine; + namespace UnityEditor.ShaderGraph { [GenerationAPI] - internal class IncludeDescriptor + [Serializable] + internal class IncludeDescriptor : IConditional { - public string value; - public IncludeLocation location; + public IncludeDescriptor(string guid, string path, IncludeLocation location, FieldCondition[] fieldConditions) + { + _guid = guid; + _path = path; + _location = location; + this.fieldConditions = fieldConditions; + } + + [SerializeField] + string _guid; + public string guid => _guid; + + // NOTE: this path is NOT guaranteed to be correct -- it's only the path that was given to us when this descriptor was constructed. + // if the file was moved, it may not be correct. use the GUID to get the current REAL path via AssetDatabase.GUIDToAssetPath + [SerializeField] + string _path; + public string path => _path; + + [SerializeField] + IncludeLocation _location; + public IncludeLocation location => _location; + + // NOTE: this is not serialized at the moment.. as it's not needed. + // (serialization only used for subgraph includes, coming from nodes, which can't have conditions) + public FieldCondition[] fieldConditions { get; } + + public string value + { + get + { + // we must get the path from asset database to ensure it is correct after file moves + var realPath = AssetDatabase.GUIDToAssetPath(guid); + if (string.IsNullOrEmpty(realPath)) + return $"// missing include file: {path} ({guid})"; + else + return $"#include \"{realPath}\""; + } + } } } diff --git a/com.unity.shadergraph/Editor/Generation/Enumerations/IncludeLocation.cs b/com.unity.shadergraph/Editor/Generation/Enumerations/IncludeLocation.cs index cedf81d1054..2d0b3af591f 100644 --- a/com.unity.shadergraph/Editor/Generation/Enumerations/IncludeLocation.cs +++ b/com.unity.shadergraph/Editor/Generation/Enumerations/IncludeLocation.cs @@ -1,6 +1,9 @@ +using System; + namespace UnityEditor.ShaderGraph { [GenerationAPI] + [Serializable] internal enum IncludeLocation { Pregraph, diff --git a/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs b/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs index 23dcedecf57..123ec72b9bc 100644 --- a/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs +++ b/com.unity.shadergraph/Editor/Generation/Processors/Generator.cs @@ -325,7 +325,8 @@ void ProcessStackForPass(ContextData contextData, BlockFieldDescriptor[] passBlo // Function Registry var functionBuilder = new ShaderStringBuilder(); - var functionRegistry = new FunctionRegistry(functionBuilder); + var graphIncludes = new IncludeCollection(); + var functionRegistry = new FunctionRegistry(functionBuilder, graphIncludes); // Hash table of named $splice(name) commands // Key: splice token @@ -413,36 +414,6 @@ void ProcessStackForPass(ContextData contextData, BlockFieldDescriptor[] passBlo spliceCommands.Add("PassPragmas", command); } - // Includes - using (var preGraphIncludeBuilder = new ShaderStringBuilder()) - { - if (pass.includes != null) - { - foreach (IncludeCollection.Item include in pass.includes.Where(x => x.descriptor.location == IncludeLocation.Pregraph)) - { - if (include.TestActive(activeFields)) - preGraphIncludeBuilder.AppendLine(include.value); - } - } - - string command = GenerationUtils.GetSpliceCommand(preGraphIncludeBuilder.ToCodeBlock(), "PreGraphIncludes"); - spliceCommands.Add("PreGraphIncludes", command); - } - using (var postGraphIncludeBuilder = new ShaderStringBuilder()) - { - if (pass.includes != null) - { - foreach (IncludeCollection.Item include in pass.includes.Where(x => x.descriptor.location == IncludeLocation.Postgraph)) - { - if (include.TestActive(activeFields)) - postGraphIncludeBuilder.AppendLine(include.value); - } - } - - string command = GenerationUtils.GetSpliceCommand(postGraphIncludeBuilder.ToCodeBlock(), "PostGraphIncludes"); - spliceCommands.Add("PostGraphIncludes", command); - } - // Keywords using (var passKeywordBuilder = new ShaderStringBuilder()) { @@ -778,6 +749,37 @@ void ProcessStackForPass(ContextData contextData, BlockFieldDescriptor[] passBlo spliceCommands.Add("GraphDefines", graphDefines.ToCodeBlock()); } + // -------------------------------------------------- + // Includes + + var allIncludes = new IncludeCollection(); + allIncludes.Add(pass.includes); + allIncludes.Add(graphIncludes); + + using (var preGraphIncludeBuilder = new ShaderStringBuilder()) + { + foreach (var include in allIncludes.Where(x => x.location == IncludeLocation.Pregraph)) + { + if (include.TestActive(activeFields)) + preGraphIncludeBuilder.AppendLine(include.value); + } + + string command = GenerationUtils.GetSpliceCommand(preGraphIncludeBuilder.ToCodeBlock(), "PreGraphIncludes"); + spliceCommands.Add("PreGraphIncludes", command); + } + + using (var postGraphIncludeBuilder = new ShaderStringBuilder()) + { + foreach (var include in allIncludes.Where(x => x.location == IncludeLocation.Postgraph)) + { + if (include.TestActive(activeFields)) + postGraphIncludeBuilder.AppendLine(include.value); + } + + string command = GenerationUtils.GetSpliceCommand(postGraphIncludeBuilder.ToCodeBlock(), "PostGraphIncludes"); + spliceCommands.Add("PostGraphIncludes", command); + } + // -------------------------------------------------- // Debug diff --git a/com.unity.shadergraph/Editor/Importers/ShaderGraphAssetPostProcessor.cs b/com.unity.shadergraph/Editor/Importers/ShaderGraphAssetPostProcessor.cs index 72597eda864..046582212c4 100644 --- a/com.unity.shadergraph/Editor/Importers/ShaderGraphAssetPostProcessor.cs +++ b/com.unity.shadergraph/Editor/Importers/ShaderGraphAssetPostProcessor.cs @@ -88,18 +88,18 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse } // moved or imported subgraphs or HLSL files should notify open shadergraphs that they need to handle them - var changedFiles = movedAssets.Concat(importedAssets).Concat(deletedAssets) + var changedFileGUIDs = movedAssets.Concat(importedAssets).Concat(deletedAssets) .Where(x => x.EndsWith(ShaderSubGraphImporter.Extension, StringComparison.InvariantCultureIgnoreCase) || CustomFunctionNode.s_ValidExtensions.Contains(Path.GetExtension(x))) .Select(AssetDatabase.AssetPathToGUID) .Distinct() .ToList(); - if (changedFiles.Count > 0) + if (changedFileGUIDs.Count > 0) { foreach (var window in windows) { - window.ReloadSubGraphsOnNextUpdate(changedFiles); + window.ReloadSubGraphsOnNextUpdate(changedFileGUIDs); } } } diff --git a/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs b/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs index 4ed0197f1b0..913bbccaf72 100644 --- a/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs +++ b/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs @@ -26,7 +26,7 @@ namespace UnityEditor.ShaderGraph // This ifdef can be removed once V2 is the only option. [ScriptedImporter(109, Extension, -902)] #else - [ScriptedImporter(41, Extension, -902)] + [ScriptedImporter(42, Extension, -902)] #endif class ShaderGraphImporter : ScriptedImporter @@ -378,7 +378,8 @@ static ShaderGraphVfxAsset GenerateVfxShaderGraphAsset(GraphData graph) } var bodySb = new ShaderStringBuilder(1); - var registry = new FunctionRegistry(new ShaderStringBuilder(), true); + var graphIncludes = new IncludeCollection(); + var registry = new FunctionRegistry(new ShaderStringBuilder(), graphIncludes, true); foreach (var properties in graph.properties) { @@ -453,6 +454,12 @@ static ShaderGraphVfxAsset GenerateVfxShaderGraphAsset(GraphData graph) sharedCodeIndices.Add(codeSnippets.Count); codeSnippets.Add($"#include \"Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl\"{nl}"); + foreach (var include in graphIncludes) + { + sharedCodeIndices.Add(codeSnippets.Count); + codeSnippets.Add(include.value + nl); + } + for (var registryIndex = 0; registryIndex < registry.names.Count; registryIndex++) { var name = registry.names[registryIndex]; diff --git a/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs b/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs index da96791362c..4447f23e72e 100644 --- a/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs +++ b/com.unity.shadergraph/Editor/Importers/ShaderSubGraphImporter.cs @@ -19,7 +19,7 @@ namespace UnityEditor.ShaderGraph { [ExcludeFromPreset] - [ScriptedImporter(20, Extension, -905)] + [ScriptedImporter(21, Extension, -905)] class ShaderSubGraphImporter : ScriptedImporter { public const string Extension = "shadersubgraph"; @@ -153,7 +153,8 @@ public override void OnImportAsset(AssetImportContext ctx) static void ProcessSubGraph(SubGraphAsset asset, GraphData graph) { - var registry = new FunctionRegistry(new ShaderStringBuilder(), true); + var graphIncludes = new IncludeCollection(); + var registry = new FunctionRegistry(new ShaderStringBuilder(), graphIncludes, true); registry.names.Clear(); asset.functions.Clear(); asset.isValid = true; @@ -193,6 +194,8 @@ static void ProcessSubGraph(SubGraphAsset asset, GraphData graph) asset.outputPrecision = outputNode.concretePrecision; asset.previewMode = graph.previewMode; + asset.includes = graphIncludes; + GatherDescendentsFromGraph(new GUID(asset.assetGuid), out var containsCircularDependency, out var descendents); asset.descendents.AddRange(descendents.Select(g => g.ToString())); asset.descendents.Sort(); // ensure deterministic order diff --git a/com.unity.shadergraph/Editor/Interface/IShaderString.cs b/com.unity.shadergraph/Editor/Interface/IShaderString.cs deleted file mode 100644 index 7b9f1c4df50..00000000000 --- a/com.unity.shadergraph/Editor/Interface/IShaderString.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace UnityEditor.ShaderGraph -{ - interface IShaderString - { - string value { get; } - } -}