You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I previously fixed the triangle() bug in webgl in #5977. However, I had some misunderstandings.
First, regarding beginShape() to endShape(), the direction of the normal line is the front direction regardless of the order in which the vertices are specified.
This is also true for 1.4.0. Therefore, it was not suitable for comparison. quad() should be compared. As you can see from the code introduced above, quad() correctly calculates the normals for the specified order of vertices.
But triangle() does not. Regardless of the specified order of vertices, the normal is always toward front.
In fact, in previous versions, the normals were always toward opposite to front regardless of the order in which the vertices were specified. I wasn't aware of this.
You can see this by running the above code on 1.4.0 and 1.5.0.
It's convenient to have the lights brighter regardless of the order specified, but it's not consistent to quad(), so it might be better to fix it.
Fixing it is easy. This is because the (3,3) component is always 1 in the matrix internally used to draw triangles used to temporarily change the uMVMatrix. Therefore, the result of the normal calculation is always (0,0,1).
constmult=newp5.Matrix([x2-x1,y2-y1,0,0,// the resulting unit X-axisx3-x1,y3-y1,0,0,// the resulting unit Y-axis0,0,1,0,// the resulting unit Z-axis (unchanged)x1,y1,0,1// the resulting origin]).mult(this.uMVMatrix);
Change this to reflect the order in which vertices are specified.
This computes the z component of the cross product of the vectors.
constorientation=Math.sign(x1*y2-x2*y1+x2*y3-x3*y2+x3*y1-x1*y3);constmult=newp5.Matrix([x2-x1,y2-y1,0,0,// the resulting unit X-axisx3-x1,y3-y1,0,0,// the resulting unit Y-axis0,0,orientation,0,// the resulting unit Z-axis (unchanged)x1,y1,0,1// the resulting origin]).mult(this.uMVMatrix);this.uMVMatrix=mult;
Now the normal directions will be calculated according to the specified order.
The text was updated successfully, but these errors were encountered:
Most appropriate sub-area of p5.js?
p5.js version
1.6.0
Web browser and version
Microsoft Edge
Operating System
Windows11
Steps to reproduce this
Steps:
Snippet:
triangle()_debug
output:
I previously fixed the triangle() bug in webgl in #5977. However, I had some misunderstandings.
First, regarding beginShape() to endShape(), the direction of the normal line is the front direction regardless of the order in which the vertices are specified.
This is also true for 1.4.0. Therefore, it was not suitable for comparison. quad() should be compared. As you can see from the code introduced above, quad() correctly calculates the normals for the specified order of vertices.
But triangle() does not. Regardless of the specified order of vertices, the normal is always toward front.
In fact, in previous versions, the normals were always toward opposite to front regardless of the order in which the vertices were specified. I wasn't aware of this.
You can see this by running the above code on 1.4.0 and 1.5.0.
It's convenient to have the lights brighter regardless of the order specified, but it's not consistent to quad(), so it might be better to fix it.
Fixing it is easy. This is because the (3,3) component is always 1 in the matrix internally used to draw triangles used to temporarily change the uMVMatrix. Therefore, the result of the normal calculation is always (0,0,1).
triangle
Change this to reflect the order in which vertices are specified.
This computes the z component of the cross product of the vectors.
Now the normal directions will be calculated according to the specified order.
The text was updated successfully, but these errors were encountered: