Instanced Geometry Vertex Shader Question

You can rotate a vector by a quaternion with this shader function:

vec3 applyQuaternionToVector( vec4 q, vec3 v ){
    return v + 2.0 * cross( q.xyz, cross( q.xyz, v ) + q.w * v );
}

The math is explained in this blog post: http://www.geeks3d.com/20141201/how-to-rotate-a-vertex-by-a-quaternion-in-glsl/

I’m not sure why the calculation in the example slightly differs from this code. If I use applyQuaternionToVector() in the example, I get the exact same visual output.

2 Likes