Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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; } }

Expand All @@ -176,7 +176,7 @@ protected override IEnumerable<VFXPropertyWithValue> inputProperties
{
var properties = base.inputProperties;

if (shaderGraph == null)
if (GetOrRefreshShaderGraphObject() == null)
{
properties = properties.Concat(PropertiesFromType("HDRPLitInputProperties"));
properties = properties.Concat(PropertiesFromType(kMaterialTypeToName[(int)materialType]));
Expand Down Expand Up @@ -213,7 +213,7 @@ protected override IEnumerable<VFXNamedExpression> 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");

Expand Down Expand Up @@ -275,7 +275,7 @@ public override IEnumerable<string> additionalDefines

yield return "HDRP_LIT";

if (shaderGraph == null)
if (GetOrRefreshShaderGraphObject() == null)
switch (materialType)
{
case MaterialType.Standard:
Expand Down Expand Up @@ -337,7 +337,7 @@ public override IEnumerable<string> additionalDefines
yield return "HDRP_USE_EMISSIVE_MAP";
}

if (shaderGraph == null)
if (GetOrRefreshShaderGraphObject() == null)
{
if ((colorMode & ColorMode.BaseColor) != 0)
yield return "HDRP_USE_BASE_COLOR";
Expand All @@ -356,7 +356,7 @@ public override IEnumerable<string> 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";
}
}
Expand Down Expand Up @@ -394,7 +394,7 @@ protected override IEnumerable<string> filteredOutSettings
yield return "alphaMask";
}

if (shaderGraph != null)
if (GetOrRefreshShaderGraphObject() != null)
{
yield return "materialType";
yield return "useEmissive";
Expand Down Expand Up @@ -448,7 +448,7 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep

yield return new KeyValuePair<string, VFXShaderWriter>("${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<string, VFXShaderWriter>("${VFXHDRPForwardPassName}", forwardPassName);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
Expand Down
4 changes: 2 additions & 2 deletions com.unity.visualeffectgraph/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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; } }

Expand Down Expand Up @@ -48,15 +48,15 @@ protected override IEnumerable<VFXNamedExpression> 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");
}

protected override IEnumerable<VFXPropertyWithValue> inputProperties
{
get
{
if (shaderGraph == null)
if (GetOrRefreshShaderGraphObject() == null)
foreach (var property in PropertiesFromType("OptionalInputProperties"))
yield return property;
foreach (var property in base.inputProperties)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> additionalDefines
Expand Down Expand Up @@ -85,7 +85,7 @@ protected override IEnumerable<VFXPropertyWithValue> inputProperties
get
{
IEnumerable<VFXPropertyWithValue> properties = base.inputProperties;
if (shaderGraph == null)
if (GetOrRefreshShaderGraphObject() == null)
properties = properties.Concat(PropertiesFromType("OptionalInputProperties"));

if (primitiveType == VFXPrimitiveType.Octagon)
Expand All @@ -98,7 +98,7 @@ protected override IEnumerable<VFXNamedExpression> 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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected override IEnumerable<VFXPropertyWithValue> inputProperties
get
{
IEnumerable<VFXPropertyWithValue> properties = base.inputProperties;
if (shaderGraph == null)
if (GetOrRefreshShaderGraphObject() == null)
properties = properties.Concat(PropertiesFromType("OptionalInputProperties"));
if (tilingMode == StripTilingMode.Custom)
properties = properties.Concat(PropertiesFromType("CustomUVInputProperties"));
Expand All @@ -54,7 +54,7 @@ protected override IEnumerable<VFXNamedExpression> 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");
Expand Down
21 changes: 3 additions & 18 deletions com.unity.visualeffectgraph/Editor/Models/VFXGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<VFXShaderGraphParticleOutput>())
{
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<ShaderGraphVfxAsset>(shaderAssetPath);
if (realAsset != null)
output.shaderGraph = realAsset;
}
}
output.GetOrRefreshShaderGraphObject();
}

//For static meshes
foreach (var output in children.OfType<VFXStaticMeshOutput>())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShaderGraphVfxAsset>(assetPath);
if (newShaderGraph != null)
{
shaderGraph = newShaderGraph;
}
}
else if(!string.IsNullOrEmpty(shadergraphGUID)) //shaderGraph really null, load from save guid.
{
shaderGraph = AssetDatabase.LoadAssetAtPath<ShaderGraphVfxAsset>(AssetDatabase.GUIDToAssetPath(shadergraphGUID));
}
}
return shaderGraph;
}

public override void OnEnable()
public void OnAfterDeserialize()
{
base.OnEnable();
if (!string.IsNullOrEmpty(shadergraphGUID))
shaderGraph = AssetDatabase.LoadAssetAtPath<ShaderGraphVfxAsset>(AssetDatabase.GUIDToAssetPath(shadergraphGUID));
}

protected VFXShaderGraphParticleOutput(bool strip = false) : base(strip) {}
Expand Down Expand Up @@ -104,7 +121,7 @@ protected override IEnumerable<string> filteredOutSettings
{
foreach (var setting in base.filteredOutSettings)
yield return setting;
if (shaderGraph != null)
if (GetOrRefreshShaderGraphObject() != null)
{
yield return "colorMapping";
yield return "useAlphaClipping";
Expand All @@ -114,11 +131,12 @@ protected override IEnumerable<string> 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)
Expand All @@ -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;
Expand All @@ -153,7 +172,7 @@ protected override IEnumerable<VFXPropertyWithValue> inputProperties
{
IEnumerable<VFXPropertyWithValue> properties = base.inputProperties;


var shaderGraph = GetOrRefreshShaderGraphObject();
if (shaderGraph != null)
{
var shaderGraphProperties = new List<VFXPropertyWithValue>();
Expand Down Expand Up @@ -238,6 +257,7 @@ protected override IEnumerable<VFXNamedExpression> CollectGPUExpressions(IEnumer
foreach (var exp in base.CollectGPUExpressions(slotExpressions))
yield return exp;

var shaderGraph = GetOrRefreshShaderGraphObject();
if (shaderGraph != null)
{
foreach (var sgProperty in shaderGraph.properties)
Expand All @@ -254,6 +274,7 @@ public override IEnumerable<string> additionalDefines
foreach (var def in base.additionalDefines)
yield return def;

var shaderGraph = GetOrRefreshShaderGraphObject();
if (shaderGraph != null)
{
yield return "VFX_SHADERGRAPH";
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -364,6 +385,7 @@ public override IEnumerable<string> 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
Expand All @@ -378,6 +400,8 @@ public override IEnumerable<string> fragmentParameters
public override bool SetupCompilation()
{
if (!base.SetupCompilation()) return false;

var shaderGraph = GetOrRefreshShaderGraphObject();
if (shaderGraph != null)
{
if (!isLitShader && shaderGraph.lit)
Expand Down Expand Up @@ -410,6 +434,7 @@ public override IEnumerable<KeyValuePair<string, VFXShaderWriter>> additionalRep
foreach (var rep in base.additionalReplacements)
yield return rep;

var shaderGraph = GetOrRefreshShaderGraphObject();
if (shaderGraph != null)
{
RPInfo info = currentRP;
Expand Down
Loading