Hi, I’m currently porting an Image Based Render algorithm written in OpenGL to Unity.
I was able to port the shaders and the basic logic but I get less FPS than the original version.
I think one of the main reasons is because of the draw calls. I can get easily more than 7.5K batches.
What i’m doing is basically the following:
- Within OnPostRender() I run a sequence of shaders that write to some render textures. Each shader draws/provides an input texture for the next one and the last one copies the final result to the main camera as target.
- Some of the shaders work similar to image effects (I draw a full quad and do some pixel processing) and others do some processing by drawing a set of meshes.
- For the steps/shaders that need to draw geometries, I draw them within a loop by calling DrawMeshNow (after of course setting the right render target, loading the right transformation matrices, setting the per mesh material’s values and enabling the material with SetPass).
I have the call to material.SetPass() within the for loop after calling material.SetValueType with the right per-mesh data. I noticed that I was not getting the right per-mesh data when calling SetPass before entering this loop.
I was reading about the other alternatives to make draw calls and this is what I understand so far.
- Graphics.DrawProcedural[Indirect]: it’s not going to work because it’s made for procedural geometry (and not actual meshes).
- Graphics.DrawMeshInstanced[Indirect]: it focuses on rendering the same mesh more than once. I’m not interested in drawing the same mesh more than one within one of my steps.
- Graphics.DrawMesh: it seems that allows to pass per-mesh data to the material by using the materialPropertyBlock and it batches the draw call (not sure about this) and also I don’t know when exactly the mesh is drawn (I need it done before the next shader run in the OnPostRender method). I have also read that is the slowest way to draw a mesh. And apart of all of that, it doesn’t seem to work within my pipeline when I replace DrawMeshNow call by DrawMesh.
The original code in OpenGL uses the function glMultiDrawElementsIndirect that allows you to batch draw commands of different meshes and then execute just one draw call to render everything. How can I get the same functionality in Unity?