Sign in to follow this  

How to do per-pixel lighting?

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

This topic is 4815 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this