- Home /
Graphics.DrawMeshInstancedIndirect vs CommandBuffer.DrawMeshInstancedIndirect
i want to use commandbuffer instead of graphics.drawmeshInstancedIndirect. However when i render the instances it seems that commands add up to the camera (its the render target) and batches are increasing lowering the framerate
Answer by BastianUrbach · Sep 05, 2019 at 08:17 PM
I don't think you're supposed to do any of that every frame. A command buffer works kinda like a script: you create it once, add it to the camera and then leave it there (or remove it explicitly). So basically just do all of that in Start instead of Update. You can also clear it every frame and fill it with new commands if that's easier in your case but right now it seems like you're creating a new command buffer every frame without ever removing them.
For example, this works fine for me and paints the entire screen red every frame:
public class CommandBufferExample: MonoBehaviour { void Start() { var buffer = new CommandBuffer(); buffer.ClearRenderTarget(true, true, Color.red); GetComponent<Camera>().AddCommandBuffer(CameraEvent.AfterEverything, buffer); } }
Your answer
Follow this Question
Related Questions
Where to call Graphics.DrawMesh to successfully draw during editor pause? 0 Answers
DrawMesh (second override) causes runtime errors 0 Answers
Changing draw order of meshes in Graphics.DrawMesh() 1 Answer
Will Camera.RenderWithShader work with Graphics.DrawMesh (and DrawMeshInstanced)? 0 Answers
How to attach a mesh created with Graphics.DrawMesh to a GameObject? 1 Answer