The Occlusion Culling SDK provides a high-performance software occlusion culling solution. That is, objects can be occluded on the CPU to offload the rendering workload on the GPU and improve the overall rendering performance.
To use the Occlusion Culling plug-in, you need to:
In this codelab, you will use the demo project to call the Occlusion Culling SDK APIs. Through this demo project, you will:
Initialize a HiCulling object before calling the Occlusion Culling APIs.
HiCulling *obj = HcCreate(true);
Call HcSetResolution to set the depth buffer resolution. The resolution argument passed to the call must be a multiple of 2. Otherwise, the setting is invalid and an error code defined in HcErrorCode is returned.
const unsigned int alignedWidth = 400;
const unsigned int alignedHeight = 200;
CHECK_RESULT(HcSetResolution(obj, alignedWidth, alignedHeight));
HcOccluderMeshType contains the following configurable items:
HcOccluderMeshType occluders = {
.numMesh = 1, .meshes = &mesh, .bWinding = HC_CCW,
.idxType = HC_UNSIGNED_SHORT, .vtxStride = case0VtxStride,
.nearClipDistance = 0.1f
};
Execute Occlusion Culling upon preparation completion. The sample code is as follows.
// Add occluders to the Occlusion Culling plug-in.
CHECK_RESULT(HcAddOccluderMeshes(obj, occluders));
// Rasterize occluders to the depth buffer
CHECK_RESULT(HcRasterizeOccluder(obj));
// Use the depth buffer to query the AABB of occludees.
CHECK_RESULT(HcTestOccludeesAABB(obj, occludees, result));
// Clear the depth buffer after the occlusion query is complete.
CHECK_RESULT(HcClearBuffer(obj));
You can print result to view the Occlusion Culling result.
bool visibility[4] = { true };
bool *result[] = { &visibility[0], &visibility[1], &visibility[2], &visibility[3] };
CHECK_RESULT(HcTestOccludeesAABB(obj, occludees, result));
printf("aabb0: %d, aabb1: %d, aabb2: %d, aabb3: %d\n\n",
visibility[0], visibility[1], visibility[2], visibility[3]);
In Sample, result is the pointer to visibility. Print visibility to view the result.
printf("aabb0: %d, aabb1: %d, aabb2: %d, aabb3: %d\n\n",
visibility[0], visibility[1], visibility[2], visibility[3]);
Well done. You have successfully completed this codelab and learned how to:
For more information, click the following links:
Related documents
Download the demo source code used in this codelab from the following address: