Search Unity

Command Buffers on Lights

Discussion in 'General Graphics' started by boundingbox, Dec 13, 2015.

  1. boundingbox

    boundingbox

    Joined:
    Mar 31, 2013
    Posts:
    30
    Does anyone know how to use command buffers with lights, as in draw more meshes to the lights shadow map?

    I have a command buffer for the camera drawing models into the deferred GBuffers which is working properly for the most part but I don't know how to get them to cast shadows. I see that lights support command buffers but there is no documentation outlining how to use them. Even regular command buffers have a sad amount of documentation.

    My original plan was to use Graphics.DrawMesh but I see that was deprecated at some point.

    Code (csharp):
    1.  
    2. // Draws new meshes to the GBuffers
    3. RenderTargetIdentifier[] rti = {BuiltinRenderTextureType.GBuffer0, BuiltinRenderTextureType.GBuffer1, BuiltinRenderTextureType.GBuffer2, BuiltinRenderTextureType.GBuffer3, BuiltinRenderTextureType.Depth};
    4. commandBuffer.SetRenderTarget (rti, BuiltinRenderTextureType.CameraTarget);
    5.        
    6. // What should a light's render targets be?????
    7. commandBufferLight.SetRenderTarget (BuiltinRenderTextureType.Depth, BuiltinRenderTextureType.CameraTarget);
    8.  
     
  2. joelv

    joelv

    Unity Technologies

    Joined:
    Mar 20, 2015
    Posts:
    203
    Hi,

    If you don't set any render target the command buffer will render using the current active render target, which is the shadow map in the case of a light command buffer.

    For rendering a mesh you should use DrawMesh on the command buffer.

    Hope this helps.
     
  3. boundingbox

    boundingbox

    Joined:
    Mar 31, 2013
    Posts:
    30
    Thanks, this worked for spot lights but not for point lights or directional lights. I really only need it on the closest cascade of the directional light. There aren't any LightEvents to separate cascades or faces of a cube shadow map. Any thoughts?
     
  4. LemonMontage420

    LemonMontage420

    Joined:
    May 28, 2020
    Posts:
    56
    OP might not see this reply, but for anyone in the future who's got the same question, you can separate which shadowmap pass gets effected in the command buffer like so: https://docs.unity3d.com/ScriptReference/Rendering.ShadowMapPass.html