# Discover what happens when occlusion culling is enabled

**URL:** https://forum.castle-engine.io/t/discover-what-happens-when-occlusion-culling-is-enabled/542
**Category:** Uncategorized
**Created:** [March 8, 2022, 10:48am UTC](https://forum.castle-engine.io/t/discover-what-happens-when-occlusion-culling-is-enabled/542 "2022-03-08T10:48:05Z")
**Posts on this page:** 1
**Showing post:** 4

<div class="post-metadata">

### Author: ![michalis](https://forum.castle-engine.io/user_avatar/forum.castle-engine.io/michalis/32/3_2.png) [@michalis](https://forum.castle-engine.io/u/michalis)
#### Post date: [March 9, 2022, 2:05am UTC](https://forum.castle-engine.io/t/discover-what-happens-when-occlusion-culling-is-enabled/542/4 "2022-03-09T02:05:17Z")

</div>

@DSK Done, with a demo! 🙂

Committed to GitHub in [Implement TCastleScene.WasVisible, TAbstractShapeNode.WasVisible, with · castle-engine/castle-engine@8adafca · GitHub](https://github.com/castle-engine/castle-engine/commit/8adafca04d617d51efc1f449e6d633162cf3e3d5) . You can either wait a few hours until the binary build of CGE is updated, or get CGE source code and recompile it now following [Compiling from source | Castle Game Engine](https://castle-engine.io/compiling_from_source.php) .

New methods:

- TCastleScene.WasVisible, docs:

```nohighlight
    { Whether the scene was (potentially, at least partially) visible in the last rendering event.

      The "was visible" means that "some shape was visible", that is:
      some shape passed frustum culling and occlusion culling (see https://castle-engine.io/occlusion_query )
      tests.

      For this method it doesn't matter if the scene contains some lights
      that only make some other scenes brighter. Or if the scene contains some background
      that affects TCastleViewport skybox. Only the visibility of shapes matters.

      If this scene instance is used multiple times within some viewport,
      or when multiple viewports render the same scene,
      then it is enough that at least one shape in one of the scene instances
      was visible last frame. }
    function WasVisible: Boolean;

```

- TAbstractShapeNode.WasVisible, docs:

```nohighlight
    { Whether the shape was (potentially, at least partially) visible in the last rendering event.

      Note that the same shape reference may be present multiple times
      within one scene.
      Moreover, the same scene may be present multiple times within one viewport.
      Moreover, multiple viewports may render the same scene.
      The shape is marked as "was visible" if any instance of it was visible
      in any viewport in any scene. }
    function WasVisible: Boolean;

```

- Demo in `examples/viewport_and_scenes/test_was_visible`. [castle-engine/examples/viewport\_and\_scenes/test\_was\_visible at master · castle-engine/castle-engine · GitHub](https://github.com/castle-engine/castle-engine/tree/master/examples/viewport_and_scenes/test_was_visible) , Screens:

 ![Zrzut ekranu z 2022-03-09 02-44-27](https://forum.castle-engine.io/uploads/default/original/1X/1ec75c115f6187a4cc8554ef0c8772e9ce278697.png)  
 ![Zrzut ekranu z 2022-03-09 02-43-58](https://forum.castle-engine.io/uploads/default/original/1X/4ef3ec81330f590e73f09a1648b035a979cf02b4.png)  
 ![Zrzut ekranu z 2022-03-09 02-43-53](https://forum.castle-engine.io/uploads/default/original/1X/eef7dbd64fe6be2a12b291918e6653d393d333df.png)

Note some caveats:

- There are no events, like OnShow / OnHide. Instead I exposed methods `WasVisible`, and you have to query them as often as you need to detect changes.

- In the end I didn’t use `TShape` to store / query this information, contrary to what I said earlier, as `TShape` and `Scene.Shapes` tree is harder to access, and it may be rebuild in case of some changes to scene graph.

---

_[View the full topic](https://forum.castle-engine.io/t/discover-what-happens-when-occlusion-culling-is-enabled/542)._
