Skip to content

Function: syncViewportUniforms() ​

ts
function syncViewportUniforms(uniforms, renderer): boolean;

Experimental

Make viewport uniforms match what the renderer is actually drawing into. Primitives call this from onBeforeRender, so it runs for every draw with the GL viewport already set.

  • uViewport (device px) is always synced: gl_FragCoord is relative to it.
  • On the canvas, uResolution / uPixelRatio are derived from it too. Without this, a primitive added to a scene without Primitive.setViewport kept the 1×1 default resolution, so every screen-space quad covered the whole canvas (spike B: seconds of GPU time per frame).
  • Render targets (picking, export) keep the logical size given via setViewport, since their pixel ratio is not the renderer's.

Returns true when the CSS resolution or pixel ratio changed.

Parameters ​

ParameterType
uniformsPick<ViewportUniforms, "uResolution" | "uPixelRatio"> & object
rendererViewportSource

Returns ​

boolean

Released under the MIT License.