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 » Wed Jun 23, 2010 8:16 am

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:
0 x

Fulmens
Gremlin
Posts: 151
Joined: Sun Jun 22, 2008 8:29 pm
Location: Nantes, France

Re: How about using quaternion instead of matrix?

Post by Fulmens » Wed Jun 23, 2010 8:54 am

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 ?)
0 x

User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany

Re: How about using quaternion instead of matrix?

Post by xadhoom » Wed Jun 23, 2010 8:55 am

Do you mean like the Ogre::Quaternion??

xad

Edit: Ah, Fulmens beat me :wink:
0 x

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 » Wed Jun 23, 2010 9:54 am

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.
0 x

User avatar
xadhoom
Minaton
Posts: 973
Joined: Fri Dec 28, 2007 4:35 pm
Location: Germany

Re: How about using quaternion instead of matrix?

Post by xadhoom » Wed Jun 23, 2010 5:02 pm

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
0 x

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

Re: How about using quaternion instead of matrix?

Post by xavier » Wed Jun 23, 2010 5:17 pm

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.
0 x
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
Contact:

Re: How about using quaternion instead of matrix?

Post by _tommo_ » Thu Jun 24, 2010 10:17 am

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.
0 x
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

Re: How about using quaternion instead of matrix?

Post by xavier » Thu Jun 24, 2010 4:50 pm

_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.
0 x
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
Contact:

Re: How about using quaternion instead of matrix?

Post by _tommo_ » Thu Jun 24, 2010 6:55 pm

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
0 x
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 » Sat Jun 26, 2010 1:42 pm

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.
0 x

cyrfer
Orc
Posts: 424
Joined: Wed Aug 01, 2007 8:13 pm
Location: Venice, CA, USA

Re: How about using quaternion instead of matrix?

Post by cyrfer » Wed Jul 07, 2010 2:48 am

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.
0 x

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
Contact:

Re: How about using quaternion instead of matrix?

Post by Praetor » Wed Jul 07, 2010 1:23 pm

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.
0 x
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

Re: How about using quaternion instead of matrix?

Post by cyrfer » Wed Jul 07, 2010 6:44 pm

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.
0 x

Post Reply