# Pixel Overdraw

**URL:** <https://forum.playcanvas.com/t/pixel-overdraw/29442>\
**Category:** Useful Resources\
**Tags:** graphics, ui, editor, performance\
**Created:** [January 29, 2023, 6:25am UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442 "2023-01-29T06:25:13Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![queriel](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/queriel/32/23979_2.png) [@queriel](https://forum.playcanvas.com/u/queriel)\
**Post date:** [January 29, 2023, 6:25am UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/1 "2023-01-29T06:25:13Z")

</div>

Hi. I prepared simple script components that can help you to understand if your scenes have massive pixel overdraw.

**Playcanvas Project** : [PlayCanvas 3D HTML5 Game Engine](https://playcanvas.com/project/1033119/overview/overdraw)  
**Github** : [GitHub - querielo/playcanvas-overdraw · GitHub](https://github.com/querielo/playcanvas-overdraw)

**Playcanvas Typescript Template** :

- **Forum topic** : [PlayCanvas TypeScript template (branch sync, GitHub actions and so on)](https://forum.playcanvas.com/t/playcanvas-typescript-template-branch-sync-github-actions-and-so-on/29430)
- **Github** : [GitHub - querielo/playcanvas-typescript-template · GitHub](https://github.com/querielo/playcanvas-typescript-template)

### Summary

Pixel overdraw refers to the number of times a pixel is drawn on top of itself. Keeping pixel overdraw as low as possible is important for several reasons:

1. **Performance** : Overdraw can greatly slow down the performance of a game or application, as it requires the GPU to do more work.
2. **Battery life** : Overdraw can also have a significant impact on battery life, as it requires more power to draw more pixels.
3. **Quality** : Overdraw can also lead to visual artifacts, such as flickering or aliasing, which can negatively impact the visual quality of the game or application.

To reduce pixel overdraw, it is important to make sure that objects in the scene are properly sorted, and that objects that are obscured by others are not drawn. Additionally, techniques such as culling and occlusion can be used to further reduce the number of pixels that need to be drawn.

**NOTE** : reducing overdraw can help only if fragment shaders are your bottleneck. So, always use [the Playcanvas profiler](https://developer.playcanvas.com/ru/user-manual/optimization/profiler/) for your project before optimizations.

Example:

 ![Screen Shot 2023-01-28 at 15.39.31](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/e/7/e728950cddb82fb10073a2d1edd208a1c0844867.png)

With enabled UI:

 ![Screen Shot 2023-01-28 at 15.40.06](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/f/5/f5b205627d4ed5bf61aeadb82528c35d8cfb6bf6.png)

**TODO** : It appears that it is necessary to consider the issue of baking text into a texture, if it isn’t changed for a long period of time. Because, black means that the pixel has been overdrawn at least 9 times.

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [January 29, 2023, 11:16am UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/2 "2023-01-29T11:16:59Z")

</div>

Hi @queriel,

Many thanks for sharing, that is super useful to debug performance. Unreal engine offers an easy to use overdraw visual debugger that I used to find so handy.

Thanks again!

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [January 29, 2023, 11:25am UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/3 "2023-01-29T11:25:31Z")

</div>

And here is a test on my vegetation full / prone to overdraw scene (Solar Island). We ended up using real meshes for grass/flowers to avoid exactly that, insane overdraw when using billboards.

 ![launch.playcanvas.com_1411927_debug=true&ministats=true](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/d/5/d5f4581a5943e87866426cc1f27e18f38884425f.jpeg)

 ![launch.playcanvas.com_1411927_debug=true&ministats=true_overdraw](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/5/5/5523996ae40b3222ab4bfe47772d379f244c17e0.jpeg)

---

<div class="post-metadata">

**Author:** ![queriel](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/queriel/32/23979_2.png) [@queriel](https://forum.playcanvas.com/u/queriel)\
**Post date:** [January 29, 2023, 12:31pm UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/4 "2023-01-29T12:31:04Z")

</div>

Have you tried using the DrawSorter component from the repo to change the render order in a World layer? How does it look?

OFFTOP: how do you add pcui? Is it loaded as an external script?

---

<div class="post-metadata">

**Author:** ![yaustar](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/yaustar/32/2268_2.png) [@yaustar](https://forum.playcanvas.com/u/yaustar)\
**Post date:** [January 30, 2023, 1:08pm UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/5 "2023-01-30T13:08:56Z")

</div>

This is awesome, I might try to add this to my devtools if I can find an easy way to add it: [yaustar.github.io/playcanvas-devtools at master · yaustar/yaustar.github.io · GitHub](https://github.com/yaustar/yaustar.github.io/tree/master/playcanvas-devtools)

> [@queriel](#):
>
> OFFTOP: how do you add pcui? Is it loaded as an external script?

If you are using the Editor, you can create a UMD build and add it as normal code file. eg [https://playcanvas.com/project/1021958/overview/pcui-30-debug-draw](https://playcanvas.com/project/1021958/overview/pcui-30-debug-draw)

PCUI build steps here: [pcui/BUILDGUIDE.md at main · playcanvas/pcui · GitHub](https://github.com/playcanvas/pcui/blob/main/BUILDGUIDE.md)

---

<div class="post-metadata">

**Author:** ![Leonidas](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/leonidas/32/6495_2.png) [@Leonidas](https://forum.playcanvas.com/u/Leonidas)\
**Post date:** [January 30, 2023, 2:38pm UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/6 "2023-01-30T14:38:04Z")

</div>

> [@queriel](#):
>
> Have you tried using the DrawSorter component from the repo to change the render order in a World layer? How does it look?

So that’s a very interesting approach! Visually there is almost no change on my test scene, it works as expected, just a slight change on the grass at a distance.

Still I think on my scene I get the best performance with the default preset Material/Mesh on the World layer.

I will make sure to let you know if I test some more, many thanks for sharing this!

---

<div class="post-metadata">

**Author:** ![mvaligursky](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/mvaligursky/32/11681_2.png) [@mvaligursky](https://forum.playcanvas.com/u/mvaligursky)\
**Post date:** [January 30, 2023, 3:48pm UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/7 "2023-01-30T15:48:10Z")

</div>

Maybe even a depth pre-pass, at least for some nearby meshes, could be beneficial in general. Not that we have some easy way to test it.

---

<div class="post-metadata">

**Author:** ![queriel](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/queriel/32/23979_2.png) [@queriel](https://forum.playcanvas.com/u/queriel)\
**Post date:** [January 30, 2023, 6:28pm UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/8 "2023-01-30T18:28:24Z")

</div>

> [@yaustar](#):
>
> I might try to add this to my devtools if I can find an easy way to add it:

It would be cool!

> [@Leonidas](#):
>
> Still I think on my scene I get the best performance with the default preset Material/Mesh on the World layer.

Ofc. It depends on CPU/GPU consumption. So, Material/Mesh is CPU-friendly, Front-To-Back is GPU-friendly. Probably, CPU is a bottleneck for your scene.

> [@mvaligursky](#):
>
> Maybe even a depth pre-pass, at least for some nearby meshes, could be beneficial in general. Not that we have some easy way to test it.

Hm. Can we use the occlusion queries (WebGL2) from previous frames for a sorting strategy? The sorting could be performed by considering the fragment count for each MeshInstance, incorporating randomness to account for any variations due to draw order. The heuristic in this case can also improve depth pre-pass for occluding objects. I’m not sure that it works.

---

<div class="post-metadata">

**Author:** ![sooyong\_Kim](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/sooyong_kim/32/28046_2.png) [@sooyong\_Kim](https://forum.playcanvas.com/u/sooyong_Kim)\
**Post date:** [September 22, 2023, 2:29am UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/9 "2023-09-22T02:29:10Z")

</div>

Somehow this one doesn’t work with 1.65.3 version.

---

<div class="post-metadata">

**Author:** ![LeXXik](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/lexxik/32/6953_2.png) [@LeXXik](https://forum.playcanvas.com/u/LeXXik)\
**Post date:** [September 22, 2023, 8:56am UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/10 "2023-09-22T08:56:59Z")

</div>

Do you have an error to share?

---

<div class="post-metadata">

**Author:** ![queriel](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/queriel/32/23979_2.png) [@queriel](https://forum.playcanvas.com/u/queriel)\
**Post date:** [September 22, 2023, 10:13am UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/11 "2023-09-22T10:13:56Z")

</div>

It looks like there is a new stencil state control mechanism. I’ll look at it today. **UPD:** the issue is bigger than I thought.

---

<div class="post-metadata">

**Author:** ![queriel](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/queriel/32/23979_2.png) [@queriel](https://forum.playcanvas.com/u/queriel)\
**Post date:** [September 25, 2023, 7:50am UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/12 "2023-09-25T07:50:11Z")

</div>

Fixed. You can use **overdraw.js** for Playcanvas +1.63 and **overdraw\_pre\_1.62.js** for Playcanvas 1.62.

 ![Screenshot 2023-09-25 at 09.46.39](https://forum-files-playcanvas-com.s3.dualstack.eu-west-1.amazonaws.com/original/3X/e/3/e37039e8d4df13ec91f892c603fcbbb50a22c1b2.png)

---

<div class="post-metadata">

**Author:** ![sooyong\_Kim](https://forum.playcanvas.com/user_avatar/forum.playcanvas.com/sooyong_kim/32/28046_2.png) [@sooyong\_Kim](https://forum.playcanvas.com/u/sooyong_Kim)\
**Post date:** [September 26, 2023, 5:29am UTC](https://forum.playcanvas.com/t/pixel-overdraw/29442/13 "2023-09-26T05:29:26Z")

</div>

@queriel Thanks…I will try it soon. ~~~~
