In my scene I have a huge numbers of objects.
I would like to group them in an optimal way in order to call less drawCalls as possible.
Grouping for me means put the vertices and other vertex properties of different objects in the same big VBO.
Of course this group of geometry has the same vertex attributes.
I was thinking to group them if they share the same shader program.
Lets make an example.
Suppose I have two objects with their own geometry, they use the same shader program but they differ in the material properties.
For material I mean the parameters that my shader can use as input such as shiness, color ecc.
The first object uses material1, the second one uses material2 and a different model matrix as well.
If I put them in the same VBO I can link once my shader program and call once a drawCall and I think this will be the best that I can obtain in order to reduce drawCalls.
Now my problems are (with the solutions that I was planning to implement):
- In my vertex shader, as usual, I have as uniform matrix the model, the view and the projection. Each of my two objects have a different model matrix but since they are in the same VBO I can set once the uniform for the model matrix before the drawCall.
- Solution 1: use a uniform array in which I will put the different model matrices, then my objects will have as vertex attribute a personal ID that I will use to find the correct model matrix in the array. But this requires me to pass all the model matrices in a big uniform array.
- Solution 2: apply on cpu the model matrix transformation to the vertices (I have already tried this solution for animation… Of course on cpu is really slow)
- In my fragment shader I have a uniform struct for the material which defines the shiness and so on. Again, each of my two objects have different material properties.
- Solution: use also here a uniform array for the materials and access it using the ID.
This solution is inspired from the discussion here in the forum.
I would like to understand if this solution is a valid alternative in order to reduce drawCalls and have bigger VBO (with more vertices and other properties).
Any suggestions/ideas are really appreciated!