@@ -238,7 +238,7 @@ void OnEnable()
238238 }
239239
240240 Matrix4x4 sizeOffset = Matrix4x4 . Translate ( decalOffset ) * Matrix4x4 . Scale ( decalSize ) ;
241- m_Handle = DecalSystem . instance . AddDecal ( position , rotation , Vector3 . one , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Material , gameObject . layer , HDUtils . GetSceneCullingMaskFromGameObject ( gameObject ) , m_FadeFactor ) ;
241+ m_Handle = DecalSystem . instance . AddDecal ( position , rotation , Vector3 . one , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Material , gameObject . layer , gameObject . sceneCullingMask , m_FadeFactor ) ;
242242 m_OldMaterial = m_Material ;
243243
244244#if UNITY_EDITOR
@@ -260,7 +260,13 @@ void UpdateDecalVisibility()
260260 else if ( m_Handle == null )
261261 {
262262 Matrix4x4 sizeOffset = Matrix4x4 . Translate ( decalOffset ) * Matrix4x4 . Scale ( decalSize ) ;
263- m_Handle = DecalSystem . instance . AddDecal ( position , rotation , Vector3 . one , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Material , gameObject . layer , HDUtils . GetSceneCullingMaskFromGameObject ( gameObject ) , m_FadeFactor ) ;
263+ m_Handle = DecalSystem . instance . AddDecal ( position , rotation , Vector3 . one , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Material , gameObject . layer , gameObject . sceneCullingMask , m_FadeFactor ) ;
264+ }
265+ else
266+ {
267+ // Scene culling mask may have changed.
268+ Matrix4x4 sizeOffset = Matrix4x4 . Translate ( decalOffset ) * Matrix4x4 . Scale ( decalSize ) ;
269+ DecalSystem . instance . UpdateCachedData ( position , rotation , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Handle , gameObject . layer , gameObject . sceneCullingMask , m_FadeFactor ) ;
264270 }
265271 }
266272#endif
@@ -299,7 +305,7 @@ internal void OnValidate()
299305
300306 if ( m_Material != null )
301307 {
302- m_Handle = DecalSystem . instance . AddDecal ( position , rotation , Vector3 . one , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Material , gameObject . layer , HDUtils . GetSceneCullingMaskFromGameObject ( gameObject ) , m_FadeFactor ) ;
308+ m_Handle = DecalSystem . instance . AddDecal ( position , rotation , Vector3 . one , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Material , gameObject . layer , gameObject . sceneCullingMask , m_FadeFactor ) ;
303309
304310 if ( ! DecalSystem . IsHDRenderPipelineDecal ( m_Material . shader ) ) // non HDRP/decal shaders such as shader graph decal do not affect transparency
305311 {
@@ -317,7 +323,7 @@ internal void OnValidate()
317323 }
318324 else // no material change, just update whatever else changed
319325 {
320- DecalSystem . instance . UpdateCachedData ( position , rotation , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Handle , gameObject . layer , HDUtils . GetSceneCullingMaskFromGameObject ( gameObject ) , m_FadeFactor ) ;
326+ DecalSystem . instance . UpdateCachedData ( position , rotation , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Handle , gameObject . layer , gameObject . sceneCullingMask , m_FadeFactor ) ;
321327 }
322328 }
323329 }
@@ -329,7 +335,7 @@ void Update() // only run in editor
329335 {
330336 Matrix4x4 sizeOffset = Matrix4x4 . Translate ( decalOffset ) * Matrix4x4 . Scale ( decalSize ) ;
331337 m_Layer = gameObject . layer ;
332- DecalSystem . instance . UpdateCachedData ( position , rotation , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Handle , gameObject . layer , HDUtils . GetSceneCullingMaskFromGameObject ( gameObject ) , m_FadeFactor ) ;
338+ DecalSystem . instance . UpdateCachedData ( position , rotation , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Handle , gameObject . layer , gameObject . sceneCullingMask , m_FadeFactor ) ;
333339 }
334340 }
335341#endif
@@ -341,7 +347,7 @@ void LateUpdate()
341347 if ( transform . hasChanged == true )
342348 {
343349 Matrix4x4 sizeOffset = Matrix4x4 . Translate ( decalOffset ) * Matrix4x4 . Scale ( decalSize ) ;
344- DecalSystem . instance . UpdateCachedData ( position , rotation , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Handle , gameObject . layer , HDUtils . GetSceneCullingMaskFromGameObject ( gameObject ) , m_FadeFactor ) ;
350+ DecalSystem . instance . UpdateCachedData ( position , rotation , sizeOffset , m_DrawDistance , m_FadeScale , uvScaleBias , m_AffectsTransparency , m_Handle , gameObject . layer , gameObject . sceneCullingMask , m_FadeFactor ) ;
345351 transform . hasChanged = false ;
346352 }
347353 }
0 commit comments