Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Can you write to a UAV RenderTexture during regular rendering?

Discussion in 'Shaders' started by Arycama, Jan 5, 2020.

  1. Arycama

    Arycama

    Joined:
    May 25, 2014
    Posts:
    183
    I am attempting to write to a UAV Texture during terrain rendering.
    I have tried creating a CommandBuffer to execute before ForwardOpaque rendering, and setting the RandomWrite target.

    However, debugging with RenderDoc shows that no UAV is assigned when the shader is rendered.

    Is this simply not possible to do with the built in rendering pipeline?
    I have seen other forum posts on the subject, but most seem to deal with compute buffers and manually rendering using Graphics.DrawMesh, Graphics.Blit or similar.

    I want to do this during a regular rendering pass so I am not doubling up on draw calls/number of vertices being rendered.

    This is the code used in the shader:
    Code (CSharp):
    1. uniform RWTexture2D<float4> _VirtualFeedbackTexture : register(u1);
    2.  
    3. // In the pixel shader
    4. _VirtualFeedbackTexture[coord] = result

    The relevant C# code is below:

    Code (CSharp):
    1. feedbackTexture = new RenderTexture(width, height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear)
    2. {
    3.     name = "VirtualFeedbackTexture",
    4.     filterMode = FilterMode.Point,
    5.     enableRandomWrite = true
    6. };
    7.  
    8. feedbackTexture.Create();
    9.  
    10. var commandBuffer = new CommandBuffer();
    11. commandBuffer.SetGlobalTexture("_VirtualFeedbackTexture", feedbackTexture);
    12. commandBuffer.SetRandomWriteTarget(1, feedbackTexture);
    13. camera.AddCommandBuffer(CameraEvent.BeforeForwardOpaque, commandBuffer);