Search Unity

_CameraGBufferTexture3 output in shaderlab

Discussion in 'Shaders' started by bugsbun, Aug 20, 2017.

  1. bugsbun

    bugsbun

    Joined:
    Jun 26, 2017
    Posts:
    27
    When I sample the _CameraGBufferTexture in the fragment shader inside unity shaderlab using :

    return tex2D(_CameraGBufferTexture3,i.uv);

    I get the following output:

    Original Image: http://imgur.com/a/q1EOc

    Frag output: http://imgur.com/a/2LqIv

    What I expected was the opposite values, that is bright spots on the bright parts of the ring. since this texture according to Unity stores the Emission + lighting + lightmaps + reflection probes buffer. Am I expecting something wrong.

    What I want :: I just wanted the light color value to be outputed through my shader, that is the value of the light color that is being reflected from various surfaces seen in the scene. Is this method correct?

    Thanks in advance!
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    When HDR is disabled that gbuffer is stored in a peculiar way:
    color = exp2(-color);

    You will want to add something like this to your code:

    #if UNITY_HDR_ON
    return tex2D(_CameraGBufferTexture3, i.uv);
    #else
    return -log2(tex2D(_CameraGBufferTexture3, i.uv));
    #endif
     
    bugsbun likes this.
  3. bugsbun

    bugsbun

    Joined:
    Jun 26, 2017
    Posts:
    27
    I am not using HDR at the moment, so I am returning :

    return -log2(tex2D(_CameraGBufferTexture3, i.uv));

    I get the same output as I see in the original Image : http://imgur.com/a/q1EOc

    what is the difference between the 2 then ? I mean

    return -log2(tex2D(_CameraGBufferTexture3, i.uv));
    return tex2D(_MainTex, i.uv);