Jump to content
  • Advertisement
Sign in to follow this  
Instruo

[MDX] Material Alpha Not Working

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

Tearing my hair out over this one, perhaps someone can see something I'm missing here. The texture alpha is working just fine, but the material alpha isn't working at all. It sets the material color, but seems to be ignoring the alpha entirely. Any ideas?
#region Blending
Emitter.Device.RenderState.ZBufferEnable = false;

Emitter.Device.RenderState.SourceBlend = Direct3d.Blend.SourceAlpha;
Emitter.Device.RenderState.DestinationBlend = Direct3d.Blend.InvSourceAlpha;
Emitter.Device.RenderState.AlphaBlendEnable = true;
#endregion


#region Material
this.material.Ambient = Color.FromArgb( 2, this.current_color );
this.material.Diffuse = Color.FromArgb( 2, this.current_color );
this.material.Emissive = Color.FromArgb( 2, this.current_color );
this.material.Specular = Color.FromArgb( 2, this.current_color );

Emitter.Device.Material = this.material;
#endregion

Emitter.Device.Transform.World = DirectX.Matrix.Scaling( 1, 1, 0 ) * m;
Emitter.Device.VertexFormat = Direct3d.CustomVertex.PositionNormalTextured.Format;
Emitter.Device.SetStreamSource( 0, this.parent.VB, 0 );
Emitter.Device.SetTexture( 0, this.texture );

Emitter.Device.DrawPrimitives( Direct3d.PrimitiveType.TriangleList,
                               0,
                               2 );

Emitter.Device.RenderState.AlphaBlendEnable = false;
Emitter.Device.RenderState.ZBufferEnable = true;

Share this post


Link to post
Share on other sites
Advertisement
I also couldn't get the material alpha to work, so if someone knows the 'official' solution, please feel free to post it here. I'm currently using the TextureFactor as a workaround for controlling the alpha in my rendering, like this:

[source lang=c#"]
device.TextureState[0].AlphaOperation = TextureOperation.Modulate;
device.TextureState[0].AlphaArgument1 = TextureArgument.TFactor;
device.TextureState[0].AlphaArgument2 = TextureArgument.TextureColor;
int alpha = 128; // alpha [0;255]
alpha = alpha << 24;
device.RenderState.TextureFactor = alpha;



Now that I think of it, maybe when you use TextureArgument.Diffuse as AlphaArgument1 it will use the alpha component in the materials diffuse color. I don't have time to check this, but if it works for you please let me know.

Share this post


Link to post
Share on other sites
Well, changing the light's diffuse alpha didn't work, but using your TextureState method did! I don't care if its a work around at this point, it works :) Anyway, you were correct in that it took AlphaArgument1 being TextureArgument.Diffuse. 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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!