processing / p5.js

p5.js is a client-side JS platform that empowers artists, designers, students, and anyone to learn to code and express themselves creatively on the web. It is based on the core principles of Processing. http://twitter.com/p5xjs —
http://p5js.org/
GNU Lesser General Public License v2.1
21.55k stars 3.3k forks source link

Limit Scope of Default Uniforms #5279

Open JetStarBlues opened 3 years ago

JetStarBlues commented 3 years ago

How would this new feature help increase access to p5.js?

Makes writing custom shaders more transparent.
Currently there are a couple of uniform names that are used by the default shaders. If a user uses these names in their program, the uniform values they set will get overwritten with the default values (and their program won't behave as they expect it to).

Most appropriate sub-area of p5.js?

Feature enhancement details:

The default shaders declare and use some uniforms. These reserved names are not known to a user. Rather than telling the user not to use this seemingly arbitrary list of reserved names, a better solution is to just not set these default uniforms when a user-defined shader is used (via shader()).

More discussion on this can be found on the related issue on the p5.js-website repo.

stalgiag commented 3 years ago

Hi! And apologies for letting so many of your issues and PRs sit for so long. There are only a few WebGL maintainers on this repo at the moment so our availability can be spotty.

I am not sure that the default uniforms should not be modified in custom shaders. I can imagine a case in which someone wants to distribute custom shaders for p5.js for people that don't know GLSL wherein the default uniforms with the p5 functions like fill() and stroke().

I am not committed to this stance as I am not sure if this case or the case in which there is an accidental uniform naming collision is more likely.

JetStarBlues commented 3 years ago

Hi, no worries, understandable! I'm very grateful for all the work you and fellow maintainers do =)!

I see, that is a cool use case. Reminds me of the shader mods people make to games like Minecraft. In that case, I can try my best to document what each of the default uniforms do.

---

What do you think of the last two commits, where the declaration of uViewPort and uPerspective are moved to the same location as other related uniforms. (uViewPort is no longer randomly on its own. uPerspective is moved from the matrix uniforms to the general stroke uniforms). If it the moves makes sense, I can create a separate PR for it.