Can't see changes on DepthOfField

Greetings.

I am currently working on HDRP Volume profiles and I create Volume and add Depth Of Field to it via script and I can change Depth of Field values from script but can’t see the effect on camera. When I change values from script can’t see the new values at Depth of Field area until I move my cursor to Depth of Field area at editor. When I move it to area, values are changed but effect is not visible at game. I am not sure if it is a bug or not. Also SetDirty is deprecated, setting isDirty = true and setting DepthOfField.active = true didn’t worked for me.

Unity 2021.3.7f1

Thank you.

UPDATE

Okay, I figure it out but I am gonna blame Unity devs for it. Documentation about HDRP Volume Overrides basically useless and there is no explanation at functions in Unity.

I realize the changes I made at DepthOfField’s near and far ranges start-end can effect my camera in game but not the slider ones under Quality setting. After I dig HDRP codes I see that DepthOfField uses selected Quality Setting even if you change values, that’s why new values didn’t effect the camera while showed up on editor. You might say that “Why don’t you just change quality setting then?”. The problem is devs didn’t add Custom enum to ScalableSettingLevelParameter.Level as you can see at Image_1.

So you need to set Custom from somewhere else. This is the second weird path to follow. In DepthOfField.cs, every override has same if condition as you can see at Image_2 which checks if override uses Quality setting. But since you can’t set Quality to Custom with enum, you had to do some work arounds. To use your custom settings, UsesQualitySettings() should return false so reverse can return true and first if condition can work. But to return UsesQualitySettings false, !quality.levelAndOverride.useOverride should return true and so on which you can see at Image_3. I am sure they did it for some purpose but since there are no proper documentation about it, HDRP must be properly documented from scratch.

TLDR: If you want to use Custom settings at DepthOfField use the below code.

dof.quality.levelAndOverride = (1, true);


9018826--1243744--Image_2.PNG

1 Like

I agree that setting it to custom should be easier.
I’ll raise it and see what’s possible.

In the meantime you can set your override to custom (or any other level) by using an int instead.
For example, Custom should be 3 (0 is low, 1 is medium, 2 is high… you get it).

       // Retrieving volume profile
        VolumeProfile profile = m_Volume.sharedProfile;
        if (!profile.TryGet<DepthOfField>(out var dof))
        {
            dof = profile.Add<DepthOfField>(false);
        }

        // Setting DoF quality setting to custom.
        dof.quality.value = 3;
        // Setting nearMaxBlur to 8
        dof.nearMaxBlur = 8;

Hope that helps !

1 Like

Thank you for your response. This solution only works when you tick quality settings on editor before play. At my position I need to create volumes and DepthOfFields at runtime so can’t tick it without;

dof.quality.levelAndOverride = (1, true);
1 Like

Indeed, I misunderstood the issue about being able to override the quality settings themselves if you add the volume at runtime ! I’ll add this info to the report, thanks !

1 Like

Thank you so much. Can you inform us about updates?

Will do

1 Like

Any updates on topic? @chap-unity

Hey, indeed, sorry it has been a while. It has not been forgotten and has been discussed internally.
It’s just that the fix require some rework that is more of the side of a feature request than a bug fix and since it’s not a critical one, it’s not a big priority. It will get taken care of at some point though, thanks for your patience!

I made the report public (link) so you can check for update if you’d like.

Have a good one.

Thank you for your response. I will follow from issue tracker from now on.

Have a good day.

1 Like