Search Unity

Raymarching in HDRP: Custom post-process vs. custom render pass?

Discussion in 'High Definition Render Pipeline' started by beaugunderson, Sep 11, 2020.

  1. beaugunderson

    beaugunderson

    Joined:
    Sep 3, 2020
    Posts:
    7
    Hi there--I'm pretty new to Unity and trying to port some code I had that worked with Post-Processing 2.0 to HDRP.

    I'm a little confused as to when to use an HDRP custom post-process vs. an HDRP custom render pass.

    Which is more correct for rendering objects defined completely in a shader, e.g. to render signed distance fields using raymarching?
     
  2. beaugunderson

    beaugunderson

    Joined:
    Sep 3, 2020
    Posts:
    7
    Well, after trying trying hundreds of combinations of parameters to generate world-space rays in a custom post-process volume I gave up and decided to try a custom render pass--within about 5 minutes I had it working. Will update here when I write up the process.
     
  3. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi @beaugunderson,
    ScreenSpaceReflections.compute has code snippets where you see how to get world space position and view direction if I remember correctly.

    These should be enough to construct a a world position and a ray direction for raymarching.
     
    beaugunderson likes this.
  4. beaugunderson

    beaugunderson

    Joined:
    Sep 3, 2020
    Posts:
    7
    Thanks @Olmi; that's a great pointer. I have the view direction calculation just fine in an HDRP custom pass but no amount of messing with the math allowed me to get it working correctly in an HDRP custom post-process. I think using the custom pass is fine for my needs, though, but I'm still interested in pros/cons of the two approaches for adding raymarched objects.
     
  5. beaugunderson

    beaugunderson

    Joined:
    Sep 3, 2020
    Posts:
    7
  6. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    I've made a simple raymarcher sometime last year, I made it as custom post processing effect.I don't think there should be much difference, it's mosty depending on having the correct data I think. I wonder what you did wrong.
     
  7. beaugunderson

    beaugunderson

    Joined:
    Sep 3, 2020
    Posts:
    7
    @Olmi did you do it as a Post-Processing V2 post processing effect or as an HDRP custom post-processing effect? I had mine working in the Post-Processing V2 framework but that does not work with HDRP as far as I know.
     
  8. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    HDRP custom post-processing of course, as this was a HDRP thread?
     
  9. beaugunderson

    beaugunderson

    Joined:
    Sep 3, 2020
    Posts:
    7
    Well, as a Unity noob the similar names are a bit confusing so I just wanted to make sure. :)
     
  10. pasxoshorp13

    pasxoshorp13

    Joined:
    Dec 11, 2018
    Posts:
    2
    Did you manage to port fullscreen raymarching to HDRP?
     
  11. naive_magic

    naive_magic

    Joined:
    Jun 5, 2020
    Posts:
    7
    bump
     
  12. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    Hi @naive_magic,

    May I ask what you are trying to do with your 'bump', which adds nothing of value to this thread? Are you trying to ask in a roundabout way if someone could provide a ready-made solution for you, or what?
     
  13. naive_magic

    naive_magic

    Joined:
    Jun 5, 2020
    Posts:
    7
    Hey Olmi, thank you kindly for your answer. Yes the bump was indeed there to shed some light on writing custom raymarched shaders for latest version of HDRP, which after spending time searching on Twitter, Github, Unity Forums, google, duckduckgo and yandex appears to be some sort of an alchemical mystery. It's not asking for roundabout but perhaps more for an answer to an unresolved call for information.. that's what forums are for - sharing and seeking out knowledge?
     
    ModLunar and Gasimo like this.
  14. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    @naive_magic Writing a raymarcher effect for HDRP custom post processing really doesn't differ from other types of post effects. What you need is already available, if you just search for it. What you need is a basic effect template as an entry point and you can find done here:
    https://docs.unity3d.com/Packages/c...efinition@7.1/manual/Custom-Post-Process.html

    Then, you need world space position of any pixel which is much easier to get than with built-in pipeline, as a pre-made methods etc. already exist for it, see the already mentioned ScreenSpaceReflections.compute.

    Next you need you need a camera world position, which you can easily pass into the shader from C# side in the post processing effect.

    You can calculate your world ray from world space position of a pixel and your camera world space position.
    Your ray origin is the camera world space position. This should be enough to get a basic raymarcher up and running.
     
    naive_magic likes this.
  15. JG-Denver

    JG-Denver

    Joined:
    Jan 4, 2013
    Posts:
    77
    @beaugunderson did you forward what you learned to Kevin Watters? I would love to see an HDRP version of that toolkit as well.
     
  16. Untitled_Tools_Projects

    Untitled_Tools_Projects

    Joined:
    Nov 9, 2016
    Posts:
    10
    How in the world do you accurately get the depth for culling?