apply an alpha map?

BlitzMax Forums/BlitzMax Programming/apply an alpha map?

Nate the Great(Posted 2009) [#1]
so I have a fuzzy blob image and I want the pixels with lower rgb values to have lower alpha but I need to use alphablend mode. Is there a way to set an image as its own alpha map?


_Skully(Posted 2009) [#2]
You would probably have to average the RGB values and apply that to the alpha channel

a=255-((R+G+B)/3)


beanage(Posted 2009) [#3]
apply a simple frag. shader


Nate the Great(Posted 2009) [#4]
no shaders benanage... b3d can do this so im sure it doesnt need shaders

@skully... um im not sure how to make an alpha channel with pixmaps and stuff... I never got how that stuff worked


_Skully(Posted 2009) [#5]
Here is the function I am using to set the image mask

Function SetImageMask(p_image:TImage, p_red:Int,p_green:Int,p_blue:Int)
	Local l_maskrgb:Int
	Local l_maskargb:Int
	Local l_pixelrgb:Int
	Local l_pixelraw:Int
	Local l_x:Int,l_y:Int
	Local l_pix1:Tpixmap
	
	l_maskrgb = p_red Shl 16 + p_green Shl 8 + p_blue
	l_pix1 = LockImage(p_image)
	For l_x = 0 To ImageWidth(p_image)-1
		For l_y = 0 To ImageHeight(p_image)-1
			l_pixelraw = ReadPixel(l_pix1,l_x,l_y)
			l_pixelrgb = l_pixelraw & 16777215
			If l_pixelrgb = l_maskrgb Then
				' make transparent
				WritePixel(l_pix1,l_x,l_y,l_maskrgb)
			Else
				' remove transparency
				Local l_PixelNoAlpha:Int=l_pixelrgb | (255 Shl 24)
				WritePixel(l_pix1,l_x,l_y,l_PixelNoAlpha)
			End if
		Next 
	next
	UnlockImage(p_image)
End function



Nate the Great(Posted 2009) [#6]
Thanks skully

ill give it a go