|
-
Jan 3rd, 2011, 12:46 PM
#1
Thread Starter
Fanatic Member
Alpha blending problem
Hello all.
Finishing off the very first 3D dual video channel model viewer, but I got into a problem. I have already managed to draw the two renders into textures, they are named dLTexture and dRTexture. Both textures are rendered correctly.
I know how to draw these two textures in cross-eye mode by using sprites (SContainer), but now I have to draw them as anaglyph. This means, both textures with half opacity and left channel no green and right channel no red color. I have to blend these two together, so here is the code:
Code:
Device.RenderState.SourceBlend = Direct3D.Blend.DestinationAlpha
Device.RenderState.DestinationBlend = Direct3D.Blend.SourceAlpha
Device.RenderState.AlphaBlendEnable = True
Device.Clear(ClearFlags.Target Or ClearFlags.ZBuffer, Color.Transparent, 1, 0)
Device.BeginScene()
SContainer.Begin(SpriteFlags.None)
If KeyPressed(Windows.Forms.Keys.Q) Then
SContainer.Draw2D(dRTexture, New Point(0, 0), 0, New Point(0, 0), Color.FromArgb(128, 0, 255, 128))
SContainer.Draw2D(dLTexture, New Point(0, 0), 0, New Point(0, 0), Color.FromArgb(128, 255, 0, 128))
Else
SContainer.Draw2D(dLTexture, New Point(0, 0), 0, New Point(0, 0), Color.FromArgb(128, 255, 0, 128))
SContainer.Draw2D(dRTexture, New Point(0, 0), 0, New Point(0, 0), Color.FromArgb(128, 0, 255, 128))
End If
SContainer.End()
Device.EndScene()
Device.Present()
But, when I press Q the screen changes, and this should NOT happen. The two textures must be blended so that they add color, so twisting the texture draw order should not make a difference. What am I doing wrong here?
BTW: when I use "Device.RenderState.DestinationBlend = Direct3D.Blend.SourceColor" it multiplies the colors, clearing the red and green channel. I don't want this. It must "add" the color values of both textures.
Last edited by bergerkiller; Jan 3rd, 2011 at 12:50 PM.
-
Jan 3rd, 2011, 02:44 PM
#2
Re: Alpha blending problem
Have you tried:
Code:
SContainer.Begin(SpriteFlags.AlphaBlend Or SpriteFlags.SortDepthFrontToBack)
-
Jan 3rd, 2011, 04:28 PM
#3
Thread Starter
Fanatic Member
Re: Alpha blending problem
Sorry does not work. I guess the container is fine, I have to set the renderstate in such manner that it actually adds the two texture colors.
I tried lots of renderstates and color alpha values, but it ll ends up in different colors/color loss.
EDIT
I got it this far:

Code:
Device.RenderState.AlphaBlendEnable = True
Device.RenderState.BlendOperation = BlendOperation.Add
'Device.RenderState.SourceBlend = Blend.DestinationAlpha
Device.RenderState.DestinationBlend = Blend.InvSourceAlpha
If KeyPressed(Windows.Forms.Keys.Q) Then
SContainer.Draw2D(dRTexture, New Point(0, 0), 0, New Point(0, 0), Color.FromArgb(255, 0, 255, 128))
SContainer.Draw2D(dLTexture, New Point(0, 0), 0, New Point(0, 0), Color.FromArgb(128, 255, 0, 128))
Else
SContainer.Draw2D(dLTexture, New Point(0, 0), 0, New Point(0, 0), Color.FromArgb(255, 255, 0, 128))
SContainer.Draw2D(dRTexture, New Point(0, 0), 0, New Point(0, 0), Color.FromArgb(128, 0, 255, 128))
End If
Little dark for my taste...and it's a weird way of using alpha. On the other hand, the scene is empty on start. It's logical the alpha values of the first render are always 255... xD
Last edited by bergerkiller; Jan 3rd, 2011 at 04:55 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|