0

Here's my situation: I have a world matrix. I'm scaling to be half-size, so multiplying (0,0),(1,1), and (2,2) by .5f

When I do this, the normals in the mesh I'm trying to display become half-sized too, which kills a glare effect I'm trying to do.

Is there a way to get the scale of that matrix back to 1.0 without having to remember the scale value so it can be multiplied back it? Is it possible to normalize a matrix so that it retains its rotation, but is scaled to 1.0 and is translated to 0,0,0?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
KiraHoneybee
  • 495
  • 3
  • 12
  • Why can't you just renormalize the normal? If it's a uniform scale, that'd work out fine. – Nicol Bolas Sep 15 '22 at 23:31
  • You can use a separate matrix to scale the normals, and not scale that one. Note that if you scale non-uniformly (e.g. stretch along one axis), then the normals have to be recomputed. – user253751 Sep 15 '22 at 23:33
  • @NicolBolas I don't want to throw a normalize into my vertex shader, just for speed reasons. – KiraHoneybee Sep 15 '22 at 23:38
  • @user253751 In my case I'm scaling uniformly. But isn't there a trick to get the matrix's scale back to 1:1? I tried treating all the columns as vectors, and normalized them... and that SEEMS to work. Is that a bad solution that will bite me later? – KiraHoneybee Sep 15 '22 at 23:39
  • @KiraHoneybee "*I don't want to throw a normalize into my vertex shader, just for speed reasons.*" But another matrix multiplication is OK for performance? Vector normalization isn't especially expensive. – Nicol Bolas Sep 16 '22 at 00:26
  • *"I don't want to throw a normalize into my vertex shader, just for speed reasons."*. If you interpolate your normals between vertex and fragment shader, you should very likely already normalize them. (linear interpolation doesn't yield unit length normals). – BDL Sep 16 '22 at 07:29
  • see [Understanding 4x4 homogenous transform matrices](https://stackoverflow.com/a/28084380/2521214) you just make the 3 direction vectors unit ... however the matrix MUST BE ORTHOGONAL so no skew or perspective or any other projection breaking orthogonality... – Spektre Sep 16 '22 at 11:03

1 Answers1

0

So after much tweaking and testing, I did find that, for my purposes, simply treating each column as a vector and normalizing them yielded the results I wanted: A matrix that scaled to 1:1 while retaining the rotational information.

Leaving this up because I wasn't able to find this quick answer with a web search.

KiraHoneybee
  • 495
  • 3
  • 12