-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Allow vertex-wise coloring of areas bounded by bezier and quadratic curves in webgl #5919
Comments
Oh, sorry, 6 and 9 for the bezierVertex function, but 4 and 6 for the quadraticVertex function. |
benchMark test. |
That warning will be fixed in the next p5 version after this PR 🙂 #5910 I think as a default behaviour, this makes sense in general, but rather than linearly interpolating over the length of the look up table, does it make more sense to assign a fill color to each control point, and interpolate the fill color the same way we interpolate position? We have an open issue for how, in the future, one might be able to specify texture coordinates for bezier vertices #5722, and one could in the future apply a fill(color1)
vertex(x1, y1, z1, u1, v1)
fill(color2)
bezierControlPoint(x2, y2, z2, u2, v2)
fill(color3)
bezierControlPoint(x3, y3, z3, u3, v3)
fill(color4)
bezierControlPoint(x4, y4, z4, u4, v4) We don't have to add new methods for all this yet, but in order to support this in the future, I think it might make sense to change the interpolation so that we pick defaults for each control point. The values we pick could use the same logic you use here, interpolating from start to end, since I think as a default the results look good! |
Thanks for reply! Ah, I see, the unevenness in the appearance is due to the poor interpolation method... I think I need to think about it a little more. Thank you!('ω') |
I think your method is reasonable too! I'm mostly just trying to make sure we build it in a way that will work with other future methods for bezier control points. (Which we don't need to do along with this change, but it could be a cool follow up project if you're interested!) |
thank you. It's difficult to decide exactly how to interpolate...Actually, there are opinions that this method is fine and should be implemented. https://twitter.com/mary_s_ann/status/1607606663930073089 So, in my opinion, it's better to implement it in this direction for the time being and postpone the issue of a more accurate implementation. |
This method is definitely OK too! If we plan on changing it in the future though, it might be a bit better for users if we try to write it in a way that won't change their visuals. That said, we shouldn't let that get in the way of giving people the ability to add colour to beziers at all! So I'll describe what I was thinking, and if you are the one making a PR with the changes, you can decide if that seems feasible, and I'm happy to accept any progress 🙂 Right now the x and y positions along a bezier segment are calculated here: p5.js/src/webgl/3d_primitives.js Lines 1598 to 1607 in caa727c
In this, const totalLength = c0.dist(c1) + c1.dist(c2) + c2.dist(c3);
const c1Color = lerpColor(c0Color, c3Color, c0.dist(c1) / totalLength);
const c2Color = lerpColor(c0Color, c3Color, 1 - c2.dist(c3) / totalLength);
const colors = [c0Color, c1Color, c2Color, c3Color]
w_r = colors.map((c) => red(c));
_r =
w_r[0] * this._lookUpTableBezier[i][0] +
w_r[1] * this._lookUpTableBezier[i][1] +
w_r[2] * this._lookUpTableBezier[i][2] +
w_r[3] * this._lookUpTableBezier[i][3];
// etc ...and then in the future we can let people specify fill colors instead of using the default interpolation if they choose. Anyway, if we don't end up doing that now, that's fine too! Like you said, your example images look great as-is. We can just make an issue to add support for it later. |
Thanks for making that side by side comparison! I'll assign the issue to you and take a look at your PR soon. |
Increasing Access
Currently, in webgl, when the fill function is called immediately before the vertex function in immediateMode to determine the color, each vertex is colored and a gradation is applied.
However, doing this for the bezierVertex and quadraticVertex functions would apply the last color set to all vertices added, resulting in nearly identical colors.
This can also be considered one of the uses, but if so, I thought it would be better to make them all the same color.
So, as the default behavior, I thought it would be better to apply interpolation with the color set by the fill function called before the previous vertex, bezierVertex, quadraticVertex function for each vertex.
for example...
bezierSample_Fill
quadraticSample_Fill
My claim is that I want to modify the bezierVertex and quadraticVertex functions in webgl to look like this.
Most appropriate sub-area of p5.js?
Feature request details
Make changes in the following locations:
main/src/webgl/3d_primitives.js
line1552: bezierVertex
line1643: quadraticVertex
Both the bezierVertex function and the quadraticVertex function have the restriction that the vertex function must be called first, so immediateMode.geometry.vertexColors definitely contains some color.
Therefore, I thought that it would be better to take the last color stored in the array as the start point, set the current color as the end point, and interpolate between them to determine the intermediate color.
First, just after setting the LUTLength, get the start and end colors.
Then, in a for loop, calculate the intermediate colors by interpolating these colors by ratio. Assign this to curFillColor each time so it gets applied in the vertex function.
Finally, after the loop finishes, we reset the current color to curFillColor, just in case.
Do this for both the 6 and 9 argument cases.
I would like to apply these changes to both the bezierVertex and quadraticVertex functions.
The text was updated successfully, but these errors were encountered: