> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/tutorials/code-tutorials/flatredballxna-tutorials-culling.md).

# Culling

### Introduction

Culling is the process of determining that an object or a part of an object does not need to be drawn, then skipping the drawing logic because of this determination. This is an effective way to improve performance if the process of detecting whether an object should be drawn is significantly faster than just performing the drawing itself, or if it is slightly faster but most objects will fail the draw test.

Some types of culling are performed at the hardware level. XNA and MDX have some options which allow you to cull objects depending on their position or orientation.

Other types of culling are performed at the engine level. FlatRedBall by default culls [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) and [PositionedModels](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) which are not in view. [SpriteGrids](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) perform an even more efficient culling than draw culling. By default [SpriteGrids](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) remove [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) which are not in view from the engine's memory. This not only saves draw time, but also management time and memory usage.

### RenderState CullMode

FlatRedBall automatically culls the "back faces" of models by setting the RenderState's CullMode to CullMode.CullCounterClockwiseFace. This eliminates the drawing of back-facign polygons which are part of [PositionedModels](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php). In some cases this can double rendering speed.

This behavior happens automatically and requires no special implementation or management.

### RenderState DepthBufferFunction

FlatRedBall uses the depth buffer (also known as the Z-buffer) to both create realistic-looking sorting as well as to improve performance.

The depth buffer is used in the following cases:

* When drawing [PositionedModels](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).
* When drawing [Z Buffered Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).

Depth buffered culling is performed on a per-pixel basis. If a depth buffer check fails, then the renderer does not need to perform the pixel shader code for that pixel.

[PositionedModels](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) automatically perform depth buffer culling so there is no need for any special implementation or management. [Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php) perform depth buffer culling if added as [Z Buffered Sprites](https://github.com/flatredball/FlatRedBallDocs/tree/main/frb/docs/index.php).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/flatredball/tutorials/code-tutorials/flatredballxna-tutorials-culling.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
