Search Unity

Resolved CommandBuffer.DrawRenderer extravaganza

Discussion in 'General Graphics' started by elijad, Jun 10, 2021.

  1. elijad

    elijad

    Joined:
    Mar 19, 2020
    Posts:
    47
    Essentially, I'm trying to draw a few skinned meshes to an off-screen render texture. In update, I fill a command buffer with DrawRenderer commands for each mesh and then call Graphics.ExecuteCommandBuffer. And the result is a blank render texture.

    I still see the calls to drawMesh in the frame debugger, but nothing gets drawn. Neither with skinned or regular mesh renderers. RenderTarget also matches the texture I'm trying to render to and the material is just a built in standard with default settings aside from color.

    upload_2021-6-10_16-21-41.png

    Now, I would understand that it's just broken, BUT!

    It draws the renderers for the first three frames after I click play.

    If I don't clear the render texture, the meshes remain there. Here's the camera view and a rendertexture in the bottom left corner.

    upload_2021-6-10_16-28-41.png



    How do I know it renders for exactly three frames? I added a condition to a DrawRenderer command to only draw after Time.frameCount has reached a certain number. And the magic number turns out to be 3. I can still clear the render texture just fine after that but DrawRenderers produces nothing.
     
  2. elijad

    elijad

    Joined:
    Mar 19, 2020
    Posts:
    47
    After a few tests it seems to work when attached to a camera event, hovewer the aforementioned behaviour still makes no sense. Does Unity clear my RenderTexture automatically at the start of each frame? I don't see that in the frame debugger. Doesn't seem to be related to the animation loop since normal renderers also stop working.
     
  3. elijad

    elijad

    Joined:
    Mar 19, 2020
    Posts:
    47
    Neverming. I just realized I forgot to set view and projection matrices.