Search Unity

Resolved Optional fragment stage in Unity?

Discussion in 'General Graphics' started by Baggers_, Jun 12, 2020.

  1. Baggers_

    Baggers_

    Joined:
    Sep 10, 2017
    Posts:
    98
    [EDIT] This was totally the wrong question. See below aleksandrk's reply for something hopefully more on track

    Before using Unity I had previously done some experiements with gpu occlusion culling and one optimization used for one pass was to disable the rasterizer whilst keeping depth write enable in order to only render to the depth texture. In GL this was done using
    glEnable(GL_RASTERIZER_DISCARD)
    . I've seen that something similar exists in DirectX.

    Is it possible to do this in Unity without using SRP? Its not the end of the world if I cant but it is a good optimization.
     
    Last edited: Jun 19, 2020
  2. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    I'm not sure how it would write to the depth texture without rasterisation.
    Are you perhaps looking to disable color writes?
     
  3. Baggers_

    Baggers_

    Joined:
    Sep 10, 2017
    Posts:
    98
    Thanks @aleksandrk, I completely misremembered, what I should have been asking about is if unity has an equivalent to GL in how it allows you not to specify a fragment stage, in which case it only writes to depth and stencil.
    Disabling color writes might be what I'm after then, I'm not sure whether is this equivalent.

    I must have transform feedback on the brain. Sorry for the confusion
     
  4. Baggers_

    Baggers_

    Joined:
    Sep 10, 2017
    Posts:
    98
    I'm guessing disabling color writes is done using
    ColorMask
    . Any info you can provide on what that does behind the scenes would be very welcome
     
  5. aleksandrk

    aleksandrk

    Unity Technologies

    Joined:
    Jul 3, 2017
    Posts:
    3,014
    Precisely.
    For GL it calls glColorMask/glColorMaski, depending on your render target setup :)

    No, this is not allowed in Unity - I don't think all platforms support this.
     
  6. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,342
    I often use this function:
    Code (csharp):
    1. void frag() {}
    On Nvidia GPUs and some mobile GPUs this works just like having no fragment shader stage!

    But on AMD GPUs you get black, and some mobile GPUs you get random noise.

    TLDR: use
    ColorMask 0
    .
     
  7. Baggers_

    Baggers_

    Joined:
    Sep 10, 2017
    Posts:
    98
  8. ArminRigo

    ArminRigo

    Joined:
    May 19, 2017
    Posts:
    20
    Sorry for the necro post. Unless I'm missing something, a fast way to completely skip running the fragment shader is to emit a constant like `float4(0, 0, 0, -1)` from the vertex shader as SV_POSITION.

    (EDIT: avoid 0, 0, 0, 1 and return anything with w < 0, which should cleanly clip out)
     
    Last edited: Feb 13, 2024
  9. Baggers_

    Baggers_

    Joined:
    Sep 10, 2017
    Posts:
    98
    Please don't necro posts like this. If you have questions about the behavior of the vertex shader please start a new thread.
    To partially answer your question, no your suggestion is not equivalent to the answer above and wouldn't solve the original questions.