Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to implement a custom shader? #28

Open
jvolker opened this issue Feb 16, 2023 · 1 comment
Open

How to implement a custom shader? #28

jvolker opened this issue Feb 16, 2023 · 1 comment

Comments

@jvolker
Copy link

jvolker commented Feb 16, 2023

I'm trying to implement a fade-out effect of a masked image. Seems like I have a precision problem with the textures trying to get a slow fade effect. Now I found this library :) and like to implement it with my code: https://editor.p5js.org/jvolker/sketches/dqMQVI6Fl

I'm stuck with adapting the floating-point texture example: https://editor.p5js.org/jvolker/sketches/1cpxckP_- to my code. How to apply custom shaders with this FBO library? I couldn't find an example.

As soon as I write

fbo.draw(() => {
    shader(theShader);
    //rect(0,0,width, height);
  }) 

I get TypeError: Cannot read properties of undefined (reading 'width').

For reference, I've previously posted in the p5 forum:
https://discourse.processing.org/t/multiplying-small-numbers-in-shader-causes-strange-behaviour/40949

Thanks a lot in advance.

@jvolker
Copy link
Author

jvolker commented Feb 16, 2023

Okay, I've managed to implement it somehow: https://editor.p5js.org/jvolker/sketches/WGod7nyus

The key is to use fbo.color when applying it to the shader, which removes the errors:

fbo = createFramebuffer();

theShader.setUniform('u_texture', fbo.color);

The effect is still not working the way I like though. I don't seem to have control of the fade duration beyond a certain point, even with very small numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant