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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With