# Stencil doesn't work on render-targets

**URL:** <https://forum.defold.com/t/stencil-doesnt-work-on-render-targets/66906>\
**Category:** Bugs\
**Created:** [November 26, 2020, 5:42pm UTC](https://forum.defold.com/t/stencil-doesnt-work-on-render-targets/66906 "2020-11-26T17:42:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![morgerion](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/morgerion/32/6641_2.png) [@morgerion](https://forum.defold.com/u/morgerion)\
**Post date:** [November 26, 2020, 5:42pm UTC](https://forum.defold.com/t/stencil-doesnt-work-on-render-targets/66906/1 "2020-11-26T17:42:07Z")

</div>

Stencil doesn’t work on render-targets.  
This is a funny observation, but I would like to know what caused this restriction and how it can be corrected?  
Is it because render.FORMAT\_DEPTH does not provide formats like D24S8 where there are bits for stencil?

---

<div class="post-metadata">

**Author:** ![morgerion](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/morgerion/32/6641_2.png) [@morgerion](https://forum.defold.com/u/morgerion)\
**Post date:** [November 29, 2020, 10:48am UTC](https://forum.defold.com/t/stencil-doesnt-work-on-render-targets/66906/2 "2020-11-29T10:48:18Z")

</div>

The solution has been found.  
Render-target documentation ([API reference (Render)](https://defold.com/ref/render/#render.render_target:name-parameters)) doesn’t mention anything about stencil.  
But if you do so:

```
  local color_params = {
        format = render.FORMAT_RGBA,
        width = RT_WIDTH,
        height = RT_HEIGHT,
        ...
    }
    local depth_params = {
        format = render.FORMAT_DEPTH,
        width = RT_WIDTH,
        height = RT_HEIGHT,
        ...
    }
    local stencil_params = {
        format = render.FORMAT_STENCIL,
        width = RT_WIDTH,
        height = RT_HEIGHT,
        ...
    }
  render_target = render.render_target("render_target_1", {
        [render.BUFFER_COLOR_BIT] = color_params,
        [render.BUFFER_DEPTH_BIT] = depth_params,
        [render.BUFFER_STENCIL_BIT] = stencil_params
  })

```

then the problems will be solved.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [November 29, 2020, 3:21pm UTC](https://forum.defold.com/t/stencil-doesnt-work-on-render-targets/66906/3 "2020-11-29T15:21:54Z")

</div>

Ah, the example only shows color and depth. But in the text it says “The table should contain keys specifying which buffers should be created with what parameters”.

---

<div class="post-metadata">

**Author:** ![morgerion](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/morgerion/32/6641_2.png) [@morgerion](https://forum.defold.com/u/morgerion)\
**Post date:** [November 29, 2020, 8:56pm UTC](https://forum.defold.com/t/stencil-doesnt-work-on-render-targets/66906/4 "2020-11-29T20:56:55Z")

</div>

Formally, it is so.  
However, the important thing is that it is impossible to find the word “stencil” in this context.  
The fact is that without a keyword anchor it is not clear WHAT to look for and WHERE to find it.

I wouldn’t have thought of linking stencil and the render-target buffer together (if I wasn’t a DirectX expert).

---

<div class="post-metadata">

**Author:** ![wind](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/wind/32/34710_2.png) [@wind](https://forum.defold.com/u/wind)\
**Post date:** [August 10, 2025, 10:18am UTC](https://forum.defold.com/t/stencil-doesnt-work-on-render-targets/66906/5 "2025-08-10T10:18:22Z")

</div>

Hi  
Is there any update about this?

I’ve added, this `BUFFER_STENCIL_BIT` on `render.render_target`, but the stencil mask is still not rendering.

> [@morgerion](#):
>
> ```lua
> local stencil_params = {
> format = render.FORMAT_STENCIL,
> width = RT_WIDTH,
> height = RT_HEIGHT,
> }
> ...
> [render.BUFFER_STENCIL_BIT] = stencil_params
> 
> ```
