How about using quaternion instead of matrix?

What it says on the tin: a place to discuss proposed new features.
Post Reply
User avatar
LangFox
Gnoblar
Posts: 7
Joined: Mon Dec 28, 2009 10:11 am
Location: Shenzhen, China.
Contact:

How about using quaternion instead of matrix?

Post by LangFox »

http://code.google.com/p/kri/wiki/Quaternions
Quaternion can be used instead of matrix, like vector transform or skinned animation. It's small and fast.
Hope Ogre could integrate quaternion into shader pipeline. :idea:
Fulmens
Gremlin
Posts: 151
Joined: Sun Jun 22, 2008 8:29 pm
Location: Nantes, France
x 1

Re: How about using quaternion instead of matrix?

Post by Fulmens »

http://www.ogre3d.org/docs/api/html/cla ... rnion.html

As for quaternion in shaders...it's more the shading language area (Cg/HLSL/GLSL).
(Does shader runtime already have quaternion manipulation functions, or are they limited to matrix ?)
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Re: How about using quaternion instead of matrix?

Post by xadhoom »

Do you mean like the Ogre::Quaternion??

xad

Edit: Ah, Fulmens beat me :wink:
User avatar
LangFox
Gnoblar
Posts: 7
Joined: Mon Dec 28, 2009 10:11 am
Location: Shenzhen, China.
Contact:

Re: How about using quaternion instead of matrix?

Post by LangFox »

No, I hope Ogre could update some shader parameters with quaternion, not matrix.
For example, use world_quat to give vertex shader a quaternion for world transform, and use bone_quat to give quaternions for hardware skinning.
Then Ogre will send much less data from CPU to GPU, when doing skinned animation or instanced drawing.
User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany
x 1

Re: How about using quaternion instead of matrix?

Post by xadhoom »

I fear this would have a huge impact to the current Scenegraph system of Ogre and I´m not sure if the limitation of having uniform scales only would be feasable. Providing both approaches might be a solution by using compilation defines or proper subclassing but this would probably introduce a significant maintenance overhead.

xad
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: How about using quaternion instead of matrix?

Post by xavier »

LangFox wrote:No, I hope Ogre could update some shader parameters with quaternion, not matrix.
For example, use world_quat to give vertex shader a quaternion for world transform, and use bone_quat to give quaternions for hardware skinning.
Then Ogre will send much less data from CPU to GPU, when doing skinned animation or instanced drawing.
This is an ill-informed request. The problem is that there are no instructions on GPU hardware for dealing with quaternions (as you can tell from all of the code they have to supply for using quaternions in a shader), whereas all you need for dealing with matrix/vector operations is present in hardware.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
_tommo_
Gnoll
Posts: 677
Joined: Tue Sep 19, 2006 6:09 pm
x 5
Contact:

Re: How about using quaternion instead of matrix?

Post by _tommo_ »

xavier wrote: This is an ill-informed request. The problem is that there are no instructions on GPU hardware for dealing with quaternions (as you can tell from all of the code they have to supply for using quaternions in a shader), whereas all you need for dealing with matrix/vector operations is present in hardware.
Uhm, this is true, but on more recent GPUs the matrix and vector code is anyway trimmed down to parallel float operations... so having to do only four of them instead of 16 could be a real advantage?
Surely it wouldn't be big anyway, as 99% of the shaders is not float limited but bandwidth limited.
OverMindGames Blog
IndieVault.it: Il nuovo portale italiano su Game Dev & Indie Games
User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Re: How about using quaternion instead of matrix?

Post by xavier »

_tommo_ wrote:
xavier wrote: This is an ill-informed request. The problem is that there are no instructions on GPU hardware for dealing with quaternions (as you can tell from all of the code they have to supply for using quaternions in a shader), whereas all you need for dealing with matrix/vector operations is present in hardware.
Uhm, this is true, but on more recent GPUs the matrix and vector code is anyway trimmed down to parallel float operations... so having to do only four of them instead of 16 could be a real advantage?
Surely it wouldn't be big anyway, as 99% of the shaders is not float limited but bandwidth limited.
Actually, in terms of the assembler, most matrix/vector multiplies are done as 3 or 4 dot products into a swizzle -- no need for all of the extra math I see in the code link. So a float4x4/float4 is already only 4 operations. On top of that, the fixed-function bits of the hardware are designed to use matrices, so you have to provide matrices anyway.
Do you need help? What have you tried?

Image

Angels can fly because they take themselves lightly.
User avatar
_tommo_
Gnoll
Posts: 677
Joined: Tue Sep 19, 2006 6:09 pm
x 5
Contact:

Re: How about using quaternion instead of matrix?

Post by _tommo_ »

xavier wrote:Actually, in terms of the assembler, most matrix/vector multiplies are done as 3 or 4 dot products into a swizzle -- no need for all of the extra math I see in the code link. So a float4x4/float4 is already only 4 operations. On top of that, the fixed-function bits of the hardware are designed to use matrices, so you have to provide matrices anyway.
Ok those are good points, i forgot that shaders are 4-wide...
I will save the quaternions for my GPGPU render :D
OverMindGames Blog
IndieVault.it: Il nuovo portale italiano su Game Dev & Indie Games
debdatta_basu
Kobold
Posts: 31
Joined: Thu Jun 10, 2010 4:32 am

Re: How about using quaternion instead of matrix?

Post by debdatta_basu »

On current gen hardware, there is no reason to use quaternions for ordinary transforms.... However, in certain cases, Quaternion based transforms provide better results..

Look up dual quaternion skinning.... I agree this would be a nice option to have, albeit if only for skinning.
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

Re: How about using quaternion instead of matrix?

Post by cyrfer »

xavier wrote: On top of that, the fixed-function bits of the hardware are designed to use matrices, so you have to provide matrices anyway.
Does this apply if you are using shaders? I don't see why matrix is required if you have your own vertex and pixel shaders. This seems like a reasonable request at least to prepare for when fixed function is not supported.
User avatar
Praetor
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 3335
Joined: Tue Jun 21, 2005 8:26 pm
Location: Rochester, New York, US
x 3
Contact:

Re: How about using quaternion instead of matrix?

Post by Praetor »

Code: Select all

vec = mul(myMat, vec);
The mul shader instruction is designed to multiply with matrices. It has a low-level implementation. You'd have to create custom implementations to handle quaternions which likely would not be as fast. Still, quaternions can be interesting. There's some skinning research using quaternions that shows promise. But, without it being supported from hardware it will probably lose out on speed.
Game Development, Engine Development, Porting
http://www.darkwindmedia.com
cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA
x 7

Re: How about using quaternion instead of matrix?

Post by cyrfer »

Praetor wrote:But, without it being supported from hardware it will probably lose out on speed.
I don't think the only point is speed. Quaternions can make it easier to do some operations (not talking about matrix multiplication), and may be faster for those operations (if that matters). Also, a quaternion can be delivered as a single uniform (float4) while a matrix is at least 3 uniforms. I provide per-instance rotations via quaternion maps when using hardware instancing, so it makes sense to delivery a parent transformation in a quaternion, avoiding the need to convert every local transformation into a matrix before calculating the combined orientation.
Post Reply