Hi! I want to use indirect rendering (multidrawindirect) to draw everything as one and to reduce the number of shaders I use because now I use one shader for drawings arrays and another for drawing instanced arrays and this is quite heavy.
But I don’t know how to do in the vertex shader to test if the draw call is drawArrays or drawArraysInstanced. It tells in the opengl spec. that if that is not a draw instanced arrays, the value of gl_BaseInstance is 0 and the value of gl_InstanceID is also 0 but the value of the first instance and the first base instance is also 0 I guess so how to check if it’s the first instance or if it’s not an instanced draw call ? If I put 1 as base instance value to start at one and not at 0 in the vertex shader’ll it work or’ll it crash ? So if it’s an instance I substract 1 for gl_BaseInstance in the vertex shader. It’s because for drawing arrays I perform model matrix transfos on the CPU but for instanced I use a buffer and perform model transform on the GPU so I need to check it in the vertex shader if I have to perform a model transformation or not.
Why would you need to?
If your monolithic draw call can include instanced calls, then you need to take that into account when building and using the commands within that draw call. Essentially, all of them are instanced; it’s just some have an instance count of 1.
How you deal with that depends on how you get the vertex data for each individual drawing command. And there are several ways of doing that, so the answer will depend on how exactly you’re doing that.
EDIT : finally you’re right I can draw non instanced vertices with an instance count of 1 I know how I’ll proceed.
Worth noting that this is how Vulkan works - every draw call is an instanced draw call, but some of them just happen to only draw 1 instance.
Ok I don’t know vulkan a lot I’ve just followed the basic tutorial to port the basic renderer of my engine to vulkan but with openGL drawing with an instance count of 1 works well so I put the materials and models data into an SSBO and I get them with gl_DrawID (I’ve one draw call per material and primitive type) and I get the transformation matrix with gl_BaseInstance + gl_InstanceID.
Sorry, I should have been clearer. My point about Vulkan was just to show that this is going to be a supported fast path in the hardware.