How to change anti-aliasing and Shadow Resolution through code

Hey, how do I change the anti-aliasing on the camera through code? I tried to access it but I can’t find the right variable to change.

Also, how do I change the shadow resolution through code in HDRP? It used to be QualitySettings.shadowResolution in standard shader, but now it’s on the lights and HDRP settings.
Accessing the shadow distance and cascades through the volume isn’t a problem.

Here’s what I use for Anti Aliasing. You want to set the antialiasing of the HDAdditionalCameraData object on the same gameobject as the camera.

if (hdCameraData != null && shouldAdjustHDCameraOverrides)
{
    if (hdCameraData.antialiasing != GraphicsPlayerOptions.Antialiasing)
    {
        //Debug.Log($"Setting Anti-aliasing to to {GraphicsSettings.Antialiasing}");
        hdCameraData.antialiasing = GraphicsPlayerOptions.Antialiasing;

        // If using SMAA, make sure quality is set to High.
        if (GraphicsPlayerOptions.Antialiasing == HDAdditionalCameraData.AntialiasingMode.SubpixelMorphologicalAntiAliasing)
        {
            hdCameraData.SMAAQuality = HDAdditionalCameraData.SMAAQualityLevel.High;
        }
    }
}

I’m not sure about the shadow resolution, and whether you just need to iterate over all lights in the scene, or if there’s a better way.

1 Like

That works, thank you.

How about the other types of Anti-Aliasing? Like, MSAA to be specific.

The code I posted is for HDRP 7, so I don’t know if things have changed in later versions, but in HDRP 7 it’s just a matter of choosing the correct HDAdditionalCameraData.AntialiasingMode value. No idea if that’s still the case in later versions.

I’ll have to check this at work tomorrow. As far as I know, when doing this in the Editor for HDRP 7.5, we need to go into the HDRP quality settings, set HDRP to Forward rendering, check the MSAA checkbox, then go into the Frame Settings for the Camera, and set that to MSAA. At least, that’s what we do if we want MSAA. I’ll have to look though my copy of the HDRP 7.5 source code to see how setting the values onto the HDAdditionalCameraData trickles back to the project settings.

MSAA being a completely separate setup to the other AA settings is just… odd. I mean I guess because it is a forward-rendering hardware thing, not a post-effect (?) but I see no way to change MSAA at runtime either except by changing quality settings with different setups.

Shadow resolution does not seem changeable on a light at runtime (HDAdditionalLightData for a light just has gets like so many HDRP classes) but you can change quality settings to one with different shadow resolution settings (via a different hdrp asset assigned to it)

Quality settings let you change a load of hdrp settings at runtime by applying a different hdrp asset but no good for ‘toggling’ individual features