0

I'm trying to implement a moving light source in webGL.

I understand that the normalMatrix is the key to managing the lighting equation in the fragment shader but am not winning the battle to set it up correctly. The only tutorial I can find is the excellent "Introduction to Computer Graphics" and he says:

It turns out that you need to drop the fourth row and the fourth column and then take something called the "inverse transpose" of the resulting 3-by-3 matrix. You don't need to know what that means or why it works.

I think I do need to understand this to really master this baby.

So I'm looking for guidance on how and why to use mat3.normalFromMat4.

(PS. I have achieved the moving light source using 3Js, but its handling of texture maps degrades the images to too great an extent for my application. In webGL I can achieve the desired resolution.)

alan.raceQs
  • 411
  • 4
  • 11
  • how about [this tutorial](https://webglfundamentals.org/webgl/lessons/webgl-3d-lighting-directional.html)? – gman Aug 09 '20 at 01:51
  • Yes, I checked that as well, but it doesn't explain the use of normalFromMat4. I'll take a closer look to see if the penny drops. – alan.raceQs Aug 09 '20 at 02:43
  • And interestingly, he doesn't get it either: "I've never bothered to understand the solution but it turns out you can get the inverse of the world matrix, transpose it, which means swap the columns for rows, and use that instead and you'll get the right answer." – alan.raceQs Aug 09 '20 at 03:37
  • If you want to understand there are several videos and sites on it. [Here's some answers](https://stackoverflow.com/questions/13654401/why-transforming-normals-with-the-transpose-of-the-inverse-of-the-modelview-matr). [Here's another](https://computergraphics.stackexchange.com/questions/5512/inverse-transpose-of-vertex-normals). [Here's a different take](https://marctenbosch.com/quaternions/) if you search for "normal" on that page you'll see where he goes into the idea that people actually are mis-understanding what normals are. – gman Aug 09 '20 at 06:43

1 Answers1

0

For me, from reading this discussion, the answer appears to be simple. mat3.normalFromMat4 is only required if you scale the object non-uniformly (i.e. more in one dimension than the others) after the normals have been computed.

Since I'm not doing that, it's a null issue.

alan.raceQs
  • 411
  • 4
  • 11
  • that exact point was in the tutorial I linked to as my first comment BTW – gman Aug 10 '20 at 11:56
  • Yes, sorry, I overlooked crediting you with the link. I now have the moving light working, truly spectacular, I'm totally blown away. http://gpsanimator.com/orbits. – alan.raceQs Aug 11 '20 at 01:03