Archived

This topic is now archived and is closed to further replies.

neveschu

Per pixel lighting

Recommended Posts

Hi I am starting to use per pixel lighting of directional light. Now, I have a directional light and a cube. It works fine. But if I add one more directional light, the cube is not affected by that additional light. I am using vertex shader and DOT3 and normal map with the first directional light. Isn''t that when we have vertex shader, the original per vertex lighting effect will be disabled? If this is the case, can we do per pixel lighting with one directional light and per vertex lighting with all the other lights ( include some point lights) ? Thx~~~~~~

Share this post


Link to post
Share on other sites
The DOT3 operation takes place in the *pixel* pipeline.

If you have vertex lighting enabled in the fixed function pipeline OR you do your own vertex lighting in a vertex shader, the results of that lighting will be in the DIFFUSE source for a pixel shader OR the texture stage state setup (a.k.a. the multitexture cascade).

If you have a vertex shader then yes, the *fixed function* vertex diffuse lighting will indeed be disabled (e.g. the D3DRS_LIGHTING renderstate will have no effect).
Also if your shader doesn''t include any diffuse vertex lighting code, then you won''t get any diffuse vertex lighting!

If you''re doing texture/tangent space DOT3 per pixel lighting/bumpmapping, then you are probably outputting the texture/tangent space light vector into the DIFFUSE pixel component at the end of your vertex shader (oD0.xyz)...

...if so you''ll want to output the result of any vertex lighting you''re doing into some other iterated value - usually either specular (oD1) or a set of texture coordinates (oT*).


You''ll then want to blend these outputs together in either a pixel shader or the texture stage system.
If you''re using texture coordinates to output the vertex lighting, to use them directly you''ll have to do it in a pixel shader, or you could sacrifice a texture unit and use them to lookup into a cube or volume texture.


I''m actually sketching out an idea in my head at the mo which will allow multiple dot3 lights in a single stage/pass - once I get round to implementing it I''ll make it public.


--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
Thanks for the information.

Ya, my vertex shadow can output to the SPECULAR channel also. This allows me to calculate the per vertex lighting in the DIFFUSE channel.

Is there any articles/source code with vertex shader to do multiple per vertex light source?

A multiple dot3 light in single pass? I''ve seen nvidia sample about dot3 point light. It uses 3 passes! It is possible to do it in single pass, even with several lights? That''s great~

Share this post


Link to post
Share on other sites
The nVidia site contains sample shader code and presentations to do this... Download their shader browser source.

I think the MSDN site does to (msdn.microsoft.com/directx)


Many attenuated dot3 spotlights in 2 passes (& about 2-3 texture stages) *might* be possible (1 won''t be practical thinking about it) - its a method which is at the idea/paper stage - there may be some serious artefacts/caveats I''ve not taken into account - so I''ll have to implement a test program etc before I reveal the idea publically (its built on the back of some other techniques, one of which is a related, unproven idea of mine).

--
Simon O''''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites