I've made a simple billboard gpu instancing vertex shader that manipulates the verticies of an object based on the projection matrix. The problem is that the renderer bounds does not update to encapsulate the object. If the objects render bounds goes out of view the objects dissapears because of frustrum culling, is there a way to recalculate the render bounds after manipulating the verticies or manually manipulate the bounds to be the maximum size that the object that be.


You can't recalculate the bounds in the vertex shader itself (culling happens before we've even decided to send those vertices to the GPU), but we can manually set the bounds in a C# script:

// Note: this copies the mesh, to avoid changes rippling out and affecting
// all instances of it, including the asset in your project folder.
// If you're sure you already have a unique mesh, you can use .sharedMesh
// to avoid creating a copy.
Mesh mesh = GetComponent<MeshFilter>().mesh;
mesh.bounds = new Bounds(center, size);

As you say, if you set up these bounds to encapsulate the maximum volume any of your vertices might occupy, then it won't be frustum culled as long as any part of that zone is within the camera's frustum.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.