toji/gl-matrix

Missing frustumZO method

AshleyScirra opened this issue · 1 comments

When using perspective with an off-axis projection, mat4.frustum is used instead of mat4.perspective. In v3.4.1 there's a mat4.perspectiveZO method for WebGPU, but no mat4.frustum. So web apps using an off-axis projection are missing a way to use the right matrix for WebGPU in glMatrix.

Figured out a workaround from the code referenced in #369:

const matWebGLtoWebGPU = mat4.fromValues(
    1, 0,   0, 0,
    0, 1,   0, 0,
    0, 0, 0.5, 0,
    0, 0, 0.5, 1,
);

// Calculate WebGL matrix (Z range [-1, 1])
mat4.frustum(outMat, /* ... */);

// Convert to WebGPU matrix (Z range [0, 1])
if (isWebGPU)
    mat4.mul(outMat, matWebGLtoWebGPU, outMat);

Hopefully an easy add for a glMatrix frustumZO method?