Alphablend [DX9][C#]
Ok so i''ve got 2 perpendicular squares (not sprites) which are meant to look like a flame. The flame texture has a blaack background which is used for color keying. The transparency works fine, but when i view it from an angle i notice that one square overlaps the other one, even though its blending with the scene (see it at http://Soundforge.myftp.org/flaming.jpg).
device.RenderState.DestinationBlend = Blend.BlendFactor;
device.RenderState.SourceBlend = Blend.SourceAlpha;
I''ve tried different combinations of blending and they all give the same result. So now i''m thinking, could it be cullmode? Its currently set to Cull.None. Or maybe lighting?
Another problem i get is a real fine line at the very top of each quad. Its not in the texture, so i dunno where it came from.
Try
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha; // or InverseSourceAlpha, I forgot.
device.RenderState.SourceBlend = Blend.SourceAlpha;
device.RenderState.DestinationBlend = Blend.InvSourceAlpha; // or InverseSourceAlpha, I forgot.
Nope
I tried all combinations of blending.
Its as if one of the two quadrants blends transparently well with the scene but not with the other quadrant.
I tried all combinations of blending.
Its as if one of the two quadrants blends transparently well with the scene but not with the other quadrant.
ok i''m a dumbass.
The problem was real trivial:
You have to sort the quadrants by z-order before rendering, since alpha blending works only based on what has been rendered already onto the buffer.
I thought i didnt need to do this since i wasnt using sprites!
The problem was real trivial:
You have to sort the quadrants by z-order before rendering, since alpha blending works only based on what has been rendered already onto the buffer.
I thought i didnt need to do this since i wasnt using sprites!
quote:Original post by nibmike
Nope
I tried all combinations of blending.
Its as if one of the two quadrants blends transparently well with the scene but not with the other quadrant.
You have to draw alphablended objects back-to-front, or else they''ll update the z-buffer and prevent more distant objects to be drawn later on, even though they''re visible through the first object.
Alternatively, since you mention you use a color key, you can use alpha testing instead of alpha blending.
what would be the major difference between alphablending and alphatesting? are they supported on all modern cards?
Yup, they are. Or at least, I would certainly think that any modern graphics hardware maker would be silly not to support them.
Alpha testing simply determines if the alpha value of a pixel is below a certain level (which you can set). If it is, then the pixel isn''t drawn to the backbuffer at all. Which means that it doesn''t have to read the previous backbuffer value, and doesn''t have to perform a blend function of any sort. This can be (I''m guessing) much more efficient than alpha blending. The problem is that you don''t get any partial transparency, just fully opaque or fully transparent. But depending on your situation, it might be exactly what you want.
Alpha testing simply determines if the alpha value of a pixel is below a certain level (which you can set). If it is, then the pixel isn''t drawn to the backbuffer at all. Which means that it doesn''t have to read the previous backbuffer value, and doesn''t have to perform a blend function of any sort. This can be (I''m guessing) much more efficient than alpha blending. The problem is that you don''t get any partial transparency, just fully opaque or fully transparent. But depending on your situation, it might be exactly what you want.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement