-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
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
WebGLRenderer: Change scissor, viewport functions to use "round" instead of "floor" #27703
Conversation
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
What I started doing for these cases is to download the screenshot that the CI generated and add it to the PR... 😇 You can get it here: |
#18326 may need to be revisited if this is merged. It was required because of the use of |
Well, it should be pretty obvious with a Pixel and this example: #18265 (comment) I can't test just now either, but I will once I pull this into MV. |
Looking at the PR - it might be best to set the viewport settings on the render target rather than the renderer. Setting the viewport on the render target itself (here) allows you to set exact pixel values instead of dealing with these rounding issues and DPR. The discrepancy in behavior when dealing with WebGLRenderTarget.viewport and WebGLRenderer.setViewport (and scissor) is fairly confusing and it might be worth looking into how to simplify this another time. |
Examples like https://threejs.org/examples/#webgl_multiple_elements rely on being able to set scissor and viewports that extend partially offscreen, so +1 for not clamping this. 🙂 |
@gkjohnson Do you mind temporarily updating the build files in this PR? I can make a test with a Pixel 4a which has a device pixel ratio of |
In #18447 the |
@@ -489,7 +489,7 @@ class WebGLRenderer { | |||
|
|||
} | |||
|
|||
state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor() ); | |||
state.viewport( _currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).round() ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In at least six other instances in the code, floor()
is still used when applying pixelRatio
. Was this an oversight, or was this intentional?
/ping @Mugen87
/ping @gkjohnson
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To me that is an oversight. When looking at the code, the usage in setRenderTarget()
should be updated to round()
as well.
three.js/src/renderers/WebGLRenderer.js
Lines 2286 to 2287 in 0bc990f
_currentViewport.copy( _viewport ).multiplyScalar( _pixelRatio ).floor(); | |
_currentScissor.copy( _scissor ).multiplyScalar( _pixelRatio ).floor(); |
Not sure about getDrawingBufferSize()
though.
three.js/src/renderers/WebGLRenderer.js
Line 412 in 0bc990f
return target.set( _width * _pixelRatio, _height * _pixelRatio ).floor(); |
Depending on how we decide, the code in examples/jsm/renderers/common/Renderer.js
should be updated accordingly.
Fixed #27655
Description
Use "round" instead of "floor" to compute the scissor and viewport functions to prevent rounding errors. From the WebGL spec there doesn't seem to be any requirement that the max value be within the width of the canvas so no value clamp has been added.