Skip to content

Commit 60ff3cb

Browse files
committed
Fix sorting for new SG VFX contexts
1 parent 8699729 commit 60ff3cb

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

com.unity.visualeffectgraph/Editor/Models/Contexts/IVFXSubRenderer.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public static VFXMaterialSerializedSettings CreateFromMaterial(Material material
2727
return settings;
2828
}
2929

30+
public bool NeedsSync() => m_PropertyMap.Count == 0;
31+
3032
public void SyncFromMaterial(Material material)
3133
{
3234
m_PropertyMap.Clear();

com.unity.visualeffectgraph/Editor/ShaderGraph/VFXShaderGraphParticleOutput.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,16 @@ public override void SetupMaterial(Material material)
180180

181181
if (shaderGraph != null && shaderGraph.generatesWithShaderGraph)
182182
{
183+
// In certain scenarios the context might not be configured with any serialized material information
184+
// when assigned a shader graph for the first time. In this case we sync the settings to the incoming material,
185+
// which will be pre-configured by shader graph with the render state & other properties (i.e. a SG with Transparent surface).
186+
if (materialSettings.NeedsSync())
187+
{
188+
materialSettings.SyncFromMaterial(material);
189+
Invalidate(InvalidationCause.kSettingChanged);
190+
return;
191+
}
192+
183193
materialSettings.ApplyToMaterial(material);
184194
VFXLibrary.currentSRPBinder.SetupMaterial(material, hasMotionVector, hasShadowCasting, shaderGraph);
185195

@@ -266,6 +276,7 @@ public static object GetSGPropertyValue(AbstractShaderProperty property)
266276
public override bool HasSorting()
267277
{
268278
var materialBlendMode = GetMaterialBlendMode();
279+
269280
return base.HasSorting() || (sort == SortMode.Auto && (materialBlendMode == BlendMode.Alpha || materialBlendMode == BlendMode.AlphaPremultiplied));
270281
}
271282

0 commit comments

Comments
 (0)