Alpha Masking During Rendering

BlitzMax Forums/BlitzMax Programming/Alpha Masking During Rendering

Vagary Labs(Posted 2010) [#1]
Greetings!

I've been trying this by all sorts of methods, from blending or other randomness, but let me explain what I am trying to do!

I would like to take two solid images and add an alpha mask to one of them, so it would blend with the other one. Sounds easy right? Well, my feeble little mind can't wrap itself around it, so that's why I am asking help from the gurus!

I've tried searching the site, but have come up with nothing useful. Thank you for your help!
-Mr.Wolf


ImaginaryHuman(Posted 2010) [#2]
Make sure the second image has an alpha channel, ie load as PNG and make sure it saved with one in your paint application. Use SetBlend(AlphaBlend). Then DrawImage the first image, and then DrawImage the second one. ?


Vagary Labs(Posted 2010) [#3]
Greetings ImaginaryHuman!

Yeah, both images are PNG files. The problem I've had with doing like that, is that the alpha channel has to be already in place, e.g. has to edited with it. What I am attempting, (but not too well!) is to take 2 images and then blend them by using another image.

I've had moderate success with some different types of blending, but still not quite the desired effect.

Thanks for your input though!
-Mr.Wolf


zambani(Posted 2010) [#4]
I would like to know of a good way also.
The only way I was able to do this is was with the stencil buffer in OpenGL/glMax. But even that worked only with shapes not actual TImages.


Vagary Labs(Posted 2010) [#5]
The closest thing I have been able get to it, is something like this. However, it uses shadeblending which causes the back image to be darker.
Without further ado, here's the generic example.

Graphics 1024, 768, 0, 60
SetBlend (ALPHABLEND)
SetAlpha (1.0)

Local image_a:TImage = LoadImage("image_a.png")
Local image_b:TImage = LoadImage("image_b.png")
Local alphamask:TImage = LoadImage("mask.png")

Repeat
Cls
SetBlend (ALPHABLEND)
'=== Reference images ==='
DrawImage image_a, 128, 384, 0
DrawImage image_b, 384, 128, 0

'=== Attempting to Blend ==='
DrawImage image_a, 128, 128, 0
DrawImage alphamask, 128, 128, 0
SetBlend (SHADEBLEND)
DrawImage image_b, 128, 128, 0

Flip 1
Delay 10

Until KeyHit(KEY_ESCAPE) Or AppTerminate()
End

I couldn't figure out how to upload the full example, but I hope it makes sense!
-Mr.Wolf


zambani(Posted 2010) [#6]
@Mr Wolf.
Can you upload a screenshot of this effect?


Vagary Labs(Posted 2010) [#7]
Sure thing! I hope this works!
<img src="http://i41.tinypic.com/3130sub.jpg" border="0" alt="Image and video hosting by TinyPic">
EDIT:
Doh! HTML tags don't work! :-P Oh well, if you follow the URL, it should show you a sample of the output.


matibee(Posted 2010) [#8]
I think what you need is to use Opengl and draw a multi-textured quad with the relevant blend modes for each texture stage. Sorry I can't help with actual code I'm really busy ATM.


zambani(Posted 2010) [#9]
@Mr. Wolf
In your image, which part was the image and which part was the mask?


Vagary Labs(Posted 2010) [#10]
Sorry about the long delay. Thanks Matibee for the idea! I was kind of thinking something like that, but I have no idea how to write it! The only reason I thought of it was because I see more blending on actual 3d objects in screenshots and what not. I didn't think this would be such a hard thing to do! :-D

@Zambani, there is actually two images in place. First, the darker green one, which is suppose to be the same luminance as the bright green one is the first layer. Next, the alpha mask is then placed on top of it--sort of the small fuzzy circle. Lastly, the blue image is placed on top which is shade blended, which then causes the blending of the alpha mask and it, but the green image gets darker as a result of how shade blending works.

I hope this all makes some sense!
-Mr.Wolf