Editor/Core/UnityKnownShaders.cs

Editor helper that lists Unity built-in, URP and HDRP shader identities and known texture property names. It maps shader GUIDs and built-in FileIds to a lightweight Shader record with workflow and flags, and exposes sets of texture property names grouped by pipeline.

Reflection
using System;
using System.Collections.Generic;

namespace ImportUnityPackage;

/// <summary>
/// Unity shaders that never ship inside packages (built-in, URP and HDRP), so materials using them cannot be checked
/// against shader source. Identities come from shader references and property layouts observed in real packages.
/// </summary>
internal static class UnityKnownShaders
{
	internal const string BuiltinGuid = "0000000000000000f000000000000000";
	internal enum Workflow { Metallic, Specular, Other }
	/// <summary>
	/// KeywordDriven: material keywords decide which features are active (Standard and URP Lit).
	/// AlphaTest/Backfaces: fixed render state of shaders that are always cut out or double-sided. Unlit: ignores scene
	/// lighting. LegacyParticle: Unity's built-in particle shaders, always blended and tinted by twice <c>_TintColor</c>.
	/// </summary>
	internal sealed record Shader( string Name, Workflow Workflow, bool KeywordDriven, bool Universal, bool AlphaTest = false, bool Backfaces = false,
		bool Unlit = false, bool LegacyParticle = false );

	static readonly Dictionary<string, Shader> Pipeline = new( StringComparer.OrdinalIgnoreCase )
	{
		["933532a4fcc9baf4fa0491de14d08ed7"] = new( "Universal Render Pipeline/Lit", Workflow.Metallic, true, true ),
		["69c1f799e772cb6438f56c23efccb782"] = new( "Universal Render Pipeline/Terrain/Lit", Workflow.Other, false, true ),
		// Particle materials show the property layouts: Lit has _Smoothness/_Metallic, Unlit has neither.
		["b7839dad95683814aa64166edc107ae2"] = new( "Universal Render Pipeline/Particles/Lit", Workflow.Other, false, true ),
		["0406db5a14f94604a8c57ccfbc9f3b46"] = new( "Universal Render Pipeline/Particles/Unlit", Workflow.Other, false, true, Unlit: true ),
		["650dd9526735d5b46b79224bc6e94025"] = new( "Universal Render Pipeline/Unlit", Workflow.Other, false, true, Unlit: true ),
		["6e4ae4064600d784cac1e41a9e6f2e59"] = new( "HDRP/Lit", Workflow.Metallic, false, false ),
		["1d64af84bdc970c4fae0c1e06dd95b73"] = new( "HDRP/Decal", Workflow.Other, false, false ),
	};

	internal static Shader Identify( UnityReference shader )
	{
		if ( !(shader.Guid ?? "").Equals( BuiltinGuid, StringComparison.OrdinalIgnoreCase ) ) return Pipeline.GetValueOrDefault( shader.Guid ?? "" );
		return shader.FileId switch
		{
			46 => new( "Standard", Workflow.Metallic, true, false ),
			45 => new( "Standard (Specular setup)", Workflow.Specular, true, false ),
			// Legacy foliage shaders observed only on leaf/plant materials, all with _Cutoff. 10601 has the Tree Creator
			// Leaves layout (_TranslucencyMap, _Cutoff), which renders both sides.
			10601 => new( "Unity built-in tree leaves shader", Workflow.Other, false, false, AlphaTest: true, Backfaces: true ),
			10511 or 51 => new( $"Unity built-in cutout shader {shader.FileId}", Workflow.Other, false, false, AlphaTest: true ),
			// Legacy particle shaders, observed only on particle/FX materials with the _TintColor/_InvFade layout.
			>= 200 and <= 205 => new( $"Unity built-in particle shader {shader.FileId}", Workflow.Other, false, false, Unlit: true, LegacyParticle: true ),
			// Skybox shaders, converted to sky materials (UnitySky).
			103 => new( "Skybox/Cubemap", Workflow.Other, false, false, Unlit: true ),
			104 => new( "Skybox/6 Sided", Workflow.Other, false, false, Unlit: true ),
			106 => new( "Skybox/Procedural", Workflow.Other, false, false, Unlit: true ),
			108 => new( "Skybox/Panoramic", Workflow.Other, false, false, Unlit: true ),
			_ => new( $"Unity built-in shader {shader.FileId}", Workflow.Other, false, false ),
		};
	}

	/// <summary>
	/// Texture properties declared by Unity-shipped shaders. A known-shader material's texture outside this list is a
	/// leftover from a previous (custom) shader: Unity keeps such properties but no Unity shader reads them.
	/// </summary>
	internal static readonly HashSet<string> TextureProperties = new( StringComparer.Ordinal )
	{
		// Standard, Standard (Specular setup) and URP Lit/Simple Lit
		"_MainTex", "_BaseMap", "_BumpMap", "_DetailAlbedoMap", "_DetailNormalMap", "_DetailMask", "_EmissionMap", "_MetallicGlossMap",
		"_SpecGlossMap", "_OcclusionMap", "_ParallaxMap", "_ClearCoatMap",
		// Legacy, nature/tree, particle, water and skybox shaders
		"_Illum", "_DecalTex", "_DetailTex", "_Detail", "_LightMap", "_Cube", "_ReflectionTex", "_RefractionTex", "_ReflectiveColor",
		"_ReflectiveColorCube", "_Fresnel", "_BumpSpecMap", "_TranslucencyMap", "_GlossMap", "_ShadowOffset", "_ShadowTex", "_NoiseTex",
		"_MaskTex", "_AlphaTex", "_SecondTex", "_ThirdTex", "_FrontTex", "_BackTex", "_LeftTex", "_RightTex", "_UpTex", "_DownTex", "_Tex",
		// Terrain
		"_Control", "_Splat0", "_Splat1", "_Splat2", "_Splat3", "_Normal0", "_Normal1", "_Normal2", "_Normal3", "_Mask0", "_Mask1", "_Mask2",
		"_Mask3", "_TerrainHolesTexture",
		// HDRP Lit, Unlit and Decal
		"_BaseColorMap", "_MaskMap", "_NormalMap", "_NormalMapOS", "_BentNormalMap", "_BentNormalMapOS", "_HeightMap", "_DetailMap",
		"_TangentMap", "_TangentMapOS", "_AnisotropyMap", "_SubsurfaceMaskMap", "_TransmissionMaskMap", "_ThicknessMap",
		"_IridescenceThicknessMap", "_IridescenceMaskMap", "_SpecularColorMap", "_EmissiveColorMap", "_CoatMaskMap",
		"_TransmittanceColorMap", "_DistortionVectorMap", "_UnlitColorMap",
	};
	/// <summary>Texture names only HDRP shaders read: leftovers on a built-in or URP material.</summary>
	internal static readonly HashSet<string> HighDefinitionOnly = new( StringComparer.Ordinal ) { "_BaseColorMap", "_MaskMap", "_NormalMap", "_NormalMapOS", "_EmissiveColorMap", "_HeightMap", "_DetailMap", "_UnlitColorMap" };
	/// <summary>Texture names only built-in and URP shaders read: leftovers on an HDRP material.</summary>
	internal static readonly HashSet<string> BuiltinUniversalOnly = new( StringComparer.Ordinal ) { "_MainTex", "_BaseMap", "_BumpMap", "_MetallicGlossMap", "_SpecGlossMap", "_OcclusionMap", "_EmissionMap", "_ParallaxMap", "_DetailAlbedoMap", "_DetailNormalMap", "_DetailMask" };
}