From: <c.schueler@ph...>  20050429 13:37:39

I guess it's not very optimal since there seems to be a longer = dependency chain on scalar values. HLSL says this float4 q; float4 test( float3 v : POSITION ) : POSITION { float3 w =3D q.xyz; float3 vww =3D dot(v,w)*w; float3 res =3D 2.f * (vww + (q.w*q.w  0.5f) * v + q.w*cross(v,w) ); return float4( res, 1 ); } // "q" is c1 vs_1_1 def c0, 0.5, 1, 0, 0 dcl_position v0 mov r0.x, c1.w mad r0.w, r0.x, r0.x, c0.x mul r1.xyz, r0.w, v0 dp3 r2.x, v0, c1 mul r0.xyz, v0.zxyw, c1.yzxw mad r1.xyz, r2.x, c1, r1 mad r0.xyz, v0.yzxw, c1.zxyw, r0 mad r0.xyz, c1.w, r0, r1 add oPos.xyz, r0, r0 mov oPos.w, c0.y Original Message From: gdalgorithmslistadmin@... = [mailto:gdalgorithmslistadmin@...] On Behalf Of = Willem de Boer Sent: Friday, April 29, 2005 3:23 PM To: gdalgorithmslist@... Subject: RE: [Algorithms] Fastest way to rotate a vector by a quaternion = in a shader > ...? > I count 6 instructions: Sure, I was just comparing methods by counting the number of _actual_ additions and multiplications they take up; I wasn't = counting vertex shader instructions. I'm not very good at handoptimising vertex shader assembly, if someone more in the know could translate the following routine into = assembly, we can start comparing instruction counts: > float3 RotateVector3ByQuaternion( float3 v, float4 q ) { > w =3D q.xyz; > float3 vww =3D dot(v,w)*w; > float3 res =3D 2.f * (vww + > (q.w*q.w  0.5f) * v + > q.w*cross(v,w) > ); > return res; > } Cheers, Willem  SF.Net email is sponsored by: Tell us your software development plans! = Take this survey and enter to win a oneyear sub to SourceForge.net Plus = IDC's 2005 lookahead and a copy of this survey Click here to start! = http://www.idcswdc.com/cgibin/survey?id=105hix _______________________________________________ GDAlgorithmslist mailing list GDAlgorithmslist@... https://lists.sourceforge.net/lists/listinfo/gdalgorithmslist Archives: http://sourceforge.net/mailarchive/forum.php?forum_ida88 