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:

What You Will Create

In this codelab, you will use the demo project to call the Occlusion Culling SDK APIs. Through this demo project, you will:

What You Will Learn

Hardware Requirements

Software Requirements

Required Knowledge

Integrating the Occlusion Culling SDK

  1. Download the SDK package and decompress it. Copy the extracted cgsdk-plugin-occlusionculling folder to the directory where Android.mk is located.
  2. Configure Android.mk, where, LOCAL_SRC_FILES is the path of the .so files in the directory where Android.mk is located.
  3. Configure Application.mk, where, APP_PLATFORM should be at least android-24.

Executing Occlusion Culling

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:
bWinding: triangle winding order. When bWinding is HC_CCW, counterclockwise winding order is considered to be the rear face of a triangle and the rear face will not be rasterized to the depth buffer.
idxType: type of triangle vertex index, selected from unsigned byte, unsigned short, and unsigned int.
vtxStride: stride (in float components) between location attributes in the vertex buffer.

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]);
  1. Run the ndk-build NDK_PROJECT_PATH=. NDK_APPLICATION_MK=Application.mk APP_BUILD_SCRIPT=Android.mk command in the Sample directory to build.
  2. Run the adb push command to push the libthirdpartyengine_plugin_oc.so and Sample files in the Sample\obj\local\arm64-v8a folder to the /data/local/tmp directory of the smartphone.
  3. Run the export LD_LIBRARY_PATH=/data/local/tmp command in the shell.
  4. Run the chmod a+x Sample command in the /data/local/tmp directory.
  5. Run the ./Sample command in the /data/local/tmp directory.
    The command output similar to the following is displayed.

Well done. You have successfully completed this codelab and learned how to:

For more information, please click the following links:
Related Documents

To download the sample code, please click the button below:

Download sample code

Code copied