Material and Shader properties logging

I needed a script which lists the material and shader properties for comparison. Couldn’t find one on the web, so I created a quick one myself and thought I’d share, feel free to extend:

#if UNITY_EDITOR
using System;
using UnityEngine;
using UnityEditor;
using static UnityEditor.ShaderUtil;

namespace DeveloperTools
{
    public static class MaterialAnalysis
    {
        static readonly IFormatProvider Formatter = new System.Globalization.CultureInfo("en-US");

        /// <summary>
        /// Log material and shader data to the console.
        /// </summary>
        /// <param name="material"></param>
        public static void LogMaterial(Material material)
        {
            Shader shader = material.shader;

            string text = "";

            #region Common
            text += string.Format("Shader Name = {0}", shader.name);
            text += "\n";
            text += string.Format("Render Queue = {0}", shader.renderQueue);
            text += "\n";
            #endregion Common

            #region Shader Keywords
            text += "Shader Keywords";
            text += "\n";

            for (int i = 0; i < material.shaderKeywords.Length; i++)
            {
                text += string.Format("{0}: {1}", i, material.shaderKeywords[i]);
                text += "\n";
            }
            #endregion Shader Keywords

            #region Properties
            text += "Properties";
            text += "\n";

            for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); i++)
            {
                string propertyName = ShaderUtil.GetPropertyName(shader, i);
                ShaderPropertyType propertyType = (ShaderPropertyType)ShaderUtil.GetPropertyType(shader, i);
                string propertyDescription = ShaderUtil.GetPropertyDescription(shader, i);

                string value;

                switch (propertyType)
                {
                    case ShaderPropertyType.Color: // The property holds a Vector4 value representing a color.
                        value = string.Format(Formatter, "{0}", material.GetColor(propertyName));
                        break;
                    case ShaderPropertyType.Vector: // The property holds a Vector4 value.
                        value = string.Format(Formatter, "{0}", material.GetVector(propertyName));
                        break;
                    case ShaderPropertyType.Float: // The property holds a floating number value.
                        value = string.Format(Formatter, "{0}", material.GetFloat(propertyName));
                        break;
                    case ShaderPropertyType.Range: //    The property holds a floating number value in a certain range.
                        value = string.Format(Formatter, "{0}", material.GetFloat(propertyName));
                        break;
                    case ShaderPropertyType.TexEnv: // The property holds a Texture object.
                        value = material.GetTexture(propertyName) == null ? "null" : string.Format(Formatter, "{0}", material.GetTexture(propertyName).dimension);
                        break;
                    default:
                        value = "<undefined>";
                        break;
                }

                text += string.Format("{0}: {1} = {2} ({3}, {4})", i, propertyName, value, propertyType, propertyDescription);
                text += "\n";
            }
            #endregion Properties

            #region Shader Passes
            text += "Shader Passes";
            text += "\n";

            for (int i = 0; i < material.passCount; i++)
            {
                text += string.Format("{0}: {1} = {2}", i, material.GetPassName(i), material.GetShaderPassEnabled(material.GetPassName(i)));
                text += "\n";
            }
            #endregion Shader Passes

            Debug.Log(text);
        }
    }
}
#endif

Output:

Shader Name = HDRP/Lit
Render Queue = 2000
Shader Keywords
0: _BLENDMODE_ALPHA
1: _BLENDMODE_PRESERVE_SPECULAR_LIGHTING
2: _ENABLE_FOG_ON_TRANSPARENT
3: _NORMALMAP_TANGENT_SPACE
4: _SURFACE_TYPE_TRANSPARENT
Properties
0: _BaseColor = RGBA(0.749, 0.000, 0.000, 0.000) (Color, BaseColor)
1: _BaseColorMap = null (TexEnv, BaseColorMap)
2: _BaseColorMap_MipInfo = (0.0, 0.0, 0.0, 0.0) (Vector, _BaseColorMap_MipInfo)
3: _Metallic = 1 (Range, _Metallic)
4: _Smoothness = 1 (Range, Smoothness)
5: _MaskMap = null (TexEnv, MaskMap)
6: _SmoothnessRemapMin = 0 (Float, SmoothnessRemapMin)
7: _SmoothnessRemapMax = 1 (Float, SmoothnessRemapMax)
8: _AORemapMin = 0 (Float, AORemapMin)
9: _AORemapMax = 1 (Float, AORemapMax)
10: _NormalMap = null (TexEnv, NormalMap)
11: _NormalMapOS = null (TexEnv, NormalMapOS)
12: _NormalScale = 1 (Range, _NormalScale)
13: _BentNormalMap = null (TexEnv, _BentNormalMap)
14: _BentNormalMapOS = null (TexEnv, _BentNormalMapOS)
15: _HeightMap = null (TexEnv, HeightMap)
16: _HeightAmplitude = 0.02 (Float, Height Amplitude)
17: _HeightCenter = 0.5 (Range, Height Center)
18: _HeightMapParametrization = 0 (Float, Heightmap Parametrization)
19: _HeightOffset = 0 (Float, Height Offset)
20: _HeightMin = -1 (Float, Heightmap Min)
21: _HeightMax = 1 (Float, Heightmap Max)
22: _HeightTessAmplitude = 2 (Float, Amplitude)
23: _HeightTessCenter = 0.5 (Range, Height Center)
24: _HeightPoMAmplitude = 2 (Float, Height Amplitude)
25: _DetailMap = null (TexEnv, DetailMap)
26: _DetailAlbedoScale = 1 (Range, _DetailAlbedoScale)
27: _DetailNormalScale = 1 (Range, _DetailNormalScale)
28: _DetailSmoothnessScale = 1 (Range, _DetailSmoothnessScale)
29: _TangentMap = null (TexEnv, TangentMap)
30: _TangentMapOS = null (TexEnv, TangentMapOS)
31: _Anisotropy = 0 (Range, Anisotropy)
32: _AnisotropyMap = null (TexEnv, AnisotropyMap)
33: _SubsurfaceMask = 1 (Range, Subsurface Radius)
34: _SubsurfaceMaskMap = null (TexEnv, Subsurface Radius Map)
35: _Thickness = 1 (Range, Thickness)
36: _ThicknessMap = null (TexEnv, Thickness Map)
37: _ThicknessRemap = (0.0, 1.0, 0.0, 0.0) (Vector, Thickness Remap)
38: _IridescenceThickness = 1 (Range, Iridescence Thickness)
39: _IridescenceThicknessMap = null (TexEnv, Iridescence Thickness Map)
40: _IridescenceThicknessRemap = (0.0, 1.0, 0.0, 0.0) (Vector, Iridescence Thickness Remap)
41: _IridescenceMask = 1 (Range, Iridescence Mask)
42: _IridescenceMaskMap = null (TexEnv, Iridescence Mask Map)
43: _CoatMask = 0 (Range, Coat Mask)
44: _CoatMaskMap = null (TexEnv, CoatMaskMap)
45: _EnergyConservingSpecularColor = 1 (Float, _EnergyConservingSpecularColor)
46: _SpecularColor = RGBA(1.000, 1.000, 1.000, 1.000) (Color, SpecularColor)
47: _SpecularColorMap = null (TexEnv, SpecularColorMap)
48: _SpecularOcclusionMode = 1 (Float, Specular Occlusion Mode)
49: _EmissiveColor = RGBA(0.000, 0.000, 0.000, 1.000) (Color, EmissiveColor)
50: _EmissiveColorLDR = RGBA(0.000, 0.000, 0.000, 1.000) (Color, EmissiveColor LDR)
51: _EmissiveColorMap = null (TexEnv, EmissiveColorMap)
52: _AlbedoAffectEmissive = 0 (Float, Albedo Affect Emissive)
53: _EmissiveIntensityUnit = 0 (Float, Emissive Mode)
54: _UseEmissiveIntensity = 0 (Float, Use Emissive Intensity)
55: _EmissiveIntensity = 1 (Float, Emissive Intensity)
56: _EmissiveExposureWeight = 1 (Range, Emissive Pre Exposure)
57: _DistortionVectorMap = null (TexEnv, DistortionVectorMap)
58: _DistortionEnable = 0 (Float, Enable Distortion)
59: _DistortionDepthTest = 1 (Float, Distortion Depth Test Enable)
60: _DistortionBlendMode = 0 (Float, Distortion Blend Mode)
61: _DistortionSrcBlend = 1 (Float, Distortion Blend Src)
62: _DistortionDstBlend = 1 (Float, Distortion Blend Dst)
63: _DistortionBlurSrcBlend = 1 (Float, Distortion Blur Blend Src)
64: _DistortionBlurDstBlend = 1 (Float, Distortion Blur Blend Dst)
65: _DistortionBlurBlendMode = 0 (Float, Distortion Blur Blend Mode)
66: _DistortionScale = 1 (Float, Distortion Scale)
67: _DistortionVectorScale = 2 (Float, Distortion Vector Scale)
68: _DistortionVectorBias = -1 (Float, Distortion Vector Bias)
69: _DistortionBlurScale = 1 (Float, Distortion Blur Scale)
70: _DistortionBlurRemapMin = 0 (Float, DistortionBlurRemapMin)
71: _DistortionBlurRemapMax = 1 (Float, DistortionBlurRemapMax)
72: _UseShadowThreshold = 0 (Float, _UseShadowThreshold)
73: _AlphaCutoffEnable = 0 (Float, Alpha Cutoff Enable)
74: _AlphaCutoff = 0.5 (Range, Alpha Cutoff)
75: _AlphaCutoffShadow = 0.5 (Range, _AlphaCutoffShadow)
76: _AlphaCutoffPrepass = 0.5 (Range, _AlphaCutoffPrepass)
77: _AlphaCutoffPostpass = 0.5 (Range, _AlphaCutoffPostpass)
78: _TransparentDepthPrepassEnable = 0 (Float, _TransparentDepthPrepassEnable)
79: _TransparentBackfaceEnable = 0 (Float, _TransparentBackfaceEnable)
80: _TransparentDepthPostpassEnable = 0 (Float, _TransparentDepthPostpassEnable)
81: _TransparentSortPriority = 0 (Float, _TransparentSortPriority)
82: _RefractionModel = 0 (Float, Refraction Model)
83: _SSRefractionProjectionModel = 0 (Float, Refraction Projection Model)
84: _Ior = 1.5 (Range, Index Of Refraction)
85: _TransmittanceColor = RGBA(1.000, 1.000, 1.000, 1.000) (Color, Transmittance Color)
86: _TransmittanceColorMap = null (TexEnv, TransmittanceColorMap)
87: _ATDistance = 1 (Float, Transmittance Absorption Distance)
88: _TransparentWritingMotionVec = 0 (Float, _TransparentWritingMotionVec)
89: _StencilRef = 0 (Float, _StencilRef)
90: _StencilWriteMask = 6 (Float, _StencilWriteMask)
91: _StencilRefGBuffer = 10 (Float, _StencilRefGBuffer)
92: _StencilWriteMaskGBuffer = 14 (Float, _StencilWriteMaskGBuffer)
93: _StencilRefDepth = 8 (Float, _StencilRefDepth)
94: _StencilWriteMaskDepth = 8 (Float, _StencilWriteMaskDepth)
95: _StencilRefMV = 40 (Float, _StencilRefMV)
96: _StencilWriteMaskMV = 40 (Float, _StencilWriteMaskMV)
97: _StencilRefDistortionVec = 4 (Float, _StencilRefDistortionVec)
98: _StencilWriteMaskDistortionVec = 4 (Float, _StencilWriteMaskDistortionVec)
99: _SurfaceType = 1 (Float, __surfacetype)
100: _BlendMode = 0 (Float, __blendmode)
101: _SrcBlend = 1 (Float, __src)
102: _DstBlend = 10 (Float, __dst)
103: _AlphaSrcBlend = 1 (Float, __alphaSrc)
104: _AlphaDstBlend = 10 (Float, __alphaDst)
105: _ZWrite = 0 (Float, __zw)
106: _TransparentZWrite = 0 (Float, _TransparentZWrite)
107: _CullMode = 2 (Float, __cullmode)
108: _CullModeForward = 2 (Float, __cullmodeForward)
109: _TransparentCullMode = 2 (Float, _TransparentCullMode)
110: _ZTestDepthEqualForOpaque = 4 (Float, _ZTestDepthEqualForOpaque)
111: _ZTestModeDistortion = 4 (Float, _ZTestModeDistortion)
112: _ZTestGBuffer = 4 (Float, _ZTestGBuffer)
113: _ZTestTransparent = 4 (Float, Transparent ZTest)
114: _EnableFogOnTransparent = 1 (Float, Enable Fog)
115: _EnableBlendModePreserveSpecularLighting = 1 (Float, Enable Blend Mode Preserve Specular Lighting)
116: _DoubleSidedEnable = 0 (Float, Double sided enable)
117: _DoubleSidedNormalMode = 1 (Float, Double sided normal mode)
118: _DoubleSidedConstants = (1.0, 1.0, -1.0, 0.0) (Vector, _DoubleSidedConstants)
119: _UVBase = 0 (Float, UV Set for base)
120: _TexWorldScale = 1 (Float, Scale to apply on world coordinate)
121: _InvTilingScale = 1 (Float, Inverse tiling scale = 2 / (abs(_BaseColorMap_ST.x) + abs(_BaseColorMap_ST.y)))
122: _UVMappingMask = RGBA(1.000, 0.000, 0.000, 0.000) (Color, _UVMappingMask)
123: _NormalMapSpace = 0 (Float, NormalMap space)
124: _MaterialID = 1 (Float, MaterialId)
125: _TransmissionEnable = 1 (Float, _TransmissionEnable)
126: _DisplacementMode = 0 (Float, DisplacementMode)
127: _DisplacementLockObjectScale = 1 (Float, displacement lock object scale)
128: _DisplacementLockTilingScale = 1 (Float, displacement lock tiling scale)
129: _DepthOffsetEnable = 0 (Float, Depth Offset View space)
130: _EnableGeometricSpecularAA = 0 (Float, EnableGeometricSpecularAA)
131: _SpecularAAScreenSpaceVariance = 0.1 (Range, SpecularAAScreenSpaceVariance)
132: _SpecularAAThreshold = 0.2 (Range, SpecularAAThreshold)
133: _PPDMinSamples = 5 (Range, Min sample for POM)
134: _PPDMaxSamples = 15 (Range, Max sample for POM)
135: _PPDLodThreshold = 5 (Range, Start lod to fade out the POM effect)
136: _PPDPrimitiveLength = 1 (Float, Primitive length for POM)
137: _PPDPrimitiveWidth = 1 (Float, Primitive width for POM)
138: _InvPrimScale = (1.0, 1.0, 0.0, 0.0) (Vector, Inverse primitive scale for non-planar POM)
139: _UVDetail = 0 (Float, UV Set for detail)
140: _UVDetailsMappingMask = RGBA(1.000, 0.000, 0.000, 0.000) (Color, _UVDetailsMappingMask)
141: _LinkDetailsWithBase = 1 (Float, LinkDetailsWithBase)
142: _EmissiveColorMode = 1 (Float, Emissive color mode)
143: _UVEmissive = 0 (Float, UV Set for emissive)
144: _TexWorldScaleEmissive = 1 (Float, Scale to apply on world coordinate)
145: _UVMappingMaskEmissive = RGBA(1.000, 0.000, 0.000, 0.000) (Color, _UVMappingMaskEmissive)
146: _EmissionColor = RGBA(1.000, 1.000, 1.000, 1.000) (Color, Color)
147: _MainTex = null (TexEnv, Albedo)
148: _Color = RGBA(0.749, 0.000, 0.000, 0.000) (Color, Color)
149: _Cutoff = 0.5 (Range, Alpha Cutoff)
150: _SupportDecals = 1 (Float, Support Decals)
151: _ReceivesSSR = 1 (Float, Receives SSR)
152: _AddPrecomputedVelocity = 0 (Float, AddPrecomputedVelocity)
153: _DiffusionProfile = 0 (Float, Obsolete, kept for migration purpose)
154: _DiffusionProfileAsset = (0.0, 0.0, 0.0, 0.0) (Vector, Diffusion Profile Asset)
155: _DiffusionProfileHash = 0 (Float, Diffusion Profile Hash)
Shader Passes
0: SceneSelectionPass = True
1: GBuffer = True
2: META = True
3: ShadowCaster = True
4: DepthOnly = True
5: MotionVectors = False
6: DistortionVectors = False
7: TransparentDepthPrepass = False
8: TransparentBackface = False
9: Forward = True
10: TransparentDepthPostpass = False
3 Likes

In case anyone needs it: I had to find out which Shader values to set after I changed the Transparent Depth Prepass on a HDRP material. So I wrote a Diff helper tool. You can find it here:

https://github.com/Roland09/MaterialAnalyzer

Long story short:

  • create a gameobject and attach the MaterialPicker script to it:

6417503--717173--mp.png

  • drag a gameobject with a material into the Analyzed Object slot

Buttons:

  • Log Material logs the material settings into the console
  • Store A stores the current material settings
  • Store B stores the current material settings
  • Diff A → B and Diff B → A show the respective differences

Example from changing the Transparent Depth Prepass checkbox:

Diff A -> B:
Common
Keywords
0: _DISABLE_SSR_TRANSPARENT
Properties
0: _DistortionSrcBlend = 1 (Float, Distortion Blend Src)
1: _DistortionDstBlend = 1 (Float, Distortion Blend Dst)
2: _DistortionBlurSrcBlend = 1 (Float, Distortion Blur Blend Src)
3: _DistortionBlurDstBlend = 1 (Float, Distortion Blur Blend Dst)
4: _TransparentDepthPrepassEnable = 1 (Float, _TransparentDepthPrepassEnable)
5: _StencilWriteMask = 6 (Float, _StencilWriteMask)
6: _StencilWriteMaskGBuffer = 14 (Float, _StencilWriteMaskGBuffer)
7: _StencilWriteMaskMV = 40 (Float, _StencilWriteMaskMV)
8: _AlphaDstBlend = 10 (Float, __alphaDst)
9: _ZTestModeDistortion = 4 (Float, _ZTestModeDistortion)
ShaderPasses
0: TransparentDepthPrepass = True
1: RayTracingPrepass = False

ie those are all the settings I have to apply via code if I wanted to change the Transparent Depth Prepass via code.

Or in other words: This is an example of what Unity modifies if you tick the mentioned single checkbox in the Material Inspector.

1 Like