@@ -24,11 +24,18 @@ internal enum VFXComponentType
2424 }
2525
2626 private static Dictionary < string , Material > s_DefaultVFXMaterials = new Dictionary < string , Material > ( ) ;
27+ private static Dictionary < string , Material > s_DefaultSceneMaterials = new Dictionary < string , Material > ( ) ;
2728
2829 private static readonly string [ ] BuiltInLitShaders = { "Standard" , "Legacy Shaders/Diffuse" } ;
2930 private static readonly string [ ] BuiltInUnlitShaders = { "Unlit/Color" , "Unlit/Texture" } ;
31+ private static readonly string [ ] BuiltInParticleShaders = { "Particles/Standard Unlit" , "Particles/Alpha Blended" , "Particles/Additive" } ;
3032 private static readonly string [ ] UrpLitShaders = { "Universal Render Pipeline/Lit" , "Universal Render Pipeline/Simple Lit" } ;
3133 private static readonly string [ ] UrpUnlitShaders = { "Universal Render Pipeline/Unlit" } ;
34+ private static readonly string [ ] UrpParticleShaders = {
35+ "Universal Render Pipeline/Particles/Unlit" ,
36+ "Universal Render Pipeline/Particles/Simple Lit" ,
37+ "Universal Render Pipeline/Particles/Lit" ,
38+ } ;
3239 private static readonly string [ ] HdrpLitShaders = { "HDRP/Lit" , "High Definition Render Pipeline/Lit" } ;
3340 private static readonly string [ ] HdrpUnlitShaders = { "HDRP/Unlit" , "High Definition Render Pipeline/Unlit" } ;
3441
@@ -170,8 +177,8 @@ private static void WarnIfPipelineMismatch(string shaderName, PipelineKind activ
170177 var lowerName = shaderName . ToLowerInvariant ( ) ;
171178 bool shaderLooksUrp = lowerName . Contains ( "universal render pipeline" ) || lowerName . Contains ( "urp/" ) ;
172179 bool shaderLooksHdrp = lowerName . Contains ( "high definition render pipeline" ) || lowerName . Contains ( "hdrp/" ) ;
173- bool shaderLooksBuiltin = lowerName . Contains ( "standard" ) || lowerName . Contains ( "legacy shaders/" ) ;
174180 bool shaderLooksSrp = shaderLooksUrp || shaderLooksHdrp ;
181+ bool shaderLooksBuiltin = LooksLikeBuiltInShader ( lowerName , shaderLooksSrp ) ;
175182
176183 switch ( activePipeline )
177184 {
@@ -262,8 +269,8 @@ private static bool IsPipelineMismatch(string shaderName, PipelineKind activePip
262269 string lowerName = shaderName . ToLowerInvariant ( ) ;
263270 bool shaderLooksUrp = lowerName . Contains ( "universal render pipeline" ) || lowerName . Contains ( "urp/" ) ;
264271 bool shaderLooksHdrp = lowerName . Contains ( "high definition render pipeline" ) || lowerName . Contains ( "hdrp/" ) ;
265- bool shaderLooksBuiltin = lowerName . Contains ( "standard" ) || lowerName . Contains ( "legacy shaders/" ) ;
266272 bool shaderLooksSrp = shaderLooksUrp || shaderLooksHdrp ;
273+ bool shaderLooksBuiltin = LooksLikeBuiltInShader ( lowerName , shaderLooksSrp ) ;
267274
268275 return activePipeline switch
269276 {
@@ -297,7 +304,7 @@ internal static Material GetOrCreateDefaultVFXMaterial(VFXComponentType componen
297304
298305 if ( material == null )
299306 {
300- Shader shader = ResolveDefaultUnlitShader ( pipeline ) ;
307+ Shader shader = ResolveDefaultVFXShader ( pipeline , componentType ) ;
301308 if ( shader == null )
302309 {
303310 shader = Shader . Find ( "Unlit/Color" ) ;
@@ -350,5 +357,89 @@ internal static Material GetOrCreateDefaultVFXMaterial(VFXComponentType componen
350357
351358 return material ;
352359 }
360+
361+ private static Shader ResolveDefaultVFXShader ( PipelineKind pipeline , VFXComponentType componentType )
362+ {
363+ if ( componentType == VFXComponentType . ParticleSystem )
364+ {
365+ return pipeline switch
366+ {
367+ PipelineKind . Universal => TryFindShader ( UrpParticleShaders ) ?? ResolveDefaultUnlitShader ( pipeline ) ,
368+ PipelineKind . HighDefinition => TryFindShader ( HdrpUnlitShaders ) ?? ResolveDefaultUnlitShader ( pipeline ) ,
369+ PipelineKind . BuiltIn => TryFindShader ( BuiltInParticleShaders ) ?? ResolveDefaultUnlitShader ( pipeline ) ,
370+ PipelineKind . Custom => TryFindShader ( UrpParticleShaders )
371+ ?? TryFindShader ( BuiltInParticleShaders )
372+ ?? TryFindShader ( HdrpUnlitShaders )
373+ ?? ResolveDefaultUnlitShader ( pipeline ) ,
374+ _ => ResolveDefaultUnlitShader ( pipeline ) ,
375+ } ;
376+ }
377+
378+ return ResolveDefaultUnlitShader ( pipeline ) ;
379+ }
380+
381+ private static bool LooksLikeBuiltInShader ( string lowerName , bool shaderLooksSrp )
382+ {
383+ if ( string . IsNullOrEmpty ( lowerName ) )
384+ {
385+ return false ;
386+ }
387+
388+ if ( lowerName == "standard" ||
389+ lowerName . StartsWith ( "legacy shaders/" , StringComparison . Ordinal ) ||
390+ lowerName . StartsWith ( "mobile/" , StringComparison . Ordinal ) )
391+ {
392+ return true ;
393+ }
394+
395+ // Built-in non-SRP shader families commonly seen on particles/old content.
396+ if ( ! shaderLooksSrp &&
397+ ( lowerName . StartsWith ( "particles/" , StringComparison . Ordinal ) ||
398+ lowerName . StartsWith ( "unlit/" , StringComparison . Ordinal ) ) )
399+ {
400+ return true ;
401+ }
402+
403+ return false ;
404+ }
405+
406+ internal static Material GetOrCreateDefaultSceneMaterial ( )
407+ {
408+ var pipeline = GetActivePipeline ( ) ;
409+ string cacheKey = $ "{ pipeline } _scene";
410+ if ( s_DefaultSceneMaterials . TryGetValue ( cacheKey , out Material cached ) && cached != null )
411+ {
412+ return cached ;
413+ }
414+
415+ Material material = null ;
416+ Shader shader = ResolveDefaultLitShader ( pipeline ) ?? ResolveDefaultUnlitShader ( pipeline ) ;
417+ if ( shader == null )
418+ {
419+ shader = Shader . Find ( "Unlit/Color" ) ;
420+ }
421+
422+ if ( shader != null )
423+ {
424+ material = new Material ( shader ) ;
425+ material . name = $ "Auto_Default_Scene_{ pipeline } ";
426+ if ( material . HasProperty ( "_Color" ) )
427+ {
428+ material . SetColor ( "_Color" , Color . white ) ;
429+ }
430+ if ( material . HasProperty ( "_BaseColor" ) )
431+ {
432+ material . SetColor ( "_BaseColor" , Color . white ) ;
433+ }
434+ McpLog . Info ( $ "[RenderPipelineUtility] Created default scene material using { shader . name } ") ;
435+ }
436+
437+ if ( material != null )
438+ {
439+ s_DefaultSceneMaterials [ cacheKey ] = material ;
440+ }
441+
442+ return material ;
443+ }
353444 }
354445}
0 commit comments