View Full Version : matrix inverse
06-06-2005, 10:33 PM
What is the better choice to compute a matrix inverse in a shader -on gpu- or in the program
06-07-2005, 02:41 AM
Depends on what you're doing.
There are some inbuilt matrices readily available, no need to build those.
If the matrix doesn't change per vertex or per fragment (ouch) there is no need to build it inside a shader.
If it does, build it where appropriate.
A general matrix inversion will be costly. Some special cases are just a transposition.
If your talking about general purpose GPU matrix inversion algorithms, that's a different topic.
06-07-2005, 02:43 AM
If you change your matrix very often it may be better to calculate in a shader, otherwise it's better to calculate on the CPU.
For example, if you have a matrix that is only changed once per model, it is better to calculate the inverse once on the CPU that to calculate it for every vertex on the GPU. But if you have a matrix that changes for every vertex, it may be better to calculate it in the vertex shader.
As a rule of thumb, prefer the method that is as far as possible on top of this list:
- precalculate once at loading time
- calculate once per batch on the CPU
- calculate in the vertex shader
- calculate in the fragment shader
Of course "as far as possible" means without sacrificing accuracy ;) .
You may trade bandwith for computation power by calculating something in the vertex shader so you need less per vertex attributes. So if your matrix is per vertex but static, you could try to move your calculation to the shader and see if it improves something...
Doh... 2 minutes late :D
Powered by vBulletin® Version 4.2.2 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.