We really could use an “instance shader” for rendering massive amounts of objects like vegetation and controlling the culling on the GPU. It really doesn’t make sense to perform this step on the CPU when the number of instances is in the thousands. For example, our vegetation system renders a randomized grid of instances around the player. An instance shader could quickly decide which objects in the grid are actually visible, and discard the instance before the vertex shader if it isn’t visible.
uniform vec4 cameraplane0;
uniform vec4 cameraplane1;
uniform vec4 cameraplane2;
uniform vec4 cameraplane3;
uniform vec4 cameraplane4;
uniform vec4 cameraplane5;
uniform objectradius;
uniform instancematrix[MAX_INSTANCES]
bool PlaneDistanceToSphere(in vec4 plane in vec3 point, in float radius) {}
main ()
{
mat4 mat = instancematrix[gl_InstanceID];
vec3 pos = mat[3].xyz;
float radius = objectradius * max(max(mat[0].length(),max[1].length),mat[2].length);
if (PlaneDistanceToSphere(cameraplane0,position,radius) > 0.0) discard;
}
This would save time on vertex shaders, which are not free when you get high volumes of geometry, and it would save the CPU from having to iterate through each instance.
I tried doing something like this with geometry shaders, but the hardware limitations are ridiculously low and you’re also performing culling for every single vertex, which is really non-optimal.