cameraViewport
Provides the viewport rectangle of the camera used for the current render as vec4(x, y, width, height). With ArrayCamera it returns the active sub-camera viewport; with a single camera it falls back to (0, 0, screenSize.x, screenSize.y).
Core Advantages
Per-camera viewport access that stays correct for split-screen, multi-view, and stereo without manual uniforms. Works with cameraIndex and renderGroup, and is cacheable.
Common Uses
Build camera-local screen UVs or masks in split-screen/PiP
Per-eye or per-view post-effects in VR/multi-view
Camera-local coordinate math when stitching multiple viewports in one frame
Debugging: draw a border/label for each camera
How to adjust
Read-only. Adjust by math on its vec4 output: e.g. (pixel.xy - xy) / (zw) to get camera-local UV, or use cv.zw for pixel-to-UV conversions. With a single camera it is equivalent to viewport.
Code Examples
1// Get camera viewport and make normalized UV inside it
2const cv = cameraViewport; // vec4(x, y, w, h)
3const pixel = positionVarying.xy; // screen pixel coord
4const uvInCamera = pixel.sub( cv.xy ).div( cv.zw );
5
6// Use uvInCamera to make a split-screen-safe gradient
7return vec3( uvInCamera.x, 0, uvInCamera.y.oneMinus() );