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

Created basic WebGL feedback example #1246

Merged
merged 6 commits into from
Oct 14, 2023

Conversation

aceslowman
Copy link
Contributor

Addresses #1228

Changes:
Added a simple feedback effect, adapted in part from an example by @aferriss

cc @kjhollen

I'm not sure if this is appropriate to go in the 3D examples section, but at the moment, non-3d WebGL examples don't seem to have a home. Happy to move it if need be!

Screenshots of the change:
Screenshot 2022-07-25 105209

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

Thanks for taking the time to add this! I've left two minor comments just to make the code a little more readable, and one other suggestion about reset that I'd love to get your opinion on!


function draw() {
// draw the previous frame
pg.texture(swap);
Copy link
Contributor

@davepagurek davepagurek Jul 25, 2022

Choose a reason for hiding this comment

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

I notice that a number of people who use WebGL p5.Graphics objects run into issues at first when they don't call reset(), possibly because there aren't many examples that use it. For this example it doesn't matter if you reset or not, but if e.g. you used sphere instead of ellipse then you would see the sphere peeking out through the plane. How would you feel about using reset and sphere just so that people are aware of that method? It might be trying to do too much in one example, let me know what you think!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That sounds great, I have pushed a new commit using sphere() and reset(). How would you explain reset() to the user? I have added 'p5.Graphics sometimes requires us to use reset() before drawing', but that doesn't feel like it does enough to explain why.

Copy link
Contributor

@davepagurek davepagurek Jul 28, 2022

Choose a reason for hiding this comment

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

I guess the main thing that reset does is that it clears the depth buffer, so you can draw new things without the old things going in front. Kind of like ensuring everything from before just becomes background colours instead of 3D content. It also does some other stuff like resets lights though so best practice is probably to do it first thing. Maybe we can move it to the top with a comment like: "Keep the colors from before but reset all 3D information so new shapes always go on top of the existing colors"? Or a more succinct version of that if you can think of something!

Copy link
Member

@kjhollen kjhollen Aug 2, 2022

Choose a reason for hiding this comment

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

I think it's also worthwhile to comment why reset() isn't used for the swap object.

Generally, maybe it would be worthwhile to think of the simplest possible example using createGraphics that would motivate calling reset(). We do have an example here, but it's not linked from the main reference page: https://p5js.org/reference/#/p5.Graphics/reset (you first have to open the p5.Graphics reference). A good first step could be to add this simple example to createGraphics directly?

Another way I've seen this show up in teaching with a WebGL buffer is that students still expect the matrix transform to be reset with draw(). Could be a more succinct way to explain the concept on its own.

src/data/examples/en/20_3D/12_simple_feedback.js Outdated Show resolved Hide resolved
Copy link
Member

@kjhollen kjhollen left a comment

Choose a reason for hiding this comment

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

Hi Austin, this looks good. I suggest updating some of the descriptions, either to provide more context (for the text that appears directly on the page) or a stronger visual description (for the describe/alt text). Shared some thoughts on possible other examples in response to Dave's comments inline.

@@ -0,0 +1,53 @@
/*
* @name Simple Feedback
* @arialabel An example of a simple feedback effect using two buffers.
Copy link
Member

Choose a reason for hiding this comment

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

Here, I think it would be good to expand on this description to motivate why two buffers are required and why WebGL specifically is needed to make this work.


function draw() {
// draw the previous frame
pg.texture(swap);
Copy link
Member

@kjhollen kjhollen Aug 2, 2022

Choose a reason for hiding this comment

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

I think it's also worthwhile to comment why reset() isn't used for the swap object.

Generally, maybe it would be worthwhile to think of the simplest possible example using createGraphics that would motivate calling reset(). We do have an example here, but it's not linked from the main reference page: https://p5js.org/reference/#/p5.Graphics/reset (you first have to open the p5.Graphics reference). A good first step could be to add this simple example to createGraphics directly?

Another way I've seen this show up in teaching with a WebGL buffer is that students still expect the matrix transform to be reset with draw(). Could be a more succinct way to explain the concept on its own.

swap = createGraphics(710, 400, WEBGL);

describe(
'a WebGL example that achieves a simple feedback effect, displaying a slowly moving, radiating white sphere.'
Copy link
Member

Choose a reason for hiding this comment

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

I think we can leave out the part that says "a web gl example" and go for something more directly focused on the visuals, like "a slowly oscillating, radiating white sphere that fades into a dark gray background through a feedback visual effect"

@stalgiag stalgiag removed their request for review August 3, 2022 11:03
@Qianqianye
Copy link
Contributor

Hi @aceslowman and @kjhollen, is this PR ready to merge? Thanks.

Copy link
Contributor

@davepagurek davepagurek left a comment

Choose a reason for hiding this comment

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

I think this is a great addition to the examples collection as it is. We can iterate some more on explanations of stuff like reset() in our upcoming examples updates so that doesn't need to block this PR. Thanks for your work on this!

@Qianqianye Qianqianye merged commit ef64da2 into processing:main Oct 14, 2023
@Qianqianye
Copy link
Contributor

Thank you for working on it. I added this PR to the p5.js Documentation Update and Organization tracking board, so we can improve this example later.

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

Successfully merging this pull request may close these issues.

4 participants