Search Unity

Recreating a mesh in the scene in a custom pass using a depth/normal texture

Discussion in 'General Graphics' started by SkiesOfArcadia, Mar 25, 2021.

  1. SkiesOfArcadia

    SkiesOfArcadia

    Joined:
    Nov 27, 2017
    Posts:
    2
    Hi,

    I have drawn a mesh and have a texture containing its depth information, and another texture containing worldspace normals.

    I'm now trying to recreate the mesh in the scene using this data.
    Essentially I want to display the mesh using a HDRP lit shader with a material that has textures set up.

    Is this possible?

    This is what I've done so far
    - Create a custom pass that injects in at the pre-transparent
    - Render a quad to the screen with a duplicate of the HDRP/Lit shader
    - In the duplicate, I've edited the forward pass, so it reads my depth and normal. I've overwritten where I think it should be overwritten.
    - Clip where the depth test fails (the depth in my depth texture vs the scene depth)

    It sorta works. The texture mapping looks off though. I dont have tangent data so this may be the issue? Will I need that.

    Is what I'm suggesting possible?
    Alternatives I've though of are to somehow render into the GBuffer with this information.
    I need this mesh to cast/receive shadows etc. It basically should look like a mesh that could be rendered in the scene with a HDRP/lit material in either opaque or transparent.