Transparent meshes.

Reidar Lange

Newcomer
Joined
Oct 29, 2004
Messages
16
In the render method I use this:

Code:
device.RenderState.Lighting = true;
device.RenderState.Ambient = Color.FromArgb(100,100,100);
device.RenderState.ZBufferEnable = true;
device.RenderState.CullMode = Cull.CounterClockwise;
device.RenderState.ShadeMode = ShadeMode.Gouraud;
device.RenderState.FillMode = FillMode.Solid;

device.RenderState.AlphaBlendEnable = true;
device.RenderState.AlphaSourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;
device.TextureState[0].ColorOperation = TextureOperation.Modulate;
device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor;
device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse;
device.TextureState[0].AlphaArgument1 = TextureArgument.Diffuse;
device.TextureState[0].AlphaArgument2 = TextureArgument.TextureColor;
device.TextureState[0].AlphaOperation = TextureOperation.BlendFactorAlpha;

device.Lights[0].Type = LightType.Directional;
device.Lights[0].Diffuse = Color.FromArgb(0,200,200,200);
device.Lights[0].Specular = Color.White;
device.Lights[0].Direction = new Vector3((float)Math.Cos((float)
device.Lights[0].Commit();//let d3d know about the light
device.Lights[0].Enabled = true;

Then I set the material color to argb(0,255,255,255) for one of the rendered meshes. I trun off alpha blending for all except one.

The question is: When I set the alpha channel to 0, I would expect the transparent mesh to dissapear completely. Why does it not ?
 

Attachments

The simplest soulution is often the best. Very good point :)

You are quite right, but what if I want the mesh to be even more transparent than what you see on the snapshot, but not completely gone ?

I have tried to fiddle with different alpha settings, but this is the best I could come up with.
 
Last edited:
Not sure here (yes, i am a DX n00b. Just trying to find some logic in DX). I always thought that SourceBlend and DestinationBlend were linked, and AlphaSourceBlend and AlphaDestinationBlend were linked. But i see you use:

device.RenderState.AlphaSourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha;

Really not sure here, just something that popped up in my head while reading...

-- Loffen
 
Last edited:
Back
Top