How about using quaternion instead of matrix?
- LangFox
- Gnoblar
- Posts: 7
- Joined: Mon Dec 28, 2009 10:11 am
- Location: Shenzhen, China.
- Contact:
How about using quaternion instead of matrix?
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.
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.
-
- Gremlin
- Posts: 151
- Joined: Sun Jun 22, 2008 8:29 pm
- Location: Nantes, France
- x 1
Re: How about using quaternion instead of matrix?
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 ?)
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 ?)
- xadhoom
- Minaton
- Posts: 973
- Joined: Fri Dec 28, 2007 4:35 pm
- Location: Germany
- x 1
- LangFox
- Gnoblar
- Posts: 7
- Joined: Mon Dec 28, 2009 10:11 am
- Location: Shenzhen, China.
- Contact:
Re: How about using quaternion instead of matrix?
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.
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.
- xadhoom
- Minaton
- Posts: 973
- Joined: Fri Dec 28, 2007 4:35 pm
- Location: Germany
- x 1
Re: How about using quaternion instead of matrix?
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
xad
- xavier
- 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?
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.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.
- _tommo_
- Gnoll
- Posts: 677
- Joined: Tue Sep 19, 2006 6:09 pm
- x 5
- Contact:
Re: How about using quaternion instead of matrix?
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?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.
Surely it wouldn't be big anyway, as 99% of the shaders is not float limited but bandwidth limited.
- xavier
- 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?
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._tommo_ wrote: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?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.
Surely it wouldn't be big anyway, as 99% of the shaders is not float limited but bandwidth limited.
- _tommo_
- Gnoll
- Posts: 677
- Joined: Tue Sep 19, 2006 6:09 pm
- x 5
- Contact:
Re: How about using quaternion instead of matrix?
Ok those are good points, i forgot that shaders are 4-wide...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.
I will save the quaternions for my GPGPU render
-
- Kobold
- Posts: 31
- Joined: Thu Jun 10, 2010 4:32 am
Re: How about using quaternion instead of matrix?
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.
Look up dual quaternion skinning.... I agree this would be a nice option to have, albeit if only for skinning.
-
- 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?
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.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.
- Praetor
- 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?
Code: Select all
vec = mul(myMat, vec);
Game Development, Engine Development, Porting
http://www.darkwindmedia.com
http://www.darkwindmedia.com
-
- 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?
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.Praetor wrote:But, without it being supported from hardware it will probably lose out on speed.