Search Unity

  1. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Can't see changes on DepthOfField

Discussion in 'High Definition Render Pipeline' started by ozaneski13, May 16, 2023.

  1. ozaneski13

    ozaneski13

    Joined:
    Oct 29, 2019
    Posts:
    9
    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.
     
    Last edited: May 16, 2023
  2. ozaneski13

    ozaneski13

    Joined:
    Oct 29, 2019
    Posts:
    9
    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.

    Code (CSharp):
    1. dof.quality.levelAndOverride = (1, true);
     

    Attached Files:

    chap-unity likes this.
  3. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    752
    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).

    Code (CSharp):
    1.  
    2.        // Retrieving volume profile
    3.         VolumeProfile profile = m_Volume.sharedProfile;
    4.         if (!profile.TryGet<DepthOfField>(out var dof))
    5.         {
    6.             dof = profile.Add<DepthOfField>(false);
    7.         }
    8.  
    9.         // Setting DoF quality setting to custom.
    10.         dof.quality.value = 3;
    11.         // Setting nearMaxBlur to 8
    12.         dof.nearMaxBlur = 8;
    13.  
    Hope that helps !
     
    Last edited: May 23, 2023
    ozaneski13 likes this.
  4. ozaneski13

    ozaneski13

    Joined:
    Oct 29, 2019
    Posts:
    9
    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;

    Code (CSharp):
    1. dof.quality.levelAndOverride = (1, true);
     
    chap-unity likes this.
  5. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    752
    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 !
     
    ozaneski13 likes this.
  6. ozaneski13

    ozaneski13

    Joined:
    Oct 29, 2019
    Posts:
    9
    Thank you so much. Can you inform us about updates?
     
  7. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    752
    Will do
     
    ozaneski13 likes this.
  8. ozaneski13

    ozaneski13

    Joined:
    Oct 29, 2019
    Posts:
    9
  9. chap-unity

    chap-unity

    Unity Technologies

    Joined:
    Nov 4, 2019
    Posts:
    752
    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.
     
  10. ozaneski13

    ozaneski13

    Joined:
    Oct 29, 2019
    Posts:
    9
    Thank you for your response. I will follow from issue tracker from now on.

    Have a good day.
     
    chap-unity likes this.