Alpha blending

Started by
5 comments, last by Namethatnobodyelsetook 19 years, 5 months ago
What constants would i have to use in the following code if: I have objects and backgrounds all with 24-bit bitmaps as textures. I want the objects to have X percent transparency and the background to stay the same. I don't want to change the RGB of the colours, just the alpha. I don't want to make a certain colour, e.g. black to be completely transparent. With D3DDevice .SetRenderState D3DRS_SRCBLEND, ***** .SetRenderState D3DRS_DESTBLEND, ***** .SetRenderState D3DRS_ALPHABLENDENABLE, True End With (this is VB btw) Please help...
Advertisement
Man I had the same problem as well. After submiting this problem in the GameDev.net forum, I was told there was a few ways of doing it. I knew none, even today I still don't know. I was given some small code snippets by a couple of other people and they told me to play around with the OH byte vales, whatever the hell that is. Plus I didn't see where to change them in their code! So I never had my question answered and nobody else replied since. Plus some of the code that was given only controlled how Transparent/Opaque the polygons were, not see-through. I know how to do alphablending in 2 different ways, but I do not know how to change their alpha either. Anyone know?

And bare in mind, I am not talking about controlling the transparency. And I doubt the other guy that posted above me meant that either. It's alphablending. So no code based on ALPHATESTENABLED/ALPHAREF/ALPHAFUNC or anything like because those help control how transparent/opaque your sprites are, not how see-through they are. We want to control how see-through our sprites are, hence the name alphablending.

I have VB too by the way, but C++ code I can easily convert.

Oh and Crazy Jonny, be sure to use CreateTextureFromFile instead of CreateTextureFromFileEx if you want non transparent sprites to get blended. Either that or use CreateTextureFromFileEx only a transparency color that is not in the image. Leaving it 0 would get rid of the black, which was your problem. And as for the rest:

            Direct3D_Device.SetRenderState D3DRS_SRCBLEND, D3DBLEND_ONE            Direct3D_Device.SetRenderState D3DRS_DESTBLEND, D3DBLEND_SRCALPHA            Direct3D_Device.SetRenderState D3DRS_ALPHABLENDENABLE, True        


Those are just to hold the constants built into DirectX. I wish I knew how to change the alpha values to make them less see-through and more see-through.

Here is another question I have to the other people who are going to reply to this thread. Why do people mistaken alphablending for transparency? Alphablending blends the pixels in an image/polygon or whatever with whatever is behind it, creating a "ghost" kinda see-through effect. Transparency is eliminating a background color in a sprite image so that only part of the image will be displayed, which will be your sprite. Using GDI and Bitblt, you needed a mask to go with your sprite image in order to create transparency. The beauty of DirectX is that you don't need a mask. You can using Alphablending tricks to create the same effect, which is why people are confused in the terminology.

[Edited by - Jacob Roman on November 10, 2004 7:01:19 PM]
here
here
here
here

Just a few topics in the last 30 days...
Quote:Original post by Jacob Roman
Here is another question I have to the other people who are going to reply to this thread. Why do people mistaken alphablending for transparency? Alphablending blends the pixels in an image/polygon or whatever with whatever is behind it, creating a "ghost" kinda see-through effect. Transparency is eliminating a background color in a sprite image so that only part of the image will be displayed, which will be your sprite.

Umm, no. What you're talking about is colour keying, which done by making a colour transparent in a source image.

Transparent:
having the property of transmitting light without appreciable scattering so that bodies lying beyond are seen clearly
Stay Casual,KenDrunken Hyena
I tried all four of the "Here's" and still couldn't get it working correctly. Probably because I have certain alphablending functions enabled that I shouldn't. Like ALPHATESTENABLE and stuff. I don't know. What do I do to control the alphablending values to make polygons more or less see through?
Hi,

Are you render Sprites or 3DObjects? Are you using FixedPipe or Shaders? You problem has a very simple solution if you use shaders.

Luck!
Guimo

TextureStageState alphaop and alphaargs control mixing of alpha that can be used during multitexturing. The color and alpha values after the last stage is what's used for framebuffer alphablending.

Frame buffer blending does this:
if (alphatestenabled && alpha passes alphatestfunc){  if (alphablendenable)    newcolor = newcolor * srcblend (blendop) framebuffercolor * destblend;  Write new color and depth}


ie:

Alphatest controls a boolean keep or discard pixel value.

Alphablend, if enabled, uses srcblend, destblend, and blendop, along with the color and alpha output from the last texture stage and the color and alpha in the frame buffer to determine the new pixel color.

In one of those links I give examples of texture stage setups.
In other links I give examples of SRCBLEND and DESTBLEND for regular blending, additive blending, modulating blending.

edit:
First link gives all the SRCBLEND DESTBLEND combos you could ever want.
Second link gives sample texture stages
Fourth link gives many different detailed sample texture stages

Definately everything you could ever hope for.

This topic is closed to new replies.

Advertisement