Overview

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

  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.

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:

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, click the following links:

Related documents
Download the demo source code used in this codelab from the following address:

Download source code

Code copied