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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

DrawProcedural and DepthBuffer Effects

Discussion in 'Image Effects' started by trek7, Feb 6, 2017.

  1. trek7

    trek7

    Joined:
    Feb 8, 2015
    Posts:
    4
    Hi there.

    I am generating a lot of particles in a compute shader and I want to apply Screen Space Ambient Occlusion with an Image Effect Script.
    Am I right, that with DrawProcedural nothing is written into the Depthbuffer? So the SSAO shader is not working! I also tried to enable ZWrite, but this had no effect. I also couldn't find an DepthBuffer Image in the Frame Debugger.
    I found out, that since Unity 5.1 there is a new functionality, called CommandBuffers. Could they help me somehow to get the particles also rendered into the DepthBuffer, that I can use it to do some Image Effects like SSAO?
    If yes, could you tell me in a few steps how to do it?

    Thank you in advance!

    Tarek
     
  2. trek7

    trek7

    Joined:
    Feb 8, 2015
    Posts:
    4
    I already tried this, but I just get a blank screen.

    Code (CSharp):
    1.  
    2. CommandBuffer commandBuffer = new CommandBuffer();
    3. Camera cam = this.GetComponent<Camera>();
    4.  
    5. // pseudo
    6. CommandBuffer argsBuffer =  { 6, 1000, 0, 0 }
    7.  
    8. void OnRenderObject()
    9. {
    10.         //material.SetPass(0);
    11.         //Graphics.DrawProcedural(MeshTopology.Triangles, 6, particleCount);
    12.  
    13.         commandBuffer.Clear();
    14.    
    15.         commandBuffer.DrawProceduralIndirect(Matrix4x4.identity, material, 0, MeshTopology.Triangles, argsBuffer);
    16.         cam.AddCommandBuffer(CameraEvent.BeforeDepthTexture, commandBuffer);
    17. }
    If I put it later in the rendering pipeline, I see all the particles, but that doesn't help me, because I want to draw into the depthbuffer.
     
    Last edited: Feb 7, 2017