Skip to content

Add Tint support in WebGL #3709

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

Merged
merged 7 commits into from
Jun 17, 2019
Merged

Add Tint support in WebGL #3709

merged 7 commits into from
Jun 17, 2019

Conversation

vedhant
Copy link
Contributor

@vedhant vedhant commented Apr 25, 2019

Fixes #2530.

Copy link
Contributor

@stalgiag stalgiag left a comment

Choose a reason for hiding this comment

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

Good first pass! A few requested changes inline.

@vedhant vedhant requested a review from stalgiag May 22, 2019 18:22
Copy link
Contributor

@stalgiag stalgiag left a comment

Choose a reason for hiding this comment

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

One simple problem that I explained inline. Other than that I'd just like to see 1 or 2 unit tests. I think that you should probably go the route of my first suggestion in the inline comment (initialize _tint with a default value in RendererGL), then you can add a unit test that checks to make sure that RendererGL._tint is not null after construction. Ping me if you need help figuring out how to make the unit test. Simplest todo here would be to make a new suite in the RendererGL unit tests after the renderer has been made and assert that myp5._renderer._tint is not null.

Also I would make a new manual test as well.

@@ -1083,6 +1086,10 @@ p5.RendererGL.prototype._setFillUniforms = function(fillShader) {
if (this._tex) {
fillShader.setUniform('uSampler', this._tex);
}
if (this._tint) {
fillShader.setUniform('uTint', this._tint);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This causes this example sketch to break:

let img;
function preload() {
  img = loadImage('../webgl/assets/UV_Grid_Sm.jpg');
}
function setup() {
  createCanvas(400, 200, WEBGL);
  image(img, 0, 0, 100, 100);
  tint(0, 153, 204); // Tint blue
  image(img, 100, 0, 100, 100);
}

The uTint uniform in the shader will have a value of vec4(0, 0, 0, 0) when drawing the first image. There are a number of different solutions that will work. You can initialize _tint with a value in RendererGL or add an else to this conditional that send a default value when _tint is null.

Copy link
Contributor

Choose a reason for hiding this comment

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

i would recommend using a default value instead of a conditional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have added default value for tint and a couple of unit tests. I wanted to add a unit test for testing whether _tint is reset after draw() loop. How can do that?

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 you need to use a Promise that tests _tint on the second pass through draw before calling resolve or reject. There may be better examples elsewhere but one place to look is the structure.js tests.

Copy link
Contributor

@stalgiag stalgiag left a comment

Choose a reason for hiding this comment

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

Thanks @vedhant!

@stalgiag stalgiag merged commit 12ec867 into processing:master Jun 17, 2019
@ffmaer
Copy link

ffmaer commented Jul 3, 2020

Thanks for the efforts. So is this feature available in p5.js 1.0.0 now? If not, when will it become available? Thanks.
Edit: I found out more about this issue: #4515

@micuat
Copy link
Member

micuat commented Feb 16, 2021

I just noticed that using tint inside a 2D canvas with webgl p5.Graphics cause error
https://editor.p5js.org/micuat/sketches/9hh8x1HjF

TypeError: canvas.getContext(...) is null (sketch: line 14)

@stalgiag
Copy link
Contributor

Thanks @micuat ! Will you open an issue for that? I think it could be related to something else but it will be easier to track in a new thread.

@micuat
Copy link
Member

micuat commented Feb 17, 2021

@stalgiag done!

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.

Tint() is not supported in WebGL
6 participants