
[ad_1]
I began implementing instanced rendering in my 3D engine, however I shortly stumbled upon some points that I’m unsure whats the very best observe to work round.
When I setup my scene, I seize the quantity of cases for each mesh and I write the transformation matrices first right into a dynamic checklist and at last into an “occasion buffer” (UBO) which is distributed to the shaders and listed by gl_InstanceID
to fetch the proper rework. This is working completely.
So after I apply frustum culling per occasion, what I do now’s that when I discovered that an occasion must be culled, I take away this transformation matrix from the dynamic checklist and due to this fact I hold the transformation matrices of simply the lively cases which find yourself getting drawn from the glDrawElementsInstanced
.
Obviously inserting and eradicating parts from this dynamic checklist is dear and I wish to eliminate it. So I used to be considering that I’ll implement a set size checklist this time consisting of per-instance structs to carry occasion knowledge one thing like this:
struct InstanceData {
float worldMatrix[16];
bool isOccluded;
/* and extra */
};
However this results in one other downside. In this case, for the reason that draw name will render a set quantity of cases on a regular basis, regardless if they’re seen or not, I’ll need to discard the vertices within the shader, and I do not suppose that that is optimum both.
I’ve considered different methods as properly, resembling sorting the cases primarily based on their occlusion standing on each body, however then I’ll need to pay the worth for the sorting.
Is there any frequent observe to cope with instanced knowledge? I worry that I ought to experiment with all of the choices and discover what fits me finest x.x
Thanks prematurely
[ad_2]