Tuesday 15 June 2010

c# - Generating an alpha mask from a texture -



c# - Generating an alpha mask from a texture -

i trying create function in 1 of helper classes take texture (left) , generate alpha mask (right)

here's have far:

public texture2d createalphamask(texture2d texture) { if (texture == null) homecoming null; { rendertarget2d target = new rendertarget2d(device, texture.width, texture.height); device.setrendertarget(target); device.clear(color.black); using (spritebatch batch = new spritebatch(device)) { blendstate blendstate = new blendstate() { alphablendfunction = blendfunction.max, alphasourceblend = blend.one, alphadestinationblend = blend.one, colorblendfunction = blendfunction.add, colorsourceblend = blend.inversedestinationcolor, colordestinationblend = blend.zero, blendfactor = color.white, colorwritechannels = colorwritechannels.all }; batch.begin(0, blendstate); batch.draw(texture, vector2.zero, color.white); batch.end(); } device.setrendertarget(null); homecoming target; } }

what should happening if alpha=0, pixel black, , if alpha=1, pixel white (and interpolated between these values if needed).

however, can't seem create go "whiter" base of operations image on left. is, if set blend white, at most go gray tones have, never brighter. isn't can create in advance, either, must calculated during game.

c# xna alpha

No comments:

Post a Comment