Skip to content
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

TSL: Introduce screenUV, screenSize, screenCoordinate and viewport revision #29347

Merged
merged 14 commits into from
Sep 7, 2024

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Sep 6, 2024

Related issue: Closes #29162

Description

viewportSize, viewportCoordinate, viewportUV, followed the logic related to viewport, while screenUV, screenSize and screenCoordinate followed the logic used previously and screen* considering the framebuffer.

Screen

Node Description
screenUV unitless in [ 0, 1 ] - normalized screen coordinates
screenSize physical pixel units - framebuffer width,height resolution.
screenCoordinate physical pixel units - framebuffer current x,y pixel position.

Viewport

Node Description
viewportUV unitless in [ 0, 1 ] - normalized viewport coordinates
viewport physical pixel units - viewport rectangle x,y,width,height
viewportSize physical pixel units - viewport width,height resolution.
viewportCoordinate physical pixel units - viewport current x,y pixel position.

@sunag sunag added this to the r169 milestone Sep 6, 2024
Copy link

github-actions bot commented Sep 6, 2024

📦 Bundle size

Full ESM build, minified and gzipped.

Before After Diff
WebGL 685.18
169.62
685.18
169.62
+0 B
+0 B
WebGPU 825.96
221.44
826.2
221.55
+241 B
+113 B
WebGPU Nodes 825.54
221.34
825.78
221.46
+241 B
+118 B

🌳 Bundle size after tree-shaking

Minimal build including a renderer, camera, empty scene, and dependencies.

Before After Diff
WebGL 461.96
111.46
461.96
111.46
+0 B
+0 B
WebGPU 525.27
141.52
525.3
141.56
+25 B
+36 B
WebGPU Nodes 481.93
131.34
481.95
131.37
+25 B
+28 B

@WestLangley
Copy link
Collaborator

viewport | physical pixel units - viewport rectangle x, y, width, height
viewportSize | physical pixel units - viewport width, height resolution.

renderer.viewport is in logical pixel units. The viewport coordinates define the affine transformation from NDC coordinates to window coordinates.

I think it would be odd if viewport was in physical units and scaled by pixel ratio. A viewport knows nothing about pixel ratio.

@sunag
Copy link
Collaborator Author

sunag commented Sep 7, 2024

The viewport must represent the entire hierarchy that follows. It would be strange and confusing for the user if viewport was logical pixel units and the rest were not. Just as renderer.getSize() is logical pixel units and viewportSize and screenSize are physical pixel units, for shaders we must have physical pixel units as default.

@sunag sunag marked this pull request as ready for review September 7, 2024 13:44
@sunag sunag merged commit 8ebbaba into mrdoob:dev Sep 7, 2024
12 checks passed
@sunag sunag deleted the dev-viewport-1 branch September 7, 2024 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ViewportNode: Honor the renderer viewport
2 participants