Skip to main content

unratio: Aspect Ratio Inverse Transform

Coordinate denormalization for aspect ratio correction

The unratio function performs the inverse transformation of aspect ratio correction, converting normalized coordinates back to their original aspect ratio space.

Given input coordinates st and screen dimensions s, the function applies:

unratio(st,s)=(st.xst.ys.xs.y+s.y0.5s.x0.5s.y)\text{unratio}(st, s) = \begin{pmatrix} st.x \\ st.y \cdot \frac{s.x}{s.y} + \frac{s.y \cdot 0.5 - s.x \cdot 0.5}{s.y} \end{pmatrix}

This transformation adjusts the Y-coordinate to restore the original aspect ratio distortion, undoing previous ratio correction.

Function Signature

FunctionInput TypesOutput TypeDescription
unratiovec2, vec2vec2Inverse aspect ratio correction

Parameters

  • st: Input coordinates to transform
  • s: Screen dimensions (width, height)
Live Editor
const fragment = () => {
      const coords = uv.sub(0.5)
      const restored = unratio(coords, iResolution)
      const color = restored.add(0.5).abs()
      return vec4(color, 0.5, 1)
}