Skip to content

How It Works

Matt Dean edited this page Apr 28, 2019 · 5 revisions

BACK > Home


Welcome to kPortals!

This page explains how the functionality behind kPortals works.

alt text Data diagram for kPortals.

1) Generate Volumes

The stage has three methods; Manual, Automatic and Hybrid

Manual: The user creates Portal Volumes in the scene. The Portal System then generates a flat data structure to fill with visibility information.

Automatic: The Portal System calculates a bounds that encapsulates all static renderers, then subidivdes it by the amount of the user defined property Subdivisions. This process generates a hierarchical data structure to fill with visibility information.

Hybrid: A mix of the previous two. The Portal System will calculate a subdivided bounds as per Automatic mode. However, the user can then suppliment this with extra Portal Volumes in the scene.

alt text Automatic Volume generation.

2) Gather Occluders

Next the Portal System filters all the renderers in the scene by the Occludee Static flag. It also collects any user defined Port Occluders in the scene. From this information the Portal System generates a collection of serialized occluder data. Later, during the bake process, The Portal System then generates temporary mesh renderers based on these occluder objects to test for occlusion. These are then discarded.

alt text Visualization of different types of Occluder data.

3) Generate Rays

Now the Portal System, per Volume, generates a number of rays based on the user property Ray Density. This value defines the amount of rays to calculate per cubic unit.

alt text Generated rays for a single Volume.

4) Filter Renderers

Per-ray, the Portal System filters the occludees by testing their bounds against a cone around the ray, with its angle defined by the user property Filter Angle. Occludees that fail these test are discarded from visibility for this ray.

alt text Cone angle filtering.

5) Calculate Visibility

For all filtered occludees, the ray is tested for intersections with their AABBs. Occludees that fail this test are discarded from visibility for this ray.

alt text Occludee AABB ray intersection.

6) Calculate Occlusion

Next the ray is tested against the Occluders defined during step 2 by physics raycast. Occluders that are hit by the ray are sorted in a list by their distance to the ray origin, then all occludees that passed the visibility test have their distance tested against the nearest Occluder. All visible occludees further from the occluder are considered occluded and discarded from visibility for this ray.

alt text Physics raycast based Occlusion test.

7) Finalise

Finally all occludees that passed occlusion tests per-ray are accumulated and stored in the temporary data for this volume. Steps 3 through 7 are repeated for every volume in the lowest subdivision level, then this visibility data is serialized along with the occluder and volume data.

alt text

Component editor GUI.

8) Runtime

At runtime the system simply searches the serialized visibility data to find the lowest subdivision volume that each of the registered Portal Agents are within bounds of then calculates the differences in visible occludees.

For now, for lack of a better scriptable culling solution, these occludees simply have their renderers enabled/disabled to provide “culling”.