Jump to content
  • Advertisement
Sign in to follow this  
EternityZA

strugling with lighting in GLSL

This topic is 3410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey. im trying to create a diffuse light using GLSL. Theres alot of tutorials out there on this subject but all of them (or at least the ones i found) accessed the built in matrix gl_NormalMatrix which as far as i understand is automaticaly calculated by the driver based on the other build in matrixes. for example heres one line of code i found in a tutorial: normal = normalize(gl_NormalMatrix * gl_Normal); My problem is that i do all Matrix calculations myself so the other build in matrixes never gets any value and im not quite sure how to calculate this gl_NormalMatrix myself. what i currently calculate in my engine is: the projection matrix, the view matrix, the "node" matrix (one for each node in my scene graph) using these 3 matrixes that i allready have. how can i calculate this gl_NormalMatrix myself? Thnx in Advance!

Share this post


Link to post
Share on other sites
Advertisement
is there a quick way to calculate that in GLSL?
or should i calculate it beforehand?
im not quite sure how to inverse a 3x3 matrix

Share this post


Link to post
Share on other sites
Are you doing any scaling in your matrix? no-> then glNormalMatrix = glModelViewMatrix

if yes,

as long as your scales are uniform (the same on all axis) then the above also holds true.

Share this post


Link to post
Share on other sites
Quote:
Original post by dpadam450
Are you doing any scaling in your matrix? no-> then glNormalMatrix = glModelViewMatrix

if yes,

as long as your scales are uniform (the same on all axis) then the above also holds true.

Yes, but then you have to renormalize the normals. That's eazy if you know the scale factor ;)

Anyway, you should always have at hand, a function that invert matrices. see for example: this one .

Share this post


Link to post
Share on other sites
If your matrix is affine (its last row is (0,0,0,1)) then you can invert it then take the top-left 3x3 submatrix. You can also adapt the function of steven katic to 3x3 matrices: just replace 4 by 3 and 16 by 9. There are plenty of examples in the net and here at GameDev so you can search for one that corresponds to your needs.
If you want to do it yourself see The Matrix and Quaternions FAQ.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!