perspective: Perspective Projection Matrix
3D perspective transformation
The perspective projection creates a 4×4 transformation matrix that maps a 3D frustum to normalized device coordinates with depth perspective. Objects further from the camera appear smaller, creating realistic 3D depth perception:
The resulting coordinates require perspective division by the w-component to obtain final NDC.
Parameter Definitions
Parameter | Description | Range |
---|---|---|
fov | Vertical field of view (radians) | |
aspect | Width/height aspect ratio | |
near | Near clipping plane distance | |
far | Far clipping plane distance |
ライブエディター
const fragment = () => { const fov = sin(iTime).mul(0.8).add(1.5) const proj = perspective(fov, 1, 0.1, 10) const coord = vec3(uv.sub(0.5).mul(2), 2) const transformed = proj.mul(vec4(coord, 1)) const depth = transformed.w.div(10) const color = vec3(depth, abs(transformed.xy).mul(0.5)) return vec4(color, 1) }