Vector Cross Product Uses?

Right! @Apollo once showed me this technique but I didn’t pay enough attention at the time to realize it contained a cross product. In case anyone wants to try it out:

You make a simple quad, but you only pass the center as the vertex position and set the scale (in world units) as texCoord2, like so:

texCoord2=new Vector2f[]{
  new Vector2f(-100.0f, -100.0f),
  new Vector2f(100.0f, -100.0f),
  new Vector2f(100.0f, 100.0f), 
  new Vector2f(-100.0f, 100.0f), 
};

And this goes into the vertex shader:

 // Calculate left and up vectors of the billboard quad.
 vec3 u=normalize(cross(m_CameraUp, g_CameraDirection));
 vec3 v=cross(g_CameraDirection, u);
 // Drag the vertex away from the billboard center.
 vec4 wPos=g_WorldMatrix*inPosition;
 wPos.xyz+=-u*inTexCoord2.x+v*inTexCoord2.y;
 gl_Position=g_ViewProjectionMatrix*wPos;

and voilà, billboard quad from the vertex shader. :sunglasses:

Neat trick :wink:

Btw, does a version of this happen to be integrated in the Particle.j3md? Sounds like something that the emitter could fully control.

2 Likes