MCPcopy Create free account
hub / github.com/TheRealMJP/DeferredTexturing / CullMeshesAndSort

Function CullMeshesAndSort

BindlessDeferred/MeshRenderer.cpp:70–96  ·  view source on GitHub ↗

Frustum culls meshes, and produces a buffer of visible mesh indices. Also sorts the indices by depth.

Source from the content-addressed store, hash-verified

68
69// Frustum culls meshes, and produces a buffer of visible mesh indices. Also sorts the indices by depth.
70static 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
99static uint64 CullMeshesOrthographic(const OrthographicCamera& camera, bool ignoreNearZ, const Array<DirectX::BoundingBox>& boundingBoxes, Array<uint32>& drawIndices)

Callers 3

RenderMainPassMethod · 0.85
RenderGBufferMethod · 0.85
RenderDepthPrepassMethod · 0.85

Calls 6

Float3Class · 0.85
OrientationMethod · 0.80
ToSIMDMethod · 0.45
TransformMethod · 0.45
SizeMethod · 0.45
DataMethod · 0.45

Tested by

no test coverage detected