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

resetShader() doesn't reset to default stroke / fill shaders #4714

Closed
1 of 12 tasks
aferriss opened this issue Jul 26, 2020 · 7 comments · Fixed by #6497
Closed
1 of 12 tasks

resetShader() doesn't reset to default stroke / fill shaders #4714

aferriss opened this issue Jul 26, 2020 · 7 comments · Fixed by #6497

Comments

@aferriss
Copy link
Contributor

aferriss commented Jul 26, 2020

Most appropriate sub-area of p5.js?

  • Color
  • Core/Environment/Rendering
  • Data
  • Dom
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Other (specify if possible)

Details about the bug:

As far as I can tell resetShader() isn't doing any resetting. I haven't dug too deeply into this so I'm not sure what might be going on but it looks like setting userFillShader and userStrokeShader to null is not enough to reset the custom shaders. Oddly, if I place my initial calls to shader() inside of setup, resetShader() does seem to work if I do my non-custom shader drawing inside of draw.

Here's a small example showing the issue
https://editor.p5js.org/aferriss/sketches/X-kF7aVT8

@matvs
Copy link
Contributor

matvs commented Jul 28, 2020

Hi @aferriss
Thanks for reporting this bug.

It looks like rendering order is an issue here.
https://editor.p5js.org/matvs/sketches/_rtBhhm-h
I am working on it :)

@matvs
Copy link
Contributor

matvs commented Jul 29, 2020

It seems to me, that there is actually nothing wrong with resetShader() function.

In my previous example one can see, that the green square is actually rendered, but either drawing order is false or z coordinate of red square is higher.

It looks like it is the latter, because adjusting position.z in vertex shader solves the issue: https://editor.p5js.org/matvs/sketches/FG-Lz2Oon

It can also be solved directly in JS with for example applyMatrix or transform.

I don't think that it is a bug in p5.js, because it simply respects how shaders are defined.

@aferriss
Copy link
Contributor Author

Ah, this is good to know! Thanks for looking into it. I wonder if there is anything we can add to the docs to make people aware of the fact that depth will be taken into account over draw order.

@davepagurek
Copy link
Contributor

An update to this to make the task clearer: it would be great to mention somewhere in the shader() docs that since a shader might update the vertex positions of shapes in 3D space, causing them to draw in front of subsequent shapes.

We generally recommend using this vertex shader for shapes to use p5's transformation system: https://github.com/processing/p5.js/blob/main/src/webgl/shaders/filters/default.vert Maybe we can add another example to shader() that uses createShader and passes that vertex shader in as a string?

@deveshidwivedi
Copy link
Contributor

alright! @davepagurek, could you please be a little specific as to how to go about it?

@davepagurek
Copy link
Contributor

Maybe we can update the shader in the createShader example (1) to use javascript multiline strings (ones surrounded by `\backticks`) instead of a bunch of concatenated lines, and (2) use this vertex shader: https://github.com/processing/p5.js/blob/main/src/webgl/shaders/filters/default.vert

Then, in the docs for loadShader, createShader and shader, add a sentence noting that shaders can change the positioning of shapes drawn with them, and to use the vertex shader in the createShader example to avoid inconsistency. (In the createShader docs, we can just say "in the example below", but for the other docs, it should link to the createShader docs.)

@deveshidwivedi
Copy link
Contributor

I opened a PR(#6497), please have a look! @davepagurek

@davepagurek davepagurek moved this from Documentation to In Progress in p5.js WebGL Projects Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: DONE! 🎉
p5.js WebGL Projects
  
In Progress
Development

Successfully merging a pull request may close this issue.

5 participants