Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error in mat3.inverse(), and suggestion #18

Open
davidjeck opened this issue Jun 6, 2023 · 2 comments
Open

error in mat3.inverse(), and suggestion #18

davidjeck opened this issue Jun 6, 2023 · 2 comments

Comments

@davidjeck
Copy link

It seems like mat3.inverse() in version 2.4.0 actually computes the transpose of the inverse. mat4.inverse() is OK. I was trying to use gpu-matrix to compute a normal vector transformation matrix -- a mat3.normalMatrixFromMat4() function would be a good addition.

<script src="wgpu-matrix.js"></script> <script> let matrix = wgpuMatrix.mat3.create( 1,0,0, 0,1,0, 2,3,1 ); console.log( wgpuMatrix.mat3.multiply( matrix, wgpuMatrix.mat3.inverse(matrix) ) ); // does not output the identity matrix console.log( wgpuMatrix.mat3.multiply( matrix, wgpuMatrix.mat3.transpose(wgpuMatrix.mat3.inverse(matrix)) ) ); // outputs the identity matrix matrix = wgpuMatrix.mat4.create( 1,0,0,0, 0,1,0,0, 0,0,1,0, 2,3,4,1 ); console.log( wgpuMatrix.mat4.multiply( matrix, wgpuMatrix.mat4.inverse(matrix) ) ); // outputs the identity matrix </script>
@greggman
Copy link
Owner

greggman commented Jun 7, 2023

fixed

As for normalMatrixFromMat4, yea, I can see the point. I'd probably name it mat3.fromMat4Transpose or something like that.

@davidjeck
Copy link
Author

Thanks, that was fast. This now works for computing the normal transformation matrix from the modelview matrix:

        wgpuMatrix.mat3.fromMat4(modelview,normalMatrix);
        wgpuMatrix.mat3.inverse(normalMatrix,normalMatrix);
        wgpuMatrix.mat3.transpose(normalMatrix,normalMatrix);

I will use wgpu-matrix for 3D WebGPU graphics in the next version of my on-line computer graphics textbook.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants