Jump to content
  • Advertisement
Sign in to follow this  

How to do per-pixel lighting?

This topic is 5462 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

Hi I want to use per-pixel lighting, so far i've tried using dot3 bump mapping off a tutorial, except all got was this.. btw heres the actual image used its all white and not coloured, even tho ive got it set up to be slighty lit. heres what my screen looks without the dot3 code and normaled image. btw heres the actual image used I've got no idea whats wrong, heres the code i am using for the dot3 to work, have i left something out? //defined function
DWORD VectorToRGB(D3DXVECTOR3* NormalVector)
DWORD dwR = (DWORD)(127 * NormalVector->x + 128);
DWORD dwG = (DWORD)(127 * NormalVector->y + 128);
DWORD dwB = (DWORD)(127 * NormalVector->z + 128);

return (DWORD)(0xff000000 + (dwR << 16) + (dwG << 8) + dwB);

//init code

D3DCAPS9 m_DeviceCaps;

if(!(m_DeviceCaps.TextureOpCaps & D3DTEXOPCAPS_DOTPRODUCT3)) {
	return false;

//loop code
dwTFactor = VectorToRGB(&Light);


Share this post

Link to post
Share on other sites
1. You need to convert the light ray into tangent space: this gives you your ray vector, which you must then convert to a color and set as your texture factor. Right now, you are using the light in world space, which might not correspond to the tangent space.

2. You never add in you other (floor) texture in the rendering process. You might want to use another texture stage, and render the floor texture modulated by the result of the previous (light) stage.

3. I strongly suggest that instead of using texture factors, you use the diffuse light component for each triangle vertex. Using texture factors, you can only achieve directional lights on flat surfaces, it will allow neither point/spot lights nor curved surfaces.

You could create the diffuse component for each vertex easily by having it contain the coordinates of the ray in tangent space.

Share this post

Link to post
Share on other sites
When setting 2 texture stages, with using the SetTexture() method do i enter SetTexture(0,texture1) and SetTexture(1, texture2) to set the texture to that texture stage, that is the 0 and 1?


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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!