Skip to content

Instantly share code, notes, and snippets.

@JimmyCushnie
Last active October 31, 2025 04:34
Show Gist options
  • Select an option

  • Save JimmyCushnie/e998cdec15394d6b68a4dbbf700f66ce to your computer and use it in GitHub Desktop.

Select an option

Save JimmyCushnie/e998cdec15394d6b68a4dbbf700f66ce to your computer and use it in GitHub Desktop.
Exposes some Unity URP graphics settings that are (for some stupid fucking bullshit reason) private.
using System.Reflection;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using ShadowResolution = UnityEngine.Rendering.Universal.ShadowResolution;
/// <summary>
/// Enables getting/setting URP graphics settings properties that don't have built-in getters and setters.
/// </summary>
public static class UnityGraphicsBullshit
{
private static FieldInfo MainLightCastShadows_FieldInfo;
private static FieldInfo AdditionalLightCastShadows_FieldInfo;
private static FieldInfo MainLightShadowmapResolution_FieldInfo;
private static FieldInfo AdditionalLightShadowmapResolution_FieldInfo;
private static FieldInfo Cascade2Split_FieldInfo;
private static FieldInfo Cascade4Split_FieldInfo;
private static FieldInfo SoftShadowsEnabled_FieldInfo;
static UnityGraphicsBullshit()
{
var pipelineAssetType = typeof(UniversalRenderPipelineAsset);
var flags = BindingFlags.Instance | BindingFlags.NonPublic;
MainLightCastShadows_FieldInfo = pipelineAssetType.GetField("m_MainLightShadowsSupported", flags);
AdditionalLightCastShadows_FieldInfo = pipelineAssetType.GetField("m_AdditionalLightShadowsSupported", flags);
MainLightShadowmapResolution_FieldInfo = pipelineAssetType.GetField("m_MainLightShadowmapResolution", flags);
AdditionalLightShadowmapResolution_FieldInfo = pipelineAssetType.GetField("m_AdditionalLightsShadowmapResolution", flags);
Cascade2Split_FieldInfo = pipelineAssetType.GetField("m_Cascade2Split", flags);
Cascade4Split_FieldInfo = pipelineAssetType.GetField("m_Cascade4Split", flags);
SoftShadowsEnabled_FieldInfo = pipelineAssetType.GetField("m_SoftShadowsSupported", flags);
}
public static bool MainLightCastShadows
{
get => (bool)MainLightCastShadows_FieldInfo.GetValue(GraphicsSettings.currentRenderPipeline);
set => MainLightCastShadows_FieldInfo.SetValue(GraphicsSettings.currentRenderPipeline, value);
}
public static bool AdditionalLightCastShadows
{
get => (bool)AdditionalLightCastShadows_FieldInfo.GetValue(GraphicsSettings.currentRenderPipeline);
set => AdditionalLightCastShadows_FieldInfo.SetValue(GraphicsSettings.currentRenderPipeline, value);
}
public static ShadowResolution MainLightShadowResolution
{
get => (ShadowResolution)MainLightShadowmapResolution_FieldInfo.GetValue(GraphicsSettings.currentRenderPipeline);
set => MainLightShadowmapResolution_FieldInfo.SetValue(GraphicsSettings.currentRenderPipeline, value);
}
public static ShadowResolution AdditionalLightShadowResolution
{
get => (ShadowResolution)AdditionalLightShadowmapResolution_FieldInfo.GetValue(GraphicsSettings.currentRenderPipeline);
set => AdditionalLightShadowmapResolution_FieldInfo.SetValue(GraphicsSettings.currentRenderPipeline, value);
}
public static float Cascade2Split
{
get => (float)Cascade2Split_FieldInfo.GetValue(GraphicsSettings.currentRenderPipeline);
set => Cascade2Split_FieldInfo.SetValue(GraphicsSettings.currentRenderPipeline, value);
}
public static Vector3 Cascade4Split
{
get => (Vector3)Cascade4Split_FieldInfo.GetValue(GraphicsSettings.currentRenderPipeline);
set => Cascade4Split_FieldInfo.SetValue(GraphicsSettings.currentRenderPipeline, value);
}
public static bool SoftShadowsEnabled
{
get => (bool)SoftShadowsEnabled_FieldInfo.GetValue(GraphicsSettings.currentRenderPipeline);
set => SoftShadowsEnabled_FieldInfo.SetValue(GraphicsSettings.currentRenderPipeline, value);
}
}
@avi6111
Copy link

avi6111 commented Sep 18, 2024

Great Job! Somehow I did think that probably the staff did these shit for Commercial Thinking, they may not want UE copied them. but after these years, I think, may be the staff in Unity are just Dummy

@VEETEEGames
Copy link

VEETEEGames commented Oct 31, 2025

You just saved me from a break down

i wanted to contribute something so i added more options to change
and also if anyone wants to expand it you can just follow a similar layout

FInd a property you want to change on the RP asset ,right click ,copy property path
paste that in the constructor when you initialize it ,and set up the getters and setters

    public static class UnityGraphicsBullshit
    {
        private static readonly FieldInfo MainLightCastShadows_FieldInfo;
        private static readonly FieldInfo AdditionalLightCastShadows_FieldInfo;
        private static readonly FieldInfo MainLightShadowmapResolution_FieldInfo;
        private static readonly FieldInfo AdditionalLightShadowmapResolution_FieldInfo;
        private static readonly FieldInfo Cascade2Split_FieldInfo;
        private static readonly FieldInfo Cascade3Split_FieldInfo; // ← NEW
        private static readonly FieldInfo Cascade4Split_FieldInfo;
        private static readonly FieldInfo CascadeCount_FieldInfo; // ← NEW
        private static readonly FieldInfo SoftShadowsEnabled_FieldInfo;
        private static readonly FieldInfo ShadowDistance_FieldInfo; // ← NEW
        private static readonly FieldInfo ShadowQuality_FieldInfo; // ← NEW (Soft Shadow Quality)

        static UnityGraphicsBullshit()
        {
            var pipelineAssetType = typeof( UniversalRenderPipelineAsset );
            var flags = BindingFlags.Instance | BindingFlags.NonPublic;

            MainLightCastShadows_FieldInfo = pipelineAssetType.GetField("m_MainLightShadowsSupported", flags);
            AdditionalLightCastShadows_FieldInfo = pipelineAssetType.GetField("m_AdditionalLightShadowsSupported", flags);
            MainLightShadowmapResolution_FieldInfo = pipelineAssetType.GetField("m_MainLightShadowmapResolution", flags);
            AdditionalLightShadowmapResolution_FieldInfo = pipelineAssetType.GetField("m_AdditionalLightsShadowmapResolution", flags);
            Cascade2Split_FieldInfo = pipelineAssetType.GetField("m_Cascade2Split", flags);
            Cascade3Split_FieldInfo = pipelineAssetType.GetField("m_Cascade3Split", flags); // ← NEW
            Cascade4Split_FieldInfo = pipelineAssetType.GetField("m_Cascade4Split", flags);
            CascadeCount_FieldInfo = pipelineAssetType.GetField("m_ShadowCascadeCount", flags); // ← NEW
            SoftShadowsEnabled_FieldInfo = pipelineAssetType.GetField("m_SoftShadowsSupported", flags);
            ShadowDistance_FieldInfo = pipelineAssetType.GetField("m_ShadowDistance", flags); // ← NEW
            ShadowQuality_FieldInfo = pipelineAssetType.GetField("m_SoftShadowQuality", flags); // ← NEW (Soft quality)
        }
        private static UniversalRenderPipelineAsset CurrentAsset => GraphicsSettings.currentRenderPipeline as UniversalRenderPipelineAsset;

        // === EXISTING ===
        public static bool MainLightCastShadows
        {
            get => (bool)MainLightCastShadows_FieldInfo.GetValue(CurrentAsset);
            set => MainLightCastShadows_FieldInfo.SetValue(CurrentAsset, value);
        }

        public static bool AdditionalLightCastShadows
        {
            get => (bool)AdditionalLightCastShadows_FieldInfo.GetValue(CurrentAsset);
            set => AdditionalLightCastShadows_FieldInfo.SetValue(CurrentAsset, value);
        }

        public static ShadowResolution MainLightShadowResolution
        {
            get => (ShadowResolution)MainLightShadowmapResolution_FieldInfo.GetValue(CurrentAsset);
            set => MainLightShadowmapResolution_FieldInfo.SetValue(CurrentAsset, value);
        }

        public static ShadowResolution AdditionalLightShadowResolution
        {
            get => (ShadowResolution)AdditionalLightShadowmapResolution_FieldInfo.GetValue(CurrentAsset);
            set => AdditionalLightShadowmapResolution_FieldInfo.SetValue(CurrentAsset, value);
        }

        public static float Cascade2Split
        {
            get => (float)Cascade2Split_FieldInfo.GetValue(CurrentAsset);
            set => Cascade2Split_FieldInfo.SetValue(CurrentAsset, value);
        }

        public static Vector3 Cascade4Split
        {
            get => (Vector3)Cascade4Split_FieldInfo.GetValue(CurrentAsset);
            set => Cascade4Split_FieldInfo.SetValue(CurrentAsset, value);
        }

        public static bool SoftShadowsEnabled
        {
            get => (bool)SoftShadowsEnabled_FieldInfo.GetValue(CurrentAsset);
            set => SoftShadowsEnabled_FieldInfo.SetValue(CurrentAsset, value);
        }

        // === NEW: 1. Shadow Max Distance ===
        public static float ShadowMaxDistance
        {
            get => (float)ShadowDistance_FieldInfo.GetValue(CurrentAsset);
            set => ShadowDistance_FieldInfo.SetValue(CurrentAsset, Mathf.Max(0.1f, value));
        }

        // === NEW: 2. Cascade 3 Split ===
        public static Vector2 Cascade3Split
        {
            get => (Vector2)Cascade3Split_FieldInfo.GetValue(CurrentAsset);
            set => Cascade3Split_FieldInfo.SetValue(CurrentAsset, value);
        }

        // === NEW: 3. Cascade Count (1, 2, 3, 4) ===
        public static int CascadeCount
        {
            get => (int)CascadeCount_FieldInfo.GetValue(CurrentAsset);
            set => CascadeCount_FieldInfo.SetValue(CurrentAsset, Mathf.Clamp(value, 1, 4));
        }

        // === NEW: 4. Soft Shadow Quality (Low/Med/High) ===
        public static SoftShadowQuality SoftShadowQuality
        {
            get => (SoftShadowQuality)ShadowQuality_FieldInfo.GetValue(CurrentAsset);
            set => ShadowQuality_FieldInfo.SetValue(CurrentAsset, value);
        }
        public static void SetToUltra()
        {
            MainLightCastShadows = true;
            AdditionalLightCastShadows = true;
            MainLightShadowResolution = ShadowResolution._2048;
            AdditionalLightShadowResolution = ShadowResolution._1024;
            ShadowMaxDistance = 80f;
            CascadeCount = 3;
            Cascade4Split = new Vector3(0.08f, 0.20f, 0.45f); // Near, Mid, Far
            SoftShadowsEnabled = true;
            SoftShadowQuality = SoftShadowQuality.Medium;
        }

        public static void SetToHigh()
        {
            MainLightCastShadows = true;
            AdditionalLightCastShadows = true;
            MainLightShadowResolution = ShadowResolution._1024;
            AdditionalLightShadowResolution = ShadowResolution._512;
            ShadowMaxDistance = 50f;
            CascadeCount = 2;
            Cascade2Split = 0.10f; // Near, Mid (Far = rest)
            SoftShadowsEnabled = true;
            SoftShadowQuality = SoftShadowQuality.Low;
        }

        public static void SetToMedium()
        {
            MainLightCastShadows = true;
            AdditionalLightCastShadows = false;
            MainLightShadowResolution = ShadowResolution._512;
            AdditionalLightShadowResolution = ShadowResolution._256;
            ShadowMaxDistance = 20f;
            CascadeCount = 1;
            SoftShadowsEnabled = false;
        }

        public static void SetToLow()
        {
            MainLightCastShadows = false;
            AdditionalLightCastShadows = false;
            MainLightShadowResolution = ShadowResolution._256;
            ShadowMaxDistance = 0f;
            CascadeCount = 1;
            SoftShadowsEnabled = false;
        }

        public static void SetQuality(int savedIndex)
        {
            switch (savedIndex)
            {
                case 0:
                    SetToLow();
                    break;
                case 1:
                    SetToMedium();
                    break;
                case 2:
                    SetToHigh();
                    break;
                case 3:
                    SetToUltra();
                    break;
            }
        }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment