logo80lv
Articlesclick_arrow
Research
Talentsclick_arrow
Events
Workshops
Aboutclick_arrow
profile_loginLogIn

Free Visual Debug Tool For Stencil Buffer In Unity

Alexander Ameye shared his new project.

Alexander Ameye, a skilled developer and Unity enthusiast known for his custom renderer for very hard shadows, as well as a tool for painting hidden outline maps, among other projects previously featured on 80 Level, has released a new tool called Stencil Debugger. It's designed to visualize the stencil buffer in Unity URP, proving valuable for debugging rendering effects that utilize the stencil buffer and help developers better understand and troubleshoot their rendering workflows.

If you're new to 3D rendering and would like to know more about the stencil buffer, Alexander provided some insights into this feature. He explained that it's an extra buffer where you can write values ranging from 0 to 255, and it's useful for querying and modifying values during rendering. Also, you can control the logic of writing to the stencil buffer so, for example, you could say, "If the stencil buffer already had a value, replace it with my new value," or "If the stencil buffer already had a value, set it to zero."

As a practical example, Alexander uses the stencil buffer in his outline shader with the following rendering process:

  1. Render the object to be outlined to a buffer and draw it as a colored silhouette. The stencil value is set to 1.
  2. Expand/dilate the silhouette. The original stencil values are preserved. The dilated silhouette doesn't write to the stencil buffer.
  3. Compose the dilated silhouette with the scene. To remove the original silhouette, the stencil buffer is checked. Only areas where the stencil value equals 0 are rendered, effectively cutting out the original outline.

You can learn more about Stencil Debugger here and try by clicking this link. The tool is free but has only been tested in Unity 6 and Unity 2022, including support for Render Graph. This implementation is not optimized for performance and is meant to be used only in the editor for debugging purposes.

Also, check out the developer's outlining toolkit available on Unity Asset Store. Alexander describes this pack as the result of years of experimentation with outline rendering in Unity, offering multiple techniques for achieving any type of outline effect you need:

Alexander Ameye

Alexander Ameye

Learn more about Alexander Ameye's projects here and join our 80 Level Talent platform and our new Discord server, follow us on InstagramTwitterLinkedInTelegramTikTok, and Threads, where we share breakdowns, the latest news, awesome artworks, and more.

Join discussion

Comments 0

    You might also like

    We need your consent

    We use cookies on this website to make your browsing experience better. By using the site you agree to our use of cookies.Learn more