Simple nDotL lighting won't work

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Geomaster
Posts: 71
Joined: Tue Oct 21, 2008 3:39 pm

Simple nDotL lighting won't work

Post by Geomaster »

I have created a really simple shader, just to test it :) It only takes normals and standard world & world*view*projection matrices in the vertex shader, and passes world position & normal in to the pixel shader, then the pixel shader takes light position, radus, intensity & color and computes the intensity by simple n.L formula (it takes into account light's radius and distance from the pixel). Now, the one part of the test sphere is always black, even when the light is really close to it and actually the whole lighting seems to be a little weird. I cannot find the reason for this, I tried to multiply normal with inverted world matrix (instead of world matrix) and to use vertex instead of pixel lighting, or even inverting the light vector, discarding last row and column from world matrix, but no luck.

Here is the example with the code: http://www.sendspace.com/file/tjxldf
(in the code, include and lib files' path is specified absolutely because of mess on my hard drive)

PS: in the example .exe file, you will be in the sphere, move a little back or ahead to see it from outside, and the black line is light's direction (line start is the light position, and the end is position*10, i was to lazy to attach a billboard to it :)

Any clues, this is driving me crazy. But seriously.
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

This one is simple to solve :)

Replace all occurances of "COLOR0" in your shader file with "TEXCOORD1" and "COLOR1" with "TEXCOORD2". Worked flawlessly for me after that.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Geomaster
Posts: 71
Joined: Tue Oct 21, 2008 3:39 pm

Post by Geomaster »

Great, works now, thanks SO much!
Post Reply