Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

GL.invertCulling equivalent for HDRP

Discussion in 'High Definition Render Pipeline' started by kamkolak, Jun 4, 2020.

  1. kamkolak

    kamkolak

    Joined:
    Nov 15, 2019
    Posts:
    4
    As in the title - I'm looking for the equivalent of GL.invertCulling in HDRP. Rendering to cubemap that I'm doing is outputting image flipped in Y axis, so I have to somehow flip it back. Reversing Y axis in projection matrix has a side effect of inverting face culling too, so only backfaces are rendered.

    Maybe I'm approaching the solution wrong - if there is an easier way to do an Y-axis flip without modifying the shader, I'd really like to know it too.
     
  2. kamkolak

    kamkolak

    Joined:
    Nov 15, 2019
    Posts:
    4
    I was able to find a partial solution that works for me, but doesn't completely solve the problem. It will cull front instead of back faces, but it won't actually reverse the culling completely (so shaders culling front faces by default will not flip to backface culling).

    In case anyone ever stumbles upon this thread, here's the solution:

    ScriptableRenderContext.DrawRenderers accepts an overload with RenderStateBlock struct as a parameter. To render everything with front face culling, just define it as this:

    Code (CSharp):
    1. // ...
    2. var stateBlock = new RenderStateBlock(RenderStateMask.Raster)
    3. {
    4.     rasterState = new RasterState
    5.     {
    6.         cullingMode = CullMode.Front
    7.     }
    8. };
    9. context.DrawRenderers(cull, ref drawing, ref filter, ref stateBlock);