Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Zbuffer UV Flipped Problem

Discussion in 'Graphics Experimental Previews' started by GuardHei, Oct 5, 2019.

  1. GuardHei

    GuardHei

    Joined:
    Feb 10, 2018
    Posts:
    89
    Hi guys, I am currently working on a scriptable render pipeline project. I want to do a depth pre-pass, which I render the depth of the objects in the scene to a depth texture first, and then use that texture in the opaque objects render process. However, it seems that the depth texture has a vertically UV flip problem.


    The code I use to create the depth texture is this:
    Code (CSharp):
    1. _currentBuffer.GetTemporaryRT(ShaderManager.OPAQUE_DEPTH_TEXTURE, pixelWidth, pixelHeight, 24, FilterMode.Point, RenderTextureFormat.Depth);
    And the code I use to bind the depth texture when rendering the normal opaque objects is this:
    Code (CSharp):
    1. // Setup Camera
    2. context.SetupCameraProperties(camera);
    3.  
    4. // Bind screen output to color buffer, bind the previous depth pre-pass to depth buffer
    5. ResetRenderTarget(BuiltinRenderTextureType.CurrentActive, _opaqueDepthId, false, true, 0, Color.black);
    6.  
    7. // Implementation of ResetRenderTarget
    8. private void ResetRenderTarget(RenderTargetIdentifier colorBuffer, RenderTargetIdentifier depthBuffer, bool clearDepth, bool clearColor, float depth, Color color) {
    9.     _currentBuffer.SetRenderTarget(colorBuffer, depthBuffer);
    10.     _currentBuffer.ClearRenderTarget(clearDepth, clearColor, color, depth);
    11. }
    I am not sure what causes this problem -- probably the auto uv flip of the rendertexture? How can I solve this problem?
    My current idea is to add another pass to flip the depth texture after the depth pre-pass. But that introduces an extra cost.
    By the way, is there a way for me to bind the color buffer to the screen output without using "context.SetupCameraProperties(camera);"?