Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Decode HDR GrabPass?

Discussion in 'Shaders' started by SunnySunshine, Jan 25, 2016.

  1. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    955
    When HDR is enabled on camera, GrabPass texture does not have RGB values in it. Rather, it has HDR values.

    How you decode these values into what they would have been without HDR enabled for the camera?

    I've tried using this:
    Code (CSharp):
    1. DecodeHDR(tex2D(_GrabTexture, IN.screenPos.xy / IN.screenPos.w), unity_SpecCube0_HDR);

    But it does not produce desired result.
     
    howong likes this.
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,248
    I believe DecodeHDR is for decoding texture assets saved in RGBM, not decoding the grab texture. You shouldn't need to do anything special with the grab pass HDR or not. I think the default way Unity displays HDR is just clamping the output between 0.0 and 1.0.
     
    howong likes this.
  3. SunnySunshine

    SunnySunshine

    Joined:
    May 18, 2009
    Posts:
    955
    Well this is awkward. This absolutely didn't work before. Using the HDR GrabTexture right away would cause everything to become white. But now when I try it works just fine. I've seen this before that sometimes all changes to a shader don't seem to apply instantly sometimes, but rather you need to restart the editor or reimport. That's frustrating considering I spent hours trying to solve this.
     
  4. krides

    krides

    Joined:
    Apr 7, 2011
    Posts:
    38
    I'm bumping this, because I've just stumbled across this problem myself. Everything is white in my Blur shader on OpenGL, and it works just fine on DirectX.

    The weird thing is that I only get it on OpenGLCore and never on DirectX.

    Does anyone have any ideas?
     
  5. bunp

    bunp

    Joined:
    Feb 21, 2019
    Posts:
    66
    I have the opposite problem, I am trying to get HDR values from a render texture, but I can only get SRGB values from 0 to 1. How do I extract HDR values from SAMPLE_TEXTURE2D?