Lighting with TnL

Started by
1 comment, last by Martin 24 years, 7 months ago
Direct3D lighting is just a bad, horrible, evil thing that doesn't really work. Don't use it. If you want that kind of additive "lighting", you could probably use flat shading with all polygons' colors set to the color of the light source and set both the source and destination blend factors to D3DBLEND_ONE. I'm not sure if that really works or clips, though.
Advertisement
Is there anyway to make DX lighting addative? I have a yellow light illuminating a blue object and guess what? No illumination. I used to do this by simply adding the light colour onto the vertex colour. Any ideas?

Cheers,
Martin

Cheers,MartinIf I've helped you, a rating++ would be appreciated
I believe the D3D lighting engine is independent of vertex color. So if you want a yellow light to mix with a blue object you have to create a D3DMATERIAL structure with the dcvAmbient, dcvSpecular, dvPower and dcvDiffuse values set to get the effect you want. This allows you an object to be one color and reflect another completely different color allowing you to simulate different materials like metals, plastic, etc..

Also I believe that a material has to be set to even enable D3D lighting.

The function below takes a material struct that defines the ambient,diffuse,specular and power vales creates a material and returns a handle - minus any type of error checking.

D3DMATERIALHANDLE CreateMaterial(LPDIRECT3DDEVICE3 lpD3DDevice3,D3DMATERIAL Material)
{
LPDIRECT3D3 lpDirect3D3;
LPDIRECT3DMATERIAL3 lpMaterial3;

lpD3DDevice3->GetDirect3D(&lpDirect3D3);
lpDirect3D3 -> CreateMaterial(lpMaterial3, NULL);
lpMaterial3->SetMaterial(&Material);
lpMaterial3->GetHandle(lpD3DDevice3,&MatHandle);
return MatHandle;
}


The way I have it set up is that every texture on every model has its own material. Then just before I call DrawPrim on a object (or section of an object - if it has multiple textures) I set the material and texture.

This is how to set the material:
lpD3DDevice3->SetLightState(D3DLIGHTSTATE_MATERIAL,Object_MatHandle);

In the end though…D3D lighting only looks good with a high poly count scene.


Good Luck!



"You know you're obsessed with computer graphics when you're outside and you look up at the trees and think, "Wow! That's spectacular resolution!""

This topic is closed to new replies.

Advertisement