# P5.js Using Shaders with FrameBuffers

**URL:** https://discourse.processing.org/t/p5-js-using-shaders-with-framebuffers/43874
**Category:** Coding Questions
**Created:** [February 10, 2024, 10:03am UTC](https://discourse.processing.org/t/p5-js-using-shaders-with-framebuffers/43874 "2024-02-10T10:03:52Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![prontopablo](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@prontopablo](https://discourse.processing.org/u/prontopablo)
#### Post date: [February 10, 2024, 10:03am UTC](https://discourse.processing.org/t/p5-js-using-shaders-with-framebuffers/43874/1 "2024-02-10T10:03:52Z")

</div>

Hi all!

I’m trying to use p5.js framebuffers with shaders. I have had success with other shaders but this threshold shader and a few other similar ones I have only work for a moment and then the screen fades to black. I can’t tell if it’s an issue on the shader side or something else.

Here’s a link to the [sketch](https://editor.p5js.org/prontopablo/sketches/-QEUzST_G)

Any help would be greatly appreciated!

---

<div class="post-metadata">

### Author: ![scudly](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/scudly/32/5597_2.png) [@scudly](https://discourse.processing.org/u/scudly)
#### Post date: [February 10, 2024, 6:20pm UTC](https://discourse.processing.org/t/p5-js-using-shaders-with-framebuffers/43874/2 "2024-02-10T18:20:09Z")

</div>

Add a `resetShader();` after the `rect();`. The shader is still in effect the next time you draw the layer which is (somehow) causing the problem.

---

<div class="post-metadata">

### Author: ![prontopablo](https://avatars.discourse-cdn.com/v4/letter/p/8edcca/32.png) [@prontopablo](https://discourse.processing.org/u/prontopablo)
#### Post date: [February 10, 2024, 6:46pm UTC](https://discourse.processing.org/t/p5-js-using-shaders-with-framebuffers/43874/3 "2024-02-10T18:46:11Z")

</div>

Thank you so much, I’ve been banging my head against the wall for 4 days. I couldn’t for the life of me figure out why the sampler seemed to change over time. I tried so many things, thank you. I really have no idea why certain shaders are affected or what the underlying interaction is that makes this happen.

---

<div class="post-metadata">

### Author: ![sableraph](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/sableraph/32/251_2.png) [@sableraph](https://discourse.processing.org/u/sableraph)
#### Post date: [February 16, 2024, 10:58am UTC](https://discourse.processing.org/t/p5-js-using-shaders-with-framebuffers/43874/4 "2024-02-16T10:58:56Z")

</div>

Ping @davepagurek for shader wisdom 🙂
