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

Question Sampling from diffuse (and other) GBuffers for deferred HDRP post processes

Discussion in 'Image Effects' started by Lad-Ty, Jul 11, 2020.

  1. Lad-Ty

    Lad-Ty

    Joined:
    May 7, 2013
    Posts:
    53
    Hi, I'd like to ask for help here. I'm implementing an SSGI post process, with HDRP in deferred. I have finally everything working (at least it seems like it). But when applying the final result of the sampled global illumination (/indirect lighting) from the nearby environment, I need one last piece of the puzzle - to be able to get diffuse colors of individual objects/faces I'm trying to apply the GI on.

    Right now I am only able to get color of the surfaces from the original image, which is ok in actually lit scenes. But for correct color mixing I need to know diffuse component of each surface I'm bouncing the light on, so I can light up even objects that are fully shadowed (black) without it.

    I'm reading everywhere, that "_CameraGBufferTexture0" serves this purpose. But when I use this, shader complains about undeclared variable (quite reasonably). If I declare it as "sampler2D _CameraGBufferTexture0;" and then read "tex2D(_CameraGBufferTexture0, uv);" the result is always grey color. So I am guessing I am missing some key info here, maybe these names are old - used with the "CG" includes, and current HDRP when working with "HLSL" includes uses different ones, or I need to pass them myself from the postprocess .cs side?
     
    Last edited: Jul 11, 2020
  2. Lad-Ty

    Lad-Ty

    Joined:
    May 7, 2013
    Posts:
    53
    After another few hours of searching, I found this post by @bgolus
    https://forum.unity.com/threads/accessing-deferred-renderer-g-buffers.315223/#post-5078510
    Sadly all my tests to get to that buffer were still unsuccessfull. I tried all declaration+sampling possibilities I could think of, but none of
    TEXTURE2D_X(_GBufferTexture0); + LOAD_TEXTURE2D_X(_GBufferTexture0, positionSS);
    TEXTURE2D(_GBufferTexture0); + SAMPLE_TEXTURE2D(_GBufferTexture0, s_linear_clamp_sampler, uv);
    sampler2D _GBufferTexture0; + tex2D(_GBufferTexture0, uv);
    didn't seem to do the trick. Honestly, I'm just trying stuff at random at this point, but still no luck :(

    Edit: Surprisingly, I get some results from _GBufferTexture1 (which should be for specular color?), but _GBufferTexture0 is fully black.
     
    Last edited: Jul 12, 2020