diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs index bd047060442..42d1d8029a5 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXAbstractParticleHDRPLitOutput.cs @@ -94,7 +94,7 @@ public enum BaseColorMapMode protected VFXAbstractParticleHDRPLitOutput(bool strip = false) : base(strip) { } - protected virtual bool allowTextures { get { return shaderGraph == null; }} + protected virtual bool allowTextures { get { return GetOrRefreshShaderGraphObject() == null; }} public class HDRPLitInputProperties { @@ -160,7 +160,7 @@ public class EmissiveColorProperties public Color emissiveColor = Color.black; } - protected override bool needsExposureWeight { get { return shaderGraph == null && ((colorMode & ColorMode.Emissive) != 0 || useEmissive || useEmissiveMap); } } + protected override bool needsExposureWeight { get { return GetOrRefreshShaderGraphObject() == null && ((colorMode & ColorMode.Emissive) != 0 || useEmissive || useEmissiveMap); } } protected override bool bypassExposure { get { return false; } } @@ -176,7 +176,7 @@ protected override IEnumerable inputProperties { var properties = base.inputProperties; - if (shaderGraph == null) + if (GetOrRefreshShaderGraphObject() == null) { properties = properties.Concat(PropertiesFromType("HDRPLitInputProperties")); properties = properties.Concat(PropertiesFromType(kMaterialTypeToName[(int)materialType])); @@ -213,7 +213,7 @@ protected override IEnumerable CollectGPUExpressions(IEnumer foreach (var exp in base.CollectGPUExpressions(slotExpressions)) yield return exp; - if( shaderGraph == null) + if(GetOrRefreshShaderGraphObject() == null) { yield return slotExpressions.First(o => o.name == "smoothness"); @@ -275,7 +275,7 @@ public override IEnumerable additionalDefines yield return "HDRP_LIT"; - if (shaderGraph == null) + if (GetOrRefreshShaderGraphObject() == null) switch (materialType) { case MaterialType.Standard: @@ -337,7 +337,7 @@ public override IEnumerable additionalDefines yield return "HDRP_USE_EMISSIVE_MAP"; } - if (shaderGraph == null) + if (GetOrRefreshShaderGraphObject() == null) { if ((colorMode & ColorMode.BaseColor) != 0) yield return "HDRP_USE_BASE_COLOR"; @@ -356,7 +356,7 @@ public override IEnumerable additionalDefines if (onlyAmbientLighting && !isBlendModeOpaque) yield return "USE_ONLY_AMBIENT_LIGHTING"; - if (isBlendModeOpaque && (shaderGraph != null || (materialType != MaterialType.SimpleLit && materialType != MaterialType.SimpleLitTranslucent))) + if (isBlendModeOpaque && (GetOrRefreshShaderGraphObject() != null || (materialType != MaterialType.SimpleLit && materialType != MaterialType.SimpleLitTranslucent))) yield return "IS_OPAQUE_NOT_SIMPLE_LIT_PARTICLE"; } } @@ -394,7 +394,7 @@ protected override IEnumerable filteredOutSettings yield return "alphaMask"; } - if (shaderGraph != null) + if (GetOrRefreshShaderGraphObject() != null) { yield return "materialType"; yield return "useEmissive"; @@ -448,7 +448,7 @@ public override IEnumerable> additionalRep yield return new KeyValuePair("${VFXHDRPForwardDefines}", forwardDefines); var forwardPassName = new VFXShaderWriter(); - forwardPassName.Write(shaderGraph == null && (materialType == MaterialType.SimpleLit || materialType == MaterialType.SimpleLitTranslucent) ? "ForwardOnly" : "Forward"); + forwardPassName.Write(GetOrRefreshShaderGraphObject() == null && (materialType == MaterialType.SimpleLit || materialType == MaterialType.SimpleLitTranslucent) ? "ForwardOnly" : "Forward"); yield return new KeyValuePair("${VFXHDRPForwardPassName}", forwardPassName); } } diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXLitMeshOutput.cs b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXLitMeshOutput.cs index 22c5899a4f4..38f0c1fa92d 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXLitMeshOutput.cs +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXLitMeshOutput.cs @@ -11,7 +11,7 @@ class VFXLitMeshOutput : VFXAbstractParticleHDRPLitOutput public override string name { get { return "Output Particle Lit Mesh"; } } public override string codeGeneratorTemplate { get { return RenderPipeTemplate("VFXParticleLitMesh"); } } public override VFXTaskType taskType { get { return VFXTaskType.ParticleMeshOutput; } } - public override bool supportsUV { get { return shaderGraph == null; } } + public override bool supportsUV { get { return GetOrRefreshShaderGraphObject() == null; } } public override bool implementsMotionVector { get { return true; } } public override CullMode defaultCullMode { get { return CullMode.Back; } } diff --git a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXLitPlanarPrimitiveOutput.cs b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXLitPlanarPrimitiveOutput.cs index c6243c66bc9..68df6f2e837 100644 --- a/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXLitPlanarPrimitiveOutput.cs +++ b/com.unity.render-pipelines.high-definition/Editor/VFXGraph/Outputs/VFXLitPlanarPrimitiveOutput.cs @@ -11,7 +11,7 @@ class VFXLitPlanarPrimitiveOutput : VFXAbstractParticleHDRPLitOutput public override string name { get { return "Output Particle Lit " + primitiveType.ToString(); } } public override string codeGeneratorTemplate { get { return RenderPipeTemplate("VFXParticleLitPlanarPrimitive"); } } public override VFXTaskType taskType { get { return VFXPlanarPrimitiveHelper.GetTaskType(primitiveType); } } - public override bool supportsUV { get { return shaderGraph == null; } } + public override bool supportsUV { get { return GetOrRefreshShaderGraphObject() == null; } } public sealed override bool implementsMotionVector { get { return true; } } [VFXSetting(VFXSettingAttribute.VisibleFlags.InInspector), SerializeField, Tooltip("Specifies what primitive type to use for this output. Triangle outputs have fewer vertices, octagons can be used to conform the geometry closer to the texture to avoid overdraw, and quads are a good middle ground.")] diff --git a/com.unity.visualeffectgraph/CHANGELOG.md b/com.unity.visualeffectgraph/CHANGELOG.md index d8957a6d6b1..282519d237a 100644 --- a/com.unity.visualeffectgraph/CHANGELOG.md +++ b/com.unity.visualeffectgraph/CHANGELOG.md @@ -5,9 +5,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). ## [7.5.3] - 2021-01-11 - +### Fixed +- Unexpected shaderGraph reference lost while upgrading package [Case 1297186](https://issuetracker.unity3d.com/product/unity/issues/guid/1297186/) Version Updated -The version number for this package has increased due to a version update of a related graphics package. ## [7.5.2] - 2020-11-16 ### Fixed diff --git a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXMeshOutput.cs b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXMeshOutput.cs index d36001578ab..7d480630b8e 100644 --- a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXMeshOutput.cs +++ b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXMeshOutput.cs @@ -12,7 +12,7 @@ class VFXMeshOutput : VFXShaderGraphParticleOutput public override string name { get { return "Output Particle Mesh"; } } public override string codeGeneratorTemplate { get { return RenderPipeTemplate("VFXParticleMeshes"); } } public override VFXTaskType taskType { get { return VFXTaskType.ParticleMeshOutput; } } - public override bool supportsUV { get { return shaderGraph == null; } } + public override bool supportsUV { get { return GetOrRefreshShaderGraphObject() == null; } } public override bool implementsMotionVector { get { return true; } } public override CullMode defaultCullMode { get { return CullMode.Back; } } @@ -48,7 +48,7 @@ protected override IEnumerable CollectGPUExpressions(IEnumer { foreach (var exp in base.CollectGPUExpressions(slotExpressions)) yield return exp; - if (shaderGraph == null) + if (GetOrRefreshShaderGraphObject() == null) yield return slotExpressions.First(o => o.name == "mainTexture"); } @@ -56,7 +56,7 @@ protected override IEnumerable inputProperties { get { - if (shaderGraph == null) + if (GetOrRefreshShaderGraphObject() == null) foreach (var property in PropertiesFromType("OptionalInputProperties")) yield return property; foreach (var property in base.inputProperties) diff --git a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXPlanarPrimitiveOutput.cs b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXPlanarPrimitiveOutput.cs index 9fd06212b47..5f24cec06ae 100644 --- a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXPlanarPrimitiveOutput.cs +++ b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXPlanarPrimitiveOutput.cs @@ -30,7 +30,7 @@ public override VFXTaskType taskType return VFXPlanarPrimitiveHelper.GetTaskType(primitiveType); } } - public override bool supportsUV { get { return shaderGraph == null; } } + public override bool supportsUV { get { return GetOrRefreshShaderGraphObject() == null; } } public override bool implementsMotionVector { get { return true; } } public override IEnumerable additionalDefines @@ -85,7 +85,7 @@ protected override IEnumerable inputProperties get { IEnumerable properties = base.inputProperties; - if (shaderGraph == null) + if (GetOrRefreshShaderGraphObject() == null) properties = properties.Concat(PropertiesFromType("OptionalInputProperties")); if (primitiveType == VFXPrimitiveType.Octagon) @@ -98,7 +98,7 @@ protected override IEnumerable CollectGPUExpressions(IEnumer { foreach (var exp in base.CollectGPUExpressions(slotExpressions)) yield return exp; - if (shaderGraph == null) + if (GetOrRefreshShaderGraphObject() == null) { yield return slotExpressions.First(o => o.name == "mainTexture"); } diff --git a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXQuadStripOutput.cs b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXQuadStripOutput.cs index 845bd754305..5b716ea8d53 100644 --- a/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXQuadStripOutput.cs +++ b/com.unity.visualeffectgraph/Editor/Models/Contexts/Implementations/VFXQuadStripOutput.cs @@ -41,7 +41,7 @@ protected override IEnumerable inputProperties get { IEnumerable properties = base.inputProperties; - if (shaderGraph == null) + if (GetOrRefreshShaderGraphObject() == null) properties = properties.Concat(PropertiesFromType("OptionalInputProperties")); if (tilingMode == StripTilingMode.Custom) properties = properties.Concat(PropertiesFromType("CustomUVInputProperties")); @@ -54,7 +54,7 @@ protected override IEnumerable CollectGPUExpressions(IEnumer foreach (var exp in base.CollectGPUExpressions(slotExpressions)) yield return exp; - if (shaderGraph == null) + if (GetOrRefreshShaderGraphObject() == null) yield return slotExpressions.First(o => o.name == "mainTexture"); if (tilingMode == StripTilingMode.Custom) yield return slotExpressions.First(o => o.name == "texCoord"); diff --git a/com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs b/com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs index 805a004270b..32b65e543f7 100644 --- a/com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs +++ b/com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs @@ -681,30 +681,15 @@ private void CheckShaderReferences() { Profiler.BeginSample("VFXGraph.CheckShaderReferences"); // Try to reimport all shadergraph at compilation if they are missing - - //For shadergraph outputs - VFXShaderGraphPostProcessor.disableImportDependentVFX = true; try { + //For shader graph outputs : TODO; not needed anymore but keep the same pattern of importing. foreach (var output in children.OfType()) { - if (!object.ReferenceEquals(output.shaderGraph, null) && output.shaderGraph == null) - { - int instanceID = output.shaderGraph.GetInstanceID(); - - string shaderAssetPath = AssetDatabase.GetAssetPath(instanceID); - if (!string.IsNullOrEmpty(shaderAssetPath)) - { - Debug.Log("forcing ShaderGraph to reimport : " + shaderAssetPath); - AssetDatabase.ImportAsset(shaderAssetPath); - - var realAsset = AssetDatabase.LoadAssetAtPath(shaderAssetPath); - if (realAsset != null) - output.shaderGraph = realAsset; - } - } + output.GetOrRefreshShaderGraphObject(); } + //For static meshes foreach (var output in children.OfType()) { diff --git a/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs b/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs index d7ee21cedab..9ae50e19fb4 100644 --- a/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs +++ b/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs @@ -13,29 +13,46 @@ namespace UnityEditor.VFX { class VFXShaderGraphParticleOutput : VFXAbstractParticleOutput, ISerializationCallbackReceiver { + //"protected" is only to be listed by VFXModel.GetSettings, we should always use GetOrRefreshShaderGraphObject [SerializeField, VFXSetting] - public ShaderGraphVfxAsset shaderGraph; + protected ShaderGraphVfxAsset shaderGraph; [SerializeField] - private string shadergraphGUID; + string shadergraphGUID; public void OnBeforeSerialize() { + var shaderGraph = GetOrRefreshShaderGraphObject(); if (shaderGraph != null) shadergraphGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(shaderGraph)); else shadergraphGUID = null; } - public void OnAfterDeserialize() + public ShaderGraphVfxAsset GetOrRefreshShaderGraphObject() { + //This is the only place where shaderGraph property is updated or read + if (shaderGraph == null) + { + if (!object.ReferenceEquals(shaderGraph, null)) //Invalid reference object, force reimport. + { + string assetPath = AssetDatabase.GetAssetPath(shaderGraph.GetInstanceID()); + var newShaderGraph = AssetDatabase.LoadAssetAtPath(assetPath); + if (newShaderGraph != null) + { + shaderGraph = newShaderGraph; + } + } + else if(!string.IsNullOrEmpty(shadergraphGUID)) //shaderGraph really null, load from save guid. + { + shaderGraph = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(shadergraphGUID)); + } + } + return shaderGraph; } - public override void OnEnable() + public void OnAfterDeserialize() { - base.OnEnable(); - if (!string.IsNullOrEmpty(shadergraphGUID)) - shaderGraph = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(shadergraphGUID)); } protected VFXShaderGraphParticleOutput(bool strip = false) : base(strip) {} @@ -104,7 +121,7 @@ protected override IEnumerable filteredOutSettings { foreach (var setting in base.filteredOutSettings) yield return setting; - if (shaderGraph != null) + if (GetOrRefreshShaderGraphObject() != null) { yield return "colorMapping"; yield return "useAlphaClipping"; @@ -114,11 +131,12 @@ protected override IEnumerable filteredOutSettings } } - public override bool supportsUV => base.supportsUV && shaderGraph == null; + public override bool supportsUV => base.supportsUV && GetOrRefreshShaderGraphObject() == null; public override bool exposeAlphaThreshold { get { + var shaderGraph = GetOrRefreshShaderGraphObject(); if (shaderGraph == null) { if (base.exposeAlphaThreshold) @@ -136,11 +154,12 @@ public override bool exposeAlphaThreshold return false; } } - public override bool supportSoftParticles => base.supportSoftParticles && shaderGraph == null; + public override bool supportSoftParticles => base.supportSoftParticles && GetOrRefreshShaderGraphObject() == null; public override bool hasAlphaClipping { get { + var shaderGraph = GetOrRefreshShaderGraphObject(); bool noShaderGraphAlphaThreshold = shaderGraph == null && useAlphaClipping; bool ShaderGraphAlphaThreshold = shaderGraph != null && shaderGraph.alphaClipping; return noShaderGraphAlphaThreshold || ShaderGraphAlphaThreshold; @@ -153,7 +172,7 @@ protected override IEnumerable inputProperties { IEnumerable properties = base.inputProperties; - + var shaderGraph = GetOrRefreshShaderGraphObject(); if (shaderGraph != null) { var shaderGraphProperties = new List(); @@ -238,6 +257,7 @@ protected override IEnumerable CollectGPUExpressions(IEnumer foreach (var exp in base.CollectGPUExpressions(slotExpressions)) yield return exp; + var shaderGraph = GetOrRefreshShaderGraphObject(); if (shaderGraph != null) { foreach (var sgProperty in shaderGraph.properties) @@ -254,6 +274,7 @@ public override IEnumerable additionalDefines foreach (var def in base.additionalDefines) yield return def; + var shaderGraph = GetOrRefreshShaderGraphObject(); if (shaderGraph != null) { yield return "VFX_SHADERGRAPH"; @@ -315,7 +336,7 @@ public override VFXExpressionMapper GetExpressionMapper(VFXDeviceTarget target) case VFXDeviceTarget.CPU: break; case VFXDeviceTarget.GPU: - + var shaderGraph = GetOrRefreshShaderGraphObject(); if (shaderGraph != null) { foreach (var tex in shaderGraph.textureInfos.Where(t => t.texture != null).OrderBy(t => t.name)) @@ -364,6 +385,7 @@ public override IEnumerable fragmentParameters { get { + var shaderGraph = GetOrRefreshShaderGraphObject(); if (shaderGraph != null) foreach (var param in shaderGraph.properties) if (!IsTexture(param.propertyType)) // Remove exposed textures from list of interpolants @@ -378,6 +400,8 @@ public override IEnumerable fragmentParameters public override bool SetupCompilation() { if (!base.SetupCompilation()) return false; + + var shaderGraph = GetOrRefreshShaderGraphObject(); if (shaderGraph != null) { if (!isLitShader && shaderGraph.lit) @@ -410,6 +434,7 @@ public override IEnumerable> additionalRep foreach (var rep in base.additionalReplacements) yield return rep; + var shaderGraph = GetOrRefreshShaderGraphObject(); if (shaderGraph != null) { RPInfo info = currentRP; diff --git a/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphPostProcessor.cs b/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphPostProcessor.cs index 5274d9e9eb0..c2890518be3 100644 --- a/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphPostProcessor.cs +++ b/com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphPostProcessor.cs @@ -64,7 +64,7 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse if (graph != null) { - if (graph.children.OfType().Any(t => modifiedShaderGraphs.Contains(t.shaderGraph))) + if (graph.children.OfType().Any(t => modifiedShaderGraphs.Contains(t.GetOrRefreshShaderGraphObject()))) assetsToReimport.Add(graph); } } @@ -72,13 +72,9 @@ static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAsse foreach (var graph in assetsToReimport) { - foreach (var sgOutput in graph.children.OfType().Where(t => modifiedShaderGraphs.Contains(t.shaderGraph))) + foreach (var sgOutput in graph.children.OfType()) { - int instanceID = sgOutput.shaderGraph.GetInstanceID(); - - // This is needed because the imported invalidate the object - sgOutput.shaderGraph = EditorUtility.InstanceIDToObject(instanceID) as ShaderGraphVfxAsset; - + sgOutput.GetOrRefreshShaderGraphObject(); sgOutput.ResyncSlots(true); }