Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GLSL | Billboard shader, keep the scaling

Tags:

math

opengl

glsl

I have searched the internet for tutorials, implementations and help. Nothing.

The only thing I can find is billboard shader implementations that set the upper-left 3x3 matrix of a mat4 to identity. This does throw away the rotation, but effectively also the scaling.

Is there a way to do billboarding that does not throw away (non-uniform) scaling?

Note: I am not looking for anyone to do my programming for me. It's just that I can't wrap my head around the specifics. Any pointers in the right direction are welcome.

like image 545
Stijn Frishert Avatar asked Apr 10 '13 22:04

Stijn Frishert


Video Answer


1 Answers

The upper-left 3x3 matrix contains the rotation but also the scale. As you've seen, nuking the upper 3x3 nukes both. You'll want to preserve the scale by extracting the scale from the 3x3 first. Each column of the 3x3, taken as a vector, tells you the scale in each direction by taking the magnitude of each column vector.

If your 4x4 matrix is

RSX   RSY   RSZ   T
0     0     0     1

Then the scale factors are

xScale = ||RSX||
yScale = ||RSY||
zScale = ||RSZ||

Save those, then form a new 4x4 matrix doing what you're doing already, but also incorporating the scale.

xScale 0      0      xT
0      yScale 0      yT
0      0      zScale zT
0      0      0      1
like image 81
DuckMaestro Avatar answered Oct 12 '22 04:10

DuckMaestro