Skip to content

Instantly share code, notes, and snippets.

@mattdesl
Created January 18, 2017 22:52
Show Gist options
  • Save mattdesl/67838c69c22218242cadf4f5d0721d42 to your computer and use it in GitHub Desktop.
Save mattdesl/67838c69c22218242cadf4f5d0721d42 to your computer and use it in GitHub Desktop.
billboarding in GLSL
attribute vec3 position;
uniform mat4 modelViewMatrix;
uniform mat4 modelMatrix;
uniform mat4 projectionMatrix;
uniform float scale;
uniform float size;
uniform float aspect;
varying vec2 vUv;
void main() {
vec2 scale = vec2(
length(modelViewMatrix[0]) / aspect,
length(modelViewMatrix[1])
);
vec4 billboard = (modelViewMatrix * vec4(vec3(0.0), 1.0));
vec4 newPosition = projectionMatrix
* billboard
+ vec4(scale * position.xy, 0.0, 0.0);
gl_Position = newPosition;
vUv = vec2(position.x + 0.5, position.y + 0.5);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment