Frustum culls meshes, and produces a buffer of visible mesh indices. Also sorts the indices by depth.
| 68 | |
| 69 | // Frustum culls meshes, and produces a buffer of visible mesh indices. Also sorts the indices by depth. |
| 70 | static uint64 CullMeshesAndSort(const Camera& camera, const Array<DirectX::BoundingBox>& boundingBoxes, |
| 71 | Array<float>& meshDepths, Array<uint32>& drawIndices) |
| 72 | { |
| 73 | DirectX::BoundingFrustum frustum(camera.ProjectionMatrix().ToSIMD()); |
| 74 | frustum.Transform(frustum, 1.0f, camera.Orientation().ToSIMD(), camera.Position().ToSIMD()); |
| 75 | |
| 76 | Float4x4 viewMatrix = camera.ViewMatrix(); |
| 77 | |
| 78 | uint64 numVisible = 0; |
| 79 | const uint64 numMeshes = boundingBoxes.Size(); |
| 80 | for(uint64 i = 0; i < numMeshes; ++i) |
| 81 | { |
| 82 | if(frustum.Intersects(boundingBoxes[i])) |
| 83 | { |
| 84 | meshDepths[i] = Float3::Transform(Float3(boundingBoxes[i].Center), viewMatrix).z; |
| 85 | drawIndices[numVisible++] = uint32(i); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | if(numVisible > 0) |
| 90 | { |
| 91 | ZSortComparer comparer(meshDepths); |
| 92 | std::sort(drawIndices.Data(), drawIndices.Data() + numVisible, comparer); |
| 93 | } |
| 94 | |
| 95 | return numVisible; |
| 96 | } |
| 97 | |
| 98 | // Frustum culls meshes for an orthographic projection, and produces a buffer of visible mesh indices |
| 99 | static uint64 CullMeshesOrthographic(const OrthographicCamera& camera, bool ignoreNearZ, const Array<DirectX::BoundingBox>& boundingBoxes, Array<uint32>& drawIndices) |