Occlusion Cutout

  Edit on GitHub

These docs are for 0.13.0-SNAPSHOT, an unreleased SNAPSHOT. See the latest release.

An OcclusionCutout cuts a dithered round hole through whatever stands between the camera and a target, such as the walls in front of a hero. Shadows are unaffected.

Materials

Only materials made with occlusionCutout = true are cut, and only where they are nearer the camera than the target.

val wall = LayeredMaterial(device, layers = listOf(bricks, moss), occlusionCutout = true)
val pillar = PBRMaterial(device, baseColorTexture = stone, occlusionCutout = true)

Target

Set the target and strength on the PBREnvironment’s occlusionCutout each frame. Ease strength from 0 to 1 instead of toggling it so the hole opens and closes smoothly.

environment.occlusionCutout.apply {
    target.set(hero.x, hero.y + 1.2f, hero.z)
    val goal = if (heroHidden) 1f else 0f
    strength += (goal - strength) * min(1f, dt.seconds * 8f)
}

Shape

radius is a fraction of the view’s height and softness is how much of it fades out. margin is how far in front of the target surfaces start being cut, and depthFade how far past that the cut takes to open fully, both in world units.

environment.occlusionCutout.apply {
    radius = 0.2f
    softness = 0.4f
    margin = 1f
    depthFade = 2f
}