-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Feature: Implemented resetShader() #3467
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
Feature: Implemented resetShader() #3467
Conversation
i wonder if it might be more in line with existing framework naming to call this function |
@Spongman thanks for the nice suggestion, main influence for the name was certainly processing, and I feel |
Also need suggestions for whether the sketch should be merged, and if yes, where it should be present. |
@Spongman @limzykenneth @AdilRabbani @lmccart would you please review my implementation if you have some time to spare? |
I'm not familiar with WebGL's implementation so I don't usually look at issues relating to webgl mode. |
I think it would be helpful and constructive for me if I get to know why this PR is not being reviewed, it will surely help me to rectify my mistakes in the future. 😄 |
Hey @sanketsingh24 I am busy with some other work these days but I'll try to have a look at this by the weekend. In the mean time, @kjhollen and @stalgiag might be able to give you additional feedback. I believe they can surely review this, better than me! 😄 |
Thanks @AdilRabbani! Very well said. @sanketsingh24 I will start reviewing WebGL related pull requests next week. If this PR hasn't been reviewed before then I will check it out in order of importance. There is a small backlog of PRs but I'll be putting in significant time looking over things starting next week. Thanks for your contribution! |
Hey @sanketsingh24, the test example you added is not able to load styles.css and stats.js file. Is it just me or does it happen for you as well? |
@AdilRabbani Oh while testing, the whole folder was somewhere else, and I didn't update the path before pushing, will do it now. Sorry and thanks for testing and pointing it out 😄. |
Hi @sanketsingh24 ! I think it is a great idea to add this feature. It may be a little heavily dependent on changes to when shader uniforms are set such as the types of changes proposed by #3076. The reason I bring this up is because I was playing around with your manual test example and I changed the code in draw to:
As you can see the lighting doesn't update before rendering the first sphere. It is possible that this should be considered unrelated to this particular PR but thought worth initiating a discussion about what the user should expect to happen when |
@stalgiag I think I need to dig a little deeper on this stuff, also on what user should expect. As my exams are coming, I need some time off, but surely I will do in this fortnight. |
@stalgiag, I have a doubt, should using Code- function draw()
{
background(0);
var dirY = (mouseY / height - 0.5) * 2;
var dirX = (mouseX / width - 0.5) * 2;
directionalLight(204, 204, 204, -dirX, -dirY, -1);
ambientMaterial(0, 255, 255);
shader(toonShader);
translate(-150, 0, 0);
sphere(120);
translate(300, 0, 0);
ambientMaterial(0, 255, 255);
sphere(120);
} Mouse pointer was in between the two spheres, couldn't capture it in the screenshot. |
Hi @sanketsingh24 it does look a little unexpected in your screenshot but I believe everything is still working as expected. I cross-tested in Processing and received different results. It is important to note that this example uses per-vertex lighting and also that the lighting direction is being modified by the mouse. This is different than the modifying the lighting origin point. With directional lights it is as thought there are rays of light moving from -infinite to infinite in the direction specified, as with sunlight. |
Oh alright I got that |
Ok I think I have an explaination for this, function draw()
{
background(0);
var dirY = (mouseY / height - 0.5) * 2;
var dirX = (mouseX / width - 0.5) * 2;
directionalLight(204, 204, 204, -dirX, -dirY, -1);
ambientMaterial(0, 255, 255);
shader(toonShader);
translate(-150, 0, 0);
sphere(120);
translate(300, 0, 0);
resetShader();
ambientMaterial(0, 255, 255);
sphere(120);
} Because function mouseClicked() {
shader(toonShader);
} Just for the first iteration of Also, if var toonShader;
var shaderEnabled=true;
function preload() {
toonShader = loadShader('vert.glsl', 'frag.glsl');
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
noStroke();
// shader(toonShader);
toonShader.setUniform('fraction', 1.0);
}
function draw()
{
background(0);
var dirY = (mouseY / height - 0.5) * 2;
var dirX = (mouseX / width - 0.5) * 2;
directionalLight(204, 204, 204, -dirX, -dirY, -1);
ambientMaterial(0, 255, 255);
shader(toonShader);
translate(-150, 0, 0);
sphere(120);
translate(300, 0, 0);
sphere(120);
} Here, I think that For your example, using I don't know how to fix this right now, maybe can be fixed in a new issue. @stalgiag @outofambit @Spongman @AdilRabbani can you please check and review if I have caught the correct error? |
this is going to conflict quite heavily with #3535 if that gets merged. |
Yes apologies for not making that more clear @sanketsingh24 . As @Spongman says #3535 is an update to the #3076 that I mentioned earlier, and is very likely to be merged soon. Your work with |
oops, sorry, i missed that you had already mentioned that. this should be reasonably simple to implement wrt. #3076. just setting |
#3535 was just merged. @Spongman's idea for how to reset the shader with those changes in mind is a good one. Thanks for the patience @sanketsingh24 ! |
Ok alright I would make the changes and test once, really nice changes :) |
Ok, the new changes were easy to do, and solves this issue, but still, please see these cases- var toonShader;
var shaderEnabled=true;
function preload() {
toonShader = loadShader('vert.glsl', 'frag.glsl');
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
noStroke();
//shader(toonShader);
toonShader.setUniform('fraction', 1.0);
}
function draw()
{
background(0);
var dirY = (mouseY / height - 0.5) * 2;
var dirX = (mouseX / width - 0.5) * 2;
directionalLight(204, 204, 204, -dirX, -dirY, -1);
shader(toonShader);
ambientMaterial(0, 255, 255);
translate(-150, 0, 0);
sphere(120);
translate(300, 0, 0);
//resetShader();
ambientMaterial(0, 255, 255);
sphere(120);
}
var toonShader;
var shaderEnabled=true;
function preload() {
toonShader = loadShader('vert.glsl', 'frag.glsl');
}
function setup() {
createCanvas(windowWidth, windowHeight, WEBGL);
noStroke();
shader(toonShader);
toonShader.setUniform('fraction', 1.0);
}
function draw()
{
background(0);
var dirY = (mouseY / height - 0.5) * 2;
var dirX = (mouseX / width - 0.5) * 2;
directionalLight(204, 204, 204, -dirX, -dirY, -1);
//shader(toonShader);
ambientMaterial(0, 255, 255);
translate(-150, 0, 0);
sphere(120);
translate(300, 0, 0);
//resetShader();
ambientMaterial(0, 255, 255);
sphere(120);
} the output is as expected here. |
shouldn't this also be resetting |
Yes @Spongman I think |
i'm not sure about |
I agree with @Spongman. We can keep the shaders and textures as separate ideas when rendering. |
Also, regarding the unit tests, shall I place them at |
@sanketsingh24 that seems good. You can just set the custom shader with one of the private |
@stalgiag I added a unit test, and also resolved a merge conflict, please review. |
@sanketsingh24 I just wanted to add a note to say that I haven't forgotten about this. I am focusing on the tickets for the 0.8.0 release right now but I definitely have not forgotten about this and will look it over one last time as soon as I get a chance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works well @sanketsingh24 ! Thanks for handling all of the requested changes while the GL renderer was undergoing a number of changes. This is a great utility for people using custom shaders.
Closes #3461
Implemented resetShader() method, on the basis of its namesake in processing.
Features:
Work Done: