1. I notice that the entire mesh is transparent (which is undesired), when I set D3DRS_ALPHABLENDENABLE to FALSE in the first draw, I get normal mesh, however I will need D3DRS_ALPHABLENDENABLE to be TRUE in some meshes, why the mesh is transparent in the above code? I want to enable alpha blending but not make the mesh transparent.

2. How do I give the shader multiples lights? sometimes I will have 500 different light in the scene, how do I give 500 light to the shader and specify the light type and other properties as well in each light?

> You need to manage lights that are not visible or very far away and which contribution is minimal so that you can skip some work.

I checked the code sample "Direct3D 9 Normal Mapping Demo" which is a good example, however it's using one single light in the entire scene, sometimes I will have a mesh which is getting affected by multiple lights at the same time.

Does that means that the project is useless and I must look for other technique such as "deferred rendering" and "light pre pass"? If yes, any deferred rendering shader out there?

Does that means that the project is useless and I must look for other technique such as "deferred rendering" and "light pre pass"? If yes, any deferred rendering shader out there?

It's not useless. You can use normal mapping with almost any lighting technique you want. I would advise against using the deferred techniques for now. They are a lot harder to implement and bring their own problems with them (transparent objects for example). You can't just throw a "deferred rendering shader" on there and expect it to work.

Choosing a lighting technique is an important decision and will fundamentally change the way your rendering pipeline works and performs.

Your choices:

- Multi-pass: Render the object multiple times and apply one light source with each pass.

- "Uber-shader": Multiple lights in one pass plus anything else you might need and enable/disable the parts you need.

If you want to listen to me, you should go with forward renderer and multi-pass lights, since you are accustomed with it and it is easiest way.

If you have 30-40 lights in the scene then be smart where do you place them, have 3 or 4 as max light count affecting some object, choose by some priority for example for outdoor scene sun would always be included, player flashlight is priority, then choose rest by distance, cull occluded lights, for point lights test light bounding sphere against objects bounding volume for intersection to see if it should contribute...

I don't know how many light I will be having in the scene, it depends on the game mission, but I expect many different lights.

For example: I could have 30-40 light in a scene as well as multiple lights affecting many meshes, rendering each mesh 30-40 times is just a total waste of performance.

Lights are additive, so you loop through all lights in the shader and add the outgoing irradiance values for each light. You should read up on lighting and BRDFs if you are serious about having 30-40 lights in a scene.

On a separate note, if you are serious about trying to build a first person shooter game, you are going about it the completely wrong way. Gamedev.net is a great place to ask questions when you already have some idea of what you want, but if you just come in here and ask for code without really a question, you come off as lazy. Then you come here with every single error you receive for code you didn't write, instead of taking some initiative and trying to figure it out on your own. That is why you have received so many downvotes for this thread. There are many resources for learning how to do proper lighting, and shader programming.

@metsfan: Maybe you misunderstood me, I have already done a lot of things other than lights, so I don't really need to start graphics programming from the beginning.

The thing that I don't have experience with is shader, I thought I could use FFP light but I couldn't since I can't use it while using shaders.

I will not use another game engine since I have already programmed almost 60%-70% of the game engine, so it's not wise to just throw what I have done so far away.

BTW, when I ask for code samples, it doesn't mean that I'm lazy, it means that I want to get the idea on how it should be done.

@Migi0027: I have heard I could pass light array to the shader, why would I test for collision? why not just pass the light array and calculate the final light accordingly?

What he is saying is this: Each point light has an area of influence. Additionally, each light adds complexity to the final shading equation, since the shading equation must be performed for each light. You can cull away lights which do not affect your object, thus increasing performance. This can be done, as he showed, using Sphere-Sphere intersection. One sphere would be the area of influence for the light, the 2nd sphere would be a bounding sphere approximation for your 3D model.