Skip to content

Instantly share code, notes, and snippets.

@Samsy
Forked from mattdesl/billboard.glsl
Created January 19, 2017 10:53
Show Gist options
  • Save Samsy/5d5c4ad2d92c365de3641de7569c55e2 to your computer and use it in GitHub Desktop.
Save Samsy/5d5c4ad2d92c365de3641de7569c55e2 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