I took a look into your project.
There were several problems:
- some of them preventing the light source from creating lighting effect.
- one which crashes the program under debug builds.
The errors are:
- Your vertex format doesn't have normals in them. For some reason you have commented out the normals. Actually your vertex format isn't the same on the program side and on the HLSL side. Fix this. You need the normals and the format has to be same in the program side and HLSL side. You can't expect the calculations to make sense if the input values aren't defined. Normals in this case aren't defined. You'll need to change the FVF declaration to include the normals.
- Your lighting calculation uses "Diffuse" multiplier. I didn't look into it so closely, but it seems to be 0 or close to it. Multiplying anything with 0 results 0 = black.
- Spaces : some of your values are in view space and some are in world space. Mixing those values won't give you correct result. Ie. Light position in world space and vertex position in view space.
- You are clearing the screen twice. It crashes the program because of invalid parameters or so. What is it with the stencil? Where do you need the stencil buffer?
Most of these things could have been debugged quite easily such as :
- use PIX
- narrow down the problem - split complex calculations/functions in parts and inspect each of them separately to find out parts which don't behave as intended.
- make the pixel shader output the value your want to inspect (this way I noticed that your normals are missing)
- Use debug builds and D3D debug libraries to catch invalid function calls.
Edited by kauna, 07 September 2012 - 11:39 AM.