Search Unity

Bug Custom pass to write to normal buffer using a fullscreen shader?

Discussion in 'High Definition Render Pipeline' started by camerondus, Oct 6, 2022.

  1. camerondus

    camerondus

    Joined:
    Dec 15, 2018
    Posts:
    52
    Hello,
    I have dumped way too many hours of my life into this, and at this point i can only assume that the system is bugged.
    I am trying to write to the normal buffer in After Opaque depth and Normal (both the normal (RGB) and roughness (A). There are several issues with this in the current custom pass fullscreen implementation.
    1) alpha is stored in the alpha channel, so in my fullscreen shader, if i want to return a smooth value (0), nothing gets written for that pixel
    2) it seems the normal buffer gets completely messed up when trying to modify it.

    Yes, I am using DecodeFromNormalBuffer and EncodeToNormalBuffer to properly pack the values.
    As you can tell from the (very) messy screenshot attached, ive tried just about everything in the custom pass.

    Even just decoding the normal buffer and encoding it and returning that value, without modifying the data, completely messes up the normal. (see shader code attached)

    At this point i am about ready to completely give up on my idea, which sucks because according the the custom pass docs, i should be able to read/write the normal buffer in this custom pass injection point.

    @antoinel_unity I have looked at your custom pass examples, and see your writing to the normal buffer using DrawRendererList, however my use case is writing to it using a fullscreen shader. I think you are one of the only people who might be able to help me with this.

    Screenshot_3.png shader code.png
     
  2. camerondus

    camerondus

    Joined:
    Dec 15, 2018
    Posts:
    52
    Forgot to include a screenshot of the result:

    Screenshot_4.png
     
  3. antoinel_unity

    antoinel_unity

    Unity Technologies

    Joined:
    Jan 7, 2019
    Posts:
    262
    Hello,

    You can look at the HDRP custom pass repo, the last sample added modifies both normal and smoothness in a fullscreen pass to do a "wetness" effect:
    https://github.com/alelievr/HDRP-Custom-Passes#screen-space-wetness
    upload_2022-10-12_19-29-49.png

    There is also an example with ShaderGraph that shows how to write to the normal / smoothness in ShaderGraph with a SubGraph. (Note that the ShaderGraph example will only work with Unity 2022.2)
     
  4. camerondus

    camerondus

    Joined:
    Dec 15, 2018
    Posts:
    52
    CustomPassUtils.Copy is what I was missing. thanks!
     
    antoinel_unity likes this.
  5. camerondus

    camerondus

    Joined:
    Dec 15, 2018
    Posts:
    52
    @antoinel_unity is this bugged for 2021.3? in this video, im just setting the normaldata.perceptualroughness to 0 before encoding it back, using the same custom pass. Something is clearly wrong here, any ideas?
     
  6. camerondus

    camerondus

    Joined:
    Dec 15, 2018
    Posts:
    52
    just a note, this is without using shadergraph. this is with a regular fullscreen shader