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

shader overrides image if shader uses texture uniform input #6564

Open
1 of 17 tasks
agrshch opened this issue Nov 18, 2023 · 6 comments
Open
1 of 17 tasks

shader overrides image if shader uses texture uniform input #6564

agrshch opened this issue Nov 18, 2023 · 6 comments

Comments

@agrshch
Copy link
Contributor

agrshch commented Nov 18, 2023

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build Process
  • Unit Testing
  • Internalization
  • Friendly Errors
  • Other (specify if possible)

p5.js version

1.8

Web browser and version

Chrome

Operating System

MacOS

Steps to reproduce this

Here is the example code https://editor.p5js.org/agrshch/sketches/1u8ZRnuKQ

image() function behave weirdly if there is a shader, which uses a texture input

@Garima3110
Copy link
Contributor

I am interested in solving this issue.

@Garima3110
Copy link
Contributor

Well I tried to understand what's going on , In your code, you are using two shaders (test1 and test2) with different fragment shaders (test1.frag and test2.frag). When you apply the shader using the shader() function, it affects all subsequent drawing operations, including rect() and image().
In the case of test1, you are not setting any uniform or applying any texture, so it doesn't affect the rendering of the image. However, in the case of test2, you are setting the uniform u_X and applying a texture (u_image). When you use a shader that has a texture uniform (u_image in this case), it will use that texture for all subsequent drawing operations until a different shader is applied.

I think here you should use resetShader , so that both the shaders don't affect each other.

@agrshch
Copy link
Contributor Author

agrshch commented Nov 21, 2023

Hi @Garima3110! Thanks for looking into it! In my view the problem is not in shaders affecting each other. I was not clear, sorry — she shaders should not be applied simultaneously, only one at a time. Just comment one and uncomment the other.
I am wondering why a shader does affect image() function at all, and why, if it affects images, only the one with texture uniform input does so. It would be more consistent if both shaders affect image, or both do not.

@davepagurek
Copy link
Contributor

This issue is similar to #6268 -- it has to do with the fact that the logic to determine when we consider a shader replaceable is not documented. I plan on making this system more explicit in the future, where you have to say which shaders you're overriding, but in the mean time, we can document what the current logic is.

@nick2432
Copy link

Can I contribute to this issue? I'm new here, but I have experience contributing to many other organizations. Is there a Discord channel or any other channel where I can discuss and get assistance?

@Garima3110
Copy link
Contributor

Is there a Discord channel or any other channel where I can discuss and get assistance?

Discord

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Bugs with No Solution Yet
Development

No branches or pull requests

4 participants