Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

How to do per-pixel lighting?

This topic is 5126 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
d3dDevice->SetTextureStageState(0,D3DTSS_COLORARG1,D3DTA_TEXTURE);
d3dDevice->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_TFACTOR);
d3dDevice->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_DOTPRODUCT3);

D3DCAPS9 m_DeviceCaps;
d3dDevice->GetDeviceCaps(&m_DeviceCaps);

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

//loop code
d3dDevice->SetTexture(0,pNormalMap);	
dwTFactor = VectorToRGB(&Light);
d3dDevice->SetRenderState(D3DRS_TEXTUREFACTOR,dwTFactor);



thx

Share this post


Link to post
Share on other sites
Advertisement
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?

thanks

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!