Problems With Lighting / Transparency

rifter1818

Junior Contributor
Joined
Sep 11, 2003
Messages
255
Location
A cold dark place
This is odd but when i enable lighting everything disapears, however Ambient is set to white?
Also i still cant get my engine to use Black as transparant.
d3d.Dev.RenderState.Lighting = true;
d3d.Dev.RenderState.Ambient = Color.White;
d3d.Dev.RenderState.CullMode = Cull.None;
d3d.Dev.RenderState.AlphaBlendEnable = true;
d3d.Dev.RenderState.AlphaTestEnable = true;
d3d.Dev.RenderState.ReferenceAlpha = Color.Black.ToArgb();
d3d.Dev.RenderState.AlphaFunction = Compare.NotEqual;
d3d.Dev.RenderState.AlphaSourceBlend = Blend.SourceAlpha;
d3d.Dev.RenderState.AlphaDestinationBlend = Blend.InvSourceAlpha;
d3d.Dev.RenderState.ColorVertex = true;
d3d.Dev.RenderState.AlphaBlendOperation = BlendOperation.Add;
 
I'm guessing here, but I think the problem is in one of the following lines:

d3d.Dev.RenderState.ReferenceAlpha = Color.Black.ToArgb();
d3d.Dev.RenderState.AlphaFunction = Compare.NotEqual;
d3d.Dev.RenderState.ColorVertex = true;
 
Alernatively your problem may be that you do not have 'normal' data for your object. DirectX then renders everything in black when lighting is turned on.
 
Last edited:
I think you got it there

That sounds about right, Ill have to apply some normals when i get a chance, just the transparancy problem left to go and one more project effectively done! (with many debts owing to the people here).
 
Normals are easy, luckily

rifter1818 said:
That sounds about right, Ill have to apply some normals when i get a chance, just the transparancy problem left to go and one more project effectively done! (with many debts owing to the people here).

If you've got a mesh, you can let DX itself calculate the normals throught the Mesh.ComputeNormals() method.

Be aware that if you re-use vertices DX will calculate the normals for those vertices as an average of all the surfaces which leads to 'roundish' results (at least it did for my meshes), which are not always what you want.
 
Back
Top