Search Unity

Custom RP. Correctly perform depth prepass with additional data.

Discussion in 'General Graphics' started by RegdayNull, Jul 22, 2019.

  1. RegdayNull

    RegdayNull

    Joined:
    Sep 28, 2015
    Posts:
    68
    I am trying to implement real depth prepass with additional data (like in Doom 2016) with correct hardware depth. Reason is early z optimization where main rendering queue get rendered with depth test flag set to Equals. Without any custom RT on depth prepass stage it works like a charm.

    But for decals I need to render normals in depth-prepass shader. And after some test I am trying to bind custom render target (with depth param = 0) like that:
    Code (CSharp):
    1. commandBuffer.SetRenderTarget(normalsRenderTarget, BuiltinRenderTextureType.CameraTarget);
    And on OpenGL works ok. But on DX11 z-buffer is flipped on Y axis (only in game view, in editor is ok). And on Vulkan depth does not fit at all.

    Any other things, like configuring render target with depth 8, 16, 32 or just setting it like single RenderTarget does not write in hardware depth at all.

    So there is the question. How to properly render into hardware depth and into RenderTexture simultaneously and correctly on all platforms.
     
  2. RegdayNull

    RegdayNull

    Joined:
    Sep 28, 2015
    Posts:
    68
    Is it question unclear or it's impossible to do?
     
  3. RegdayNull

    RegdayNull

    Joined:
    Sep 28, 2015
    Posts:
    68
    Nice support of production ready package.
     
  4. RegdayNull

    RegdayNull

    Joined:
    Sep 28, 2015
    Posts:
    68
    Taken from teh documentation.
    "When rendering into a Texture on a Direct3D-like platform, Unity internally flips rendering upside down. This makes the conventions match between platforms, with the OpenGL-like platform convention the standard."

    So how to prevent Unity to do that? It is not conventional behaviour, it is inconsistent behaviour, because it's does not work in Unity editor window and broking early-z.
     
  5. RegdayNull

    RegdayNull

    Joined:
    Sep 28, 2015
    Posts:
    68
    Okay, let's assume that is multiplying SV_POSITION y component by _ProjectionParams.x, and setting Cull to off is a good idea. But there is editor window, where after that hack all meshes are going mad and rotating left and right. Is Unity all about dirty hacks and bugs?