-
-
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
WEBGL stroke weight misbehaves after call to perspective() #4214
Comments
Thanks for the well-written issue @jwdunn1 ! This is known behavior. Currently the stroke shader doesn't track the amount of perspective that is applied to the sketch. There are only two states, default perspective and custom perspective. Custom perspectives always use orthographic projection on the stroke. In the example you linked, after clicking, the stroke doesn't get larger further from the camera but instead stays the exact same size while the box itself gets smaller. This behavior begins with this PR which I filed. The PR was a way of fixing broken stroking in custom perspectives. As a blunt solution, stroke perspective was given a simple on or off state. This was done to avoid calculating the mix of perspective to orthographic projection in a user's custom perspective. That said, if you (or anyone) has interest in adding a calculation of the ortho-to-perspective interpolation of a custom perspective then I'd be happy to review. |
Thank you for the information. As an experiment (without knowing the deeper ramifications), I removed the This is the code change I include at the beginning of my sketch to override the v0.10.2 p5.Shader.prototype._setMatrixUniforms = function() {
this.setUniform('uProjectionMatrix', this._renderer.uPMatrix.mat4);
if (this.isStrokeShader()) this.setUniform('uPerspective', 1);
this.setUniform('uModelViewMatrix', this._renderer.uMVMatrix.mat4);
this.setUniform('uViewMatrix', this._renderer._curCamera.cameraMatrix.mat4);
if (this.uniforms.uNormalMatrix) {
this._renderer.uNMatrix.inverseTranspose(this._renderer.uMVMatrix);
this.setUniform('uNormalMatrix', this._renderer.uNMatrix.mat3);
}
}; Examples with this 'fix': |
@jwdunn1 I don't see a problem with that solution for your sketches. Unfortunately, it isn't a general solution because it is possible for a user to make a sketch that has a projection matrix that breaks this. Here is an example that shows this.. If you comment out your prototype override you can see that the ortho is more legible than the incorrect perspective. This is a situation where a fix introduces another problem. The thought with introducing this behavior was that orthographic stroke projection was a safer assumption for custom perspective, but perhaps it is better to assume perspective projection. It is difficult to say which problem will present itself more, or be more obtrusive, but I am open to arguments either way. The only true fix, as I said in my earlier comment, would be a calculation of where a custom perspective is on an interpolation between orthographic and perspective, but I don't know how to do that easily. |
I have come up with an approach to calculate the interpolation value. Please let me know if I am going in the right direction or not ..! @davepagurek @stalgiag , I would love to have your suggestions on this .. |
Could you describe the bounding box method you're mentioning @Garima3110? Also, in case it's useful, Another option we have is just to add a way to manually set whether or not lines should have perspective, e.g. |
I thought maybe we could do something like getting the dimensions of the bounding box, and then finding the max of all these dimensions (length ,breadth ,height) to get the max distance for perspective scaling. |
This too sounds good, I'll just look into its implementation and get back to you soon.. |
I don't think we currently do. This seems like a useful feature for other reasons like physics simulations or shape packing, but I'm imagining how it might get used for line perspective. If the perspective changes per object, that probably isn't what we want, as all the objects in the scene would potentially have different line perspectives, which might look inconsistent. If we base it on the bounding box of everything in the scene, then on a single frame things look consistent, but as objects move over time, the bounding box will change, and the line perspective will change accordingly, and then lines might look inconsistent over time, which is also not ideal. So whatever we do, I think it would need to be (by default anyway) consistent across all objects in the scene, and consistent over time as the objects move. Basing it on camera settings might do that, but also it might just be easier to let users pick for themselves. |
Thanks for your insights on this @davepagurek ! I'll just start working on this approach. |
Thank you, this appears to be fixed! |
After perspective() is called, stroke weights become unexpectedly thin near the camera while objects far away are stroked too thickly. I noticed this on another sketch I was building with a roving camera. For reporting purposes, I've created a minimal sketch to illustrate the problem.
Nature of issue?
Most appropriate sub-area of p5.js?
Which platform were you using when you encountered this?
Details about the bug:
The stroke weights work correctly with perspective() in v0.9.0 and earlier.
Sketch code is below:
The text was updated successfully, but these errors were encountered: