Search Unity

Question URP RendererFeatures and stereo cameras

Discussion in 'VR' started by Dustyroom, May 28, 2021.

  1. Dustyroom

    Dustyroom

    Joined:
    Sep 23, 2015
    Posts:
    108
    Hi all,

    I'm trying to adapt our fog and outline image effects to work in VR, but so far it's been just shooting in the dark.

    The image effects are implemented as RendererFeature with a `ScrptableRenderPass`. Both fog and the outline effects use the opaque and depth maps in the HLSL shaders. Both effects work in the multi-pass VR mode, but give incorrect results in the single-pass mode.

    I've looked at other URP's RendererFeatures - the SSAO and post-processing, but couldn't reverse engineer what's going on there with the XR stereo cameras support.

    Is there any documentation how to handle the stereo rendering with RendererFeature? Any help is greatly appreciated.
     
  2. ThomasZeng

    ThomasZeng

    Unity Technologies

    Joined:
    Jun 24, 2019
    Posts:
    86
    Hello @Dustyroom,

    Thanks for reaching out! I would try to share some info from top of my head :) Hope it helps.

    For doing screen space pass I would recommend checking out SSAO in URP for reference:
    Here is the SSAO shader:
    https://github.com/Unity-Technologi...ders/Utils/ScreenSpaceAmbientOcclusion.shader
    And here is the SSAO c# side for drawing fullscreen quad:
    https://github.com/Unity-Technologi...rFeatures/ScreenSpaceAmbientOcclusion.cs#L341

    For using opaque and depth maps in shaders I would recommend checking out these files, they provide some utility functions to sample depth/color.
    https://github.com/Unity-Technologi...versal/ShaderLibrary/DeclareDepthTexture.hlsl
    https://github.com/Unity-Technologi...ersal/ShaderLibrary/DeclareOpaqueTexture.hlsl

    And here is a doc about some usage of sampling depth that could potential be useful:
    https://github.com/Unity-Technologi...ing-shaders-urp-reconstruct-world-position.md

    Regards,
    Thomas
     
    rz_0lento and Dustyroom like this.
  3. Dustyroom

    Dustyroom

    Joined:
    Sep 23, 2015
    Posts:
    108
    Thank you Thomas,

    Is there a reason the temporary buffers are rendered as a fullscreen quad as opposed to using
    commandBuffer.Blit()
    ?
     
  4. Dustyroom

    Dustyroom

    Joined:
    Sep 23, 2015
    Posts:
    108
    Another question, is world position reconstruction needed for image-space depth/normal-based edge detection in single-pass stereo? Can I sample the depth texture using
    SampleSceneDepth()
    or do I need this code as well?
     
  5. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    Thanks for the references but I really feel like Unity should provide some bare bones examples for these instead of making the users decipher larger built-in URP effects. Would be a lot nicer to get example on how to make some naive effect using RendererFeatures that works in URP VR with SPI, for example simple desaturation example would be fine.

    A good example is how HDRP custom PP does this on their docs, they provide a simple snippet that works and gives entry point for users digging into these things:
    https://docs.unity3d.com/Packages/c...finition@12.0/manual/Custom-Post-Process.html

    Making everyone go through the hard way is bit silly IMHO especially considering how huge painpoint URP VR is for everyone doing custom effects atm. Just look at the Asset Store where practically no 3rd party asset currently works in URP VR using recent URP versions. Simple examples go a long way in cases like these.
     
    Last edited: Jul 29, 2021
  6. Dustyroom

    Dustyroom

    Joined:
    Sep 23, 2015
    Posts:
    108
    I agree. Alternatively to adding a new sample, Unity can at least update this one (which doesn't work with single-pass XR): https://github.com/Unity-Technologies/UniversalRenderingExamples.
     
  7. mutp

    mutp

    Joined:
    Oct 1, 2018
    Posts:
    79
    +1. We're really unable to do any URP SPI work with VR when it comes to image effects. Really need an example for us to understand this better.
     
    ChristopherKerr and moatdd like this.
  8. ThomasZeng

    ThomasZeng

    Unity Technologies

    Joined:
    Jun 24, 2019
    Posts:
    86
    Hi @rz_0lento ,

    Thanks for the suggestion. I completely agree this area is lacking at the moment. Will discuss with the doc team to improve this area.
     
  9. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
    I put together a simple saturation effect made with URP Renderer Feature:
    https://github.com/0lento/URP_RendererFeature_SPI_Example

    Tested with both SPI + Multipass on MockHDM, OculusXR and OpenXR.

    Do ignore the console error spam while using MockHMD, it's not related to this project but to MockHMD issue with new Input System (https://forum.unity.com/threads/att...eature-type-id-1-while-using-mockhmd.1021825/)

    Edit: Updated the repo to have separate commits for old cmd.Blit and cmd.DrawMesh approaches so you can see what needs to change from the commit diff. Added also extra branch where I put similar RT handling as what Unity does on SSAO, wanted to keep this separate as it makes the overall change look bit more complicated than what it is.
     
    Last edited: Aug 17, 2021
  10. rz_0lento

    rz_0lento

    Joined:
    Oct 8, 2013
    Posts:
    2,361
  11. jamie_xr

    jamie_xr

    Joined:
    Feb 28, 2020
    Posts:
    67
  12. morepixels

    morepixels

    Joined:
    May 21, 2014
    Posts:
    18
    @Tomas the approach described in "How to perform a full screen blit in Single Pass Instanced rendering in XR" doesn't work in the latest URP. The effect is not applied and an error is shown in the console: `You can only call cameraColorTarget inside the scope of a ScriptableRenderPass. Otherwise the pipeline camera target texture might have not been created or might have already been disposed.`

    Can you please update the instructions?
     
    Last edited: Feb 3, 2022
    pierre92nicot and nasos_333 like this.
  13. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,362
    Second that, a working example would help a lot