# Why the shader alpha value is not applied

**URL:** <https://forum.defold.com/t/why-the-shader-alpha-value-is-not-applied/80070>\
**Category:** Questions\
**Created:** [March 15, 2025, 10:22am UTC](https://forum.defold.com/t/why-the-shader-alpha-value-is-not-applied/80070 "2025-03-15T10:22:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Asatte](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/asatte/32/39093_2.png) [@Asatte](https://forum.defold.com/u/Asatte)\
**Post date:** [March 15, 2025, 10:22am UTC](https://forum.defold.com/t/why-the-shader-alpha-value-is-not-applied/80070/1 "2025-03-15T10:22:09Z")

</div>

I’m trying to get a shader work. But alpha value is not applied despite I set the value to 0 (or any other value). There probably some setting (blend setting?) that I need to enable but could not find where I can do it so I would appreciate it if. I can show it with this minimal code

```lua
#version 140

in highp vec4 var_position;
in mediump vec2 var_texcoord0;
in mediump vec3 var_normal;
in mediump vec4 var_light;

out vec4 out_fragColor;

uniform fs_uniforms
{
    mediump vec4 scanline_params;
    mediump vec4 time;
};

void main()
{
    float scanline_count = scanline_params.x;

    float scroll_speed = 0.02;
    float scroll_offset = mod(var_texcoord0.y + time.x * scroll_speed, 1.0); 

    float scanline_intensity = sin(scroll_offset * scanline_count * 3.14159 * 2.0);
    scanline_intensity = (scanline_intensity * 0.5 + 0.5) * 0.9 + 0.1;

    if (scanline_intensity < 0.75)
    discard;

    out_fragColor = vec4(vec3(0.2), 0);
}

```

 ![1](https://forum-defold-uploads.b-cdn.net/original/3X/9/f/9ff2220a48fc8bb37a8db289ae96aa22e92bd532.png)  
 ![2](https://forum-defold-uploads.b-cdn.net/original/3X/d/9/d9f0d1ce0aa5b3966583865721e8c133018d10c5.png)  
 ![3](https://forum-defold-uploads.b-cdn.net/original/3X/e/1/e105afd8ea6d6b5c4a3c78b37b7a7d7282f2aea2.png)

---

<div class="post-metadata">

**Author:** ![selimanac](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/selimanac/32/6397_2.png) [@selimanac](https://forum.defold.com/u/selimanac)\
**Post date:** [March 15, 2025, 11:27am UTC](https://forum.defold.com/t/why-the-shader-alpha-value-is-not-applied/80070/2 "2025-03-15T11:27:51Z")

</div>

> [@How to make a shader’s alpha/transparency work?](https://forum.defold.com/t/how-to-make-a-shader-s-alpha-transparency-work/79834/2):
>
> For transparency, render it last. And don’t write in depth buffer. render.set\_depth\_mask(false) --don't write to depth render.enable\_state(graphics.STATE\_DEPTH\_TEST) render.draw(self.predicates.model\_transparent, self.draw\_opts)

---

<div class="post-metadata">

**Author:** ![Asatte](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/asatte/32/39093_2.png) [@Asatte](https://forum.defold.com/u/Asatte)\
**Post date:** [March 15, 2025, 11:43am UTC](https://forum.defold.com/t/why-the-shader-alpha-value-is-not-applied/80070/3 "2025-03-15T11:43:22Z")

</div>

Thank you for the answer. But, I have already seen it, just could not figure out where or how to apply it. Do I modify the builtin renderer?  
I’m relatively new to Defold so there are many things I’m unfamiliar with. I can handle game logic part but shaders are a mystery to me so I’d appreciate if you could give some tips on it

---

<div class="post-metadata">

**Author:** ![selimanac](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/selimanac/32/6397_2.png) [@selimanac](https://forum.defold.com/u/selimanac)\
**Post date:** [March 15, 2025, 12:07pm UTC](https://forum.defold.com/t/why-the-shader-alpha-value-is-not-applied/80070/5 "2025-03-15T12:07:33Z")

</div>

> [@Asatte](#):
>
> Do I modify the builtin renderer?

Yes, you have to modify the builtin renderer.  
Copy, paste the build-in `.render_script` and `.render` to your project folder and [set it](https://defold.com/manuals/project-settings/#render) .

You can place your model predicated after the sprites, tilemaps section.

Something like this:  
(You might want to use graphics.BLEND\_FACTOR\_ONE\_MINUS\_SRC\_ALPHA instead of BLEND\_FACTOR\_ONE\_MINUS\_CONSTANT\_ALPHA)

```lua
  -- render the other components: sprites, tilemaps, particles etc
    --
    render.enable_state(graphics.STATE_BLEND)
    render.draw(predicates.tile, draw_options_world)
    render.draw(predicates.particle)
    --render.disable_state(graphics.STATE_DEPTH_TEST)

    -- render last
    render.set_blend_func(graphics.BLEND_FACTOR_SRC_ALPHA, graphics.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA) -- <- You might want to use graphics.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA
    render.draw(predicates.model_transparent, draw_options_world) -- <- model_transparent predicated
    render.disable_state(graphics.STATE_DEPTH_TEST)

```

Edit: You can set predicates in the init() function of the render script. Also, don’t forget to set the **TAG** to **model\_transparent** in the .material file of the model.

```lua
  self.predicates = create_predicates("tile", "gui", "particle", "model", "model_transparent", "skybox", "debug_text")

```

---

<div class="post-metadata">

**Author:** ![Asatte](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/asatte/32/39093_2.png) [@Asatte](https://forum.defold.com/u/Asatte)\
**Post date:** [March 15, 2025, 12:26pm UTC](https://forum.defold.com/t/why-the-shader-alpha-value-is-not-applied/80070/6 "2025-03-15T12:26:54Z")

</div>

It worked! Thank you so much. I wish there would be an easier way of doing thing with Defold, but at least its community makes things easier for newcomers

---

<div class="post-metadata">

**Author:** ![jhonny.goransson](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/jhonny.goransson/32/3864_2.png) [@jhonny.goransson](https://forum.defold.com/u/jhonny.goransson)\
**Post date:** [March 15, 2025, 2:04pm UTC](https://forum.defold.com/t/why-the-shader-alpha-value-is-not-applied/80070/7 "2025-03-15T14:04:04Z")

</div>

Yeah models should really have alpha settings, no idea why this hasn’t been added yet
