Skip to content

Per-polygon fills in 2D mode #7722

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
2 of 17 tasks
davepagurek opened this issue Apr 10, 2025 · 4 comments
Open
2 of 17 tasks

Per-polygon fills in 2D mode #7722

davepagurek opened this issue Apr 10, 2025 · 4 comments

Comments

@davepagurek
Copy link
Contributor

Increasing access

This is a thing in WebGL so getting as close to this as possible in 2D can help with consistency.

Most appropriate sub-area of p5.js?

  • Accessibility
  • Color
  • Core/Environment/Rendering
  • Data
  • DOM
  • Events
  • Image
  • IO
  • Math
  • Typography
  • Utilities
  • WebGL
  • Build process
  • Unit testing
  • Internationalization
  • Friendly errors
  • Other (specify if possible)

Feature enhancement details

In 2D mode, a limitation of the base canvas API is that every shape drawn can only have one color.

While we advertised one color per shape in 2D mode, in 1.x, some of the shape modes used to draw multiple shapes under the hood, including TRIANGLE_STRIP. Our initial shape implementation for 2.0 assumes that every shape in 2D mode is just one color, but we could in theory put this back for TRIANGLES, TRIANGLE_STRIP, QUAD_STRIP, and QUADS modes. (Unlike WebGL, it will not interpolate between vertices, but we can still change color per polygon.) We likely will want to continue to render the full thing as one shape for performance if the color does not change.

@LalitNarayanYadav
Copy link

Hi @davepagurek
I’ve submitted a PR that implements per-polygon fills in 2D mode as discussed in #7722.
It updates shape modes like TRIANGLES, TRIANGLE_STRIP, QUADS, etc., to apply fill and stroke based on the last vertex of each polygon.

Could you please take a look when you get a chance? I'd really appreciate your feedback!

@limzykenneth
Copy link
Member

Thanks @LalitNarayanYadav. Your PR is filed against the main branch which is currently the source code for the 1.x version of p5.js, however this issue applies to the dev-2.0 branch or the 2.0 version of p5.js. It might be a bit confusing as we didn't clearly indicate in the issue enough.

In 1.x this feature already works, so we don't need an implementation/PR for the main branch. We need an implementation for 2.0 where there are major changes in the internals of beginShape() endShape() hence the need for a new implementation.

I hope that made sense.

@LalitNarayanYadav
Copy link

Thanks for the clarification, @limzykenneth! That makes sense now—I misunderstood the target branch for this feature.

Would you recommend that I rebase and submit the PR against the dev-2.0 branch instead? If there are any specific guidelines or differences I should be aware of when implementing this in 2.0, I’d really appreciate any pointers.

Looking forward to your feedback!

@limzykenneth
Copy link
Member

The main branch and the dev-2.0 branch have diverge significantly especially in the vertex section that this issue relates to, which means rebase is not recommended. Starting from the dev-2.0 branch implementation from scratch is needed here.

The implementation is potentially very different in dev-2.0 so you may want to study that implementation first before trying to implement solution to this issue.

@ksen0 ksen0 moved this to In Progress in p5.js 2.1 🌱🌳 Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: In Progress
Development

No branches or pull requests

4 participants
@davepagurek @limzykenneth @LalitNarayanYadav and others