Hi,

I am stuck at converting something done in CPU to a compute shader program, i’m a bit new to this,

i was wondering if someone can help me figure out how i can write Quaternion*Vector3 , which is basically a vector rotation

Please help,

Hi,

I am stuck at converting something done in CPU to a compute shader program, i’m a bit new to this,

i was wondering if someone can help me figure out how i can write Quaternion*Vector3 , which is basically a vector rotation

Please help,

anyone, any help is appreciated

Try a google search for HLSL quaternion rotation, you’ll find a couple of examples.

1 Like

found this and it works like charm

thanx

```
float4 qmul(float4 q1, float4 q2)
{
return float4(
q2.xyz * q1.w + q1.xyz * q2.w + cross(q1.xyz, q2.xyz),
q1.w * q2.w - dot(q1.xyz, q2.xyz)
);
}
// Vector rotation with a quaternion
// http://mathworld.wolfram.com/Quaternion.html
float3 rotate_vector(float3 v, float4 r)
{
float4 r_c = r * float4(-1, -1, -1, 1);
return qmul(r, qmul(float4(v, 0), r_c)).xyz;
}
```

3 Likes