Skip to main content
GameDev.net gamedev.net
🔒 Locked

[.net] Alpha Blending

Started by spejic Dec 20, 2004 at 9:03 AM 3 replies 1.2k views
Original Post
spejic
spejic
I know this is a common question, but I have been beating my head against a problem for a while I don't know how to solve it. I have a bunch of opaque PositionNormalTextured and PositionColoredTextured vertexes and they work just fine. I want to draw some partially-transparant PositionColoredTextured triangles over them (well, after them anyway). No matter what I try, it always ends up totally opaque. When I wrote a test program that did the same thing with only two triangles (using the same texture and settings) it works just fine. That seems to indicate that somewhere else in my program one of my RenderState or TextureState settings is wrecking the effect I want to achieve, but I can't seem to find out what it is. What possible other setting could cause the following to always output totally opaque? device.RenderState.AlphaBlendEnable = true; device.RenderState.SourceBlend = Blend.SourceColor; device.RenderState.DestinationBlend = Blend.DestinationColor; device.TextureState[0].ColorOperation = TextureOperation.Modulate; device.TextureState[0].ColorArgument1 = TextureArgument.TextureColor; device.TextureState[0].ColorArgument2 = TextureArgument.Diffuse; device.TextureState[0].AlphaOperation = TextureOperation.Modulate; device.TextureState[0].AlphaArgument1 = TextureArgument.TextureColor; device.TextureState[0].AlphaArgument2 = TextureArgument.Diffuse; I've also tried a great number of other options and it always ends up looking the same.
---Grandpa Simpson - "I never thought I could shoot down a German plane, but last year I proved myself wrong!"
Guimo
Guimo
Maybe you are writing the zBuffer?

If a transparent object fills the ZBuffer then you wont be able to write anyhing behind it. Try turning off ZWrites (ZWriteEnable?).

Also, turn off texture operations in stage 1.

Luck!
Guimo
spejic
spejic
Thanks for the help. I think I figured it out - all my vertexes of the same type are being grouped together, but only some were transparant and most were not. I was changing the settings correctly, but as I was drawing the primitives once I reached 100 vertexes (not depending on the opacity of the item), it wasn't having an effect.
---Grandpa Simpson - "I never thought I could shoot down a German plane, but last year I proved myself wrong!"
JesseT
JesseT
Quote:
Original post by spejic
I know this is a common question, but I have been beating my head against a problem for a while I don't know how to solve it...


I believe you have the SourceBlend and DestinationBlend blend factors set up incorrectly. These blend factors aren't the actual colors you're blending, but rather the factors multiplied with source and destination colors. They should probably be:

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

Leaving everything else the same, the SourceAlpha value happens to be the alpha component of the modulation of the RGBA texture color and diffuse color.

So you can control the opacity of geometry you're rendering by modifying the alpha component of the diffuse color of each of the vertices, or by adjusting the alpha components of the texels in the texture. The greater the alpha value, the more opaque it is. You can of course achieve entirely different effects and behaviours by changing the SourceBlend and DestinationBlend values, or the AlphaOperation type, or AlphaArgument1/2 values.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.