Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question URP HDR alpha blending problem

Discussion in 'Universal Render Pipeline' started by EdwinPs, Jul 28, 2022.

  1. EdwinPs

    EdwinPs

    Joined:
    Dec 26, 2019
    Posts:
    2
    Untitled-2.png Hello, in my project I'm using URP with HDR enabled. The Problem is that when HDR is enabled and many textures overlap they become yellowish, when HDR is disabled it renders as it should. You can see an example in the picture above, particles systems spawns a lot of smoke textures with alpha blending shader and pixels with the smallest alpha becomes yellowish.

    Can't find any solution to that.
     
  2. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    I think URP HDR mode uses R11G11B10 framebuffer format by default. In that format the blue channel uses 10-bit floating point values while the red and green channels use 11-bit values. This means the blue channel will accumulate rounding errors faster than the green and red channel. In your case, it seems the blue channel is accumulating to a lower value than the green and red channel, causing the result to become yellow-ish.

    Ultimately, there isn't much you can do. You should at least try to reduce the amount of overlapping alpha transparencies, since that can become very expensive on mid and low end hardware.
     
    KonradNFP and EdwinPs like this.
  3. EdwinPs

    EdwinPs

    Joined:
    Dec 26, 2019
    Posts:
    2
    Hey,

    Thanks for the reply, you are absolutely right about that. Actually, even opaque materials which uses blue channel becomes a bit yellowish.
    It's a sad thing that you cannot do anything about it. I saw that HDRP has ability to change buffer to R16G16B16A16, maybe this feature will come to URP later also?
     
  4. KSzczech

    KSzczech

    Joined:
    Sep 24, 2020
    Posts:
    30
    We had the same problem in our game and I ended up solving it like this:

    - register your own callback for RenderPipelineManager.beginFrameRendering
    - In the callback, put your own render texture into camera that is about to render
    - add a fullscreen quad with that texture (you can use RawImage UI component placed on canvas)
    - add one more camera that renders this UI only to primary display

    This worked ok for forward rendering, but our current game is using deferred shading so I have to do research again.

    When researching this topic a while back, I found that older versions of Unity allowed choosing texture format, but the option is no longer available in URP.
     
    Last edited: Dec 18, 2023
  5. KSzczech

    KSzczech

    Joined:
    Sep 24, 2020
    Posts:
    30
    Good news guys - there's still a way to force proper HDR render targets in URP.

    You can't do it in Unity Editor, but you can open your URP rendering pipeline asset in notepad.
    These asset files are typically in your /Assets/Settings folder and you will have multiple assets for different quality levels.

    If you can't find it - simply search your Assets folder for any file named *.asset containing string "m_HDRColorBufferPrecision".

    By default this value is set to 0, meaning 32-bit HDR. Change this setting to 1 in your file - it will change HDR render targets to 64-bit precision and therefore give you equal bits per color component. This will make all your smoke and particles look good again.

    Cheers!
     
    MUGIK and tw00275 like this.
  6. tw00275

    tw00275

    Joined:
    Oct 19, 2018
    Posts:
    102
    @KSzczech In Unity 2022.3, URP 14, they added the option to change this in the editor. It's in the URP Asset settings under Quality -> HDR -> HDR Precision. I just tested it and it does change the value of m_HDRColorBufferPrecision.

    If you want to change it through scripting, you can use something like this:

    UniversalRenderPipelineAsset universalRenderPipelineAsset = (UniversalRenderPipelineAsset)QualitySettings.renderPipeline;
    universalRenderPipelineAsset.hdrColorBufferPrecision = HDRColorBufferPrecision._64Bits;

    It's great to see an example of where 64-bit precision helps.
     
    KSzczech and oliverschnabel like this.
  7. KSzczech

    KSzczech

    Joined:
    Sep 24, 2020
    Posts:
    30
    I'm on 2022.3.11f1 with URP version 14.0.9 and I don't have it in asset settings. So I guss I'm close and when we update again we will have it in GUI.

    For those using older versions, our info about changing it in files or via scripting will still be useful.

    Thanks for the additional info.
     
  8. MUGIK

    MUGIK

    Joined:
    Jul 2, 2015
    Posts:
    486
    Thank you so much! I've spent a whole hour investigating this issue.
    The funny thing is that in scene view it renders properly, the problem is only with GameView. Designer almost went insane trying to find the mysterious post-processing volume responsible for that yellow-ish color.