Skip to content

Limit Scope of Default Uniforms #5280

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

JetStarBlues
Copy link
Contributor

@JetStarBlues JetStarBlues commented Jun 1, 2021

Resolves #5279

Changes:
Only sets the default uniforms if the current shader is not user-defined. See linked issue for more details.

They should not be set if using a user-defined fill shader.
They should not be set if using a user-defined stroke shader.
fillShader.setUniform('uMaterialColor', this.curFillColor);
fillShader.setUniform('isTexture', !!this._tex);
if (this._tex) {
fillShader.setUniform('uSampler', this._tex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this prevent people from using the uSampler uniform? For instance, at the moment, you can use uSampler as a uniform in your shader and have p5 send you whatever texture was bound with the texture() function. I think we wouldn't want to take that functionality away.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just based off of the code, I think if a user has set texture(someTexture), then this._tex will be set, and the uSampler uniform will still get set for you here. A test to confirm that would be great though

@@ -262,15 +260,6 @@ p5.Shader.prototype.unbindTextures = function() {

p5.Shader.prototype._setMatrixUniforms = function() {
this.setUniform('uProjectionMatrix', this._renderer.uPMatrix.mat4);
if (this.isStrokeShader()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think moving this to the set stroke uniforms makes sense!

@Qianqianye
Copy link
Contributor

Thanks @JetStarBlues for working on it and @aferriss for the review.

I'm tagging this year's GSoC WebGL shader contributor @wong-justin and mentors @aferriss @aceslowman @sosunnyproject @davepagurek to take a look at this, so we can decide how to move forward with this PR.

@davepagurek
Copy link
Contributor

I think this is probably the right direction to move in. Currently it's pretty hard to tell whether p5 will decide to send uniforms to you or not. Unfortunately any changes we make to this might end up breaking someone's workflow, so I feel like if we want to settle on something we can confidently support going forward, we need a system for users to explicitly opt in to shader features via something like #6144 (ideally also by just replacing one "block" of a shader where possible so that most other p5 features continue to work.) Does that sound like the right direction to you all?

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

Successfully merging this pull request may close these issues.

Limit Scope of Default Uniforms
4 participants