Search Unity

Question URP, ShaderGraph, RenderTextures, and XR Stereo Rendering

Discussion in 'Universal Render Pipeline' started by Jonathan_L, Jun 6, 2020.

  1. Jonathan_L

    Jonathan_L

    Joined:
    Jan 26, 2016
    Posts:
    43
    Hi, I am trying to re-create this outline effect using ShaderGraph in URP. The reference link I posted below is supposedly taken from how Unity performs outlines for selected objects in the scene editor. I am familiar with ShaderGraph but slightly unfamiliar with things like cginc and multiple passes etc so I am trying my best to learn as much as I can so I can make something like this work in URP.

    https://github.com/michaelcurtiss/UnityOutlineFX/tree/master/UnityOutlineFX

    Also on top of that, I am working with the Single Pass Instanced Rendering (Stereo Rendering) under VR and I feel like this might complicate things. Really I was wondering if anybody could guide me in a generate direction on how one might do this step by step. Any type of information or guidance would be greatly appreciated. I am finding sources all over the place but I'm not even sure if what I am looking at will help.

    For example, this is documentation on Single Pass Instance rendering (https://docs.unity3d.com/Manual/SinglePassStereoRendering.html) but I'm not sure how to even approach something like this using ShaderGraph.

    Also I feel like rendering to a render texture might help with this but I don't know how to approach that with XR stereo rendering.

    Anyway, thanks in advance. I'll try my best to wrap my head around all of this and post here if I come up with some understanding of it all.
     
  2. Jonathan_L

    Jonathan_L

    Joined:
    Jan 26, 2016
    Posts:
    43
    So i looked into this a bit and think I have an approach for this. Instead of looking at the github project I made in the first post, I'll look at what's done here:

    https://github.com/alelievr/HDRP-Cu...ection/Shaders/02_Selection_Fullscreen.shader

    upload_2020-6-8_0-55-11.png

    This uses custom pass options that are available in HDRP. I'm not sure if custom passes are available in URP but this can be done using ScriptableRenderPass.

    So my approach is to
    1) Create a render feature pass where I render objects that I want to outline as white. I'll also store depth in this texture so I can do an effect like shown above or maybe render outlines underneath objects as a different color.
    2) Create another render feature pass that samples the depth mask texture I made in step #1. I'll make a shader that renders pixels nearby white pixels the color of the outline
    3) In the same shader, compare depth in the texture with depth in the scene (using _CameraDepthTexture) and if the depth is greater, then render that part of the outline with an alpha of 0.5 or something.

    I'm having issues with the depth values and I made another post on it here:
    https://forum.unity.com/threads/urp-render-feature-depth-mask-and-_cameradepthtexture.907424/

    And as far as the Single Pass Instance stereo rendering goes, I found that there are a few changes I can make to shader code to work with XR.

    - Instead of declaring texture with TEXTURE2D(_myTexture) you call TEXTURE2D_X(_myTexture)
    - Instead of sampling with SAMPLE_TEXTURE2D, use SAMPLE_TEXTURE2D_X
    - When sampling textures, wrap UVs with the method UnityStereoTransformScreenSpaceTex(UV)

    I found this by creating shaders in shadergraph and then right clicking nodes to "Show Generated Code" and then following what the built-in unity methods do.

    Hopefully this helps anyone with similar issues