SquareFeet
SquareFeet

Reputation: 641

THREE.js - Billboard Vertex Shader

I have the need to orientate an instance of THREE.Mesh to always face the camera. I know I could just use the [THREE.Mesh].lookAt() method, but I'm trying to work on my GLSL chops a bit more and want to be able to do this in a vertex shader.

I've read through NeHe's Billboarding tutorial, and it makes sense to me. Well, all apart from the bit where one applies these orientation vectors to each vertex.

I feel like I'm very close to getting this working, but as it stands at the moment, my vertex shader is looking more like a 90s rave video than a billboard:

Progress so far fiddle: http://jsfiddle.net/RZ4XE/2/

Below is my vertex shader (the fragment shader just assigns a vec4 color). It's making use of various default uniforms / attributes that THREE.js provides, listed below just in case someone unfamiliar with THREE.js is reading this :)

Thanks in advance.

Upvotes: 3

Views: 3931

Answers (1)

Kyle Paulsen
Kyle Paulsen

Reputation: 1006

Apparently this works:

gl_Position = projectionMatrix * (modelViewMatrix * vec4(0.0, 0.0, 0.0, 1.0) + vec4(position.x, position.y, 0.0, 0.0));

I'm actually trying to figure out how to do axis aligned billboards.

Upvotes: 6

Related Questions