-
-
Save Samsy/5d5c4ad2d92c365de3641de7569c55e2 to your computer and use it in GitHub Desktop.
billboarding in GLSL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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