Friday, February 06, 2004

creating overlay FX with the blend() function

if you're like me and are fascinated by the possibilities of mingling pixels, you'll like that little demo i did last night. inspired by the "glow" look of 3d geometry achievable with vertex/pixel shaders on modern graphics cards i tried to come up with a pure software only version. the effect is achieved by creating a scaled down version of the current content of the pixel buffer, which is then scaled up again and merged with the original using additive blending. the demo also shows how to clear the z-Buffer independently from the pixel buffer. this is important for cases where you don't want background refreshs, but still make sure 3d geometry is drawn properly.

superGlow is here: /p5/superGlow/

As the reference for the blend() function is not yet posted to the Processing website, here's an excerpt about the various blend modes:


Function to copy a single pixel or region of pixels from one image into another (or in itself again) with full alpha channel support and a choice of the following modes to blend the colours of source pixels (A) with the ones of pixels in the destination image (B):

BLEND - linear interpolation of colours: C = A*factor + B
ADD - additive blending with white clip: C = min(A*factor + B, 255)
SUBSTRACT - substractive blending with black clip: C = max(B - A*factor, 0)
DARKEST - only the darkest colour succeeds: C = min(A*factor, B)
LIGHTEST - only the lightest colour succeeds: C = max(A*factor, B)
REPLACE - destination colour equals colour of source pixel: C = A

All modes (excluding REPLACE) will use the alpha information (highest byte) of source image pixels as blending factor. See the reference for alpha() for more detail. The source and destination regions need not be of equal dimensions, the function will automatically resize source pixels to fit the specified target region.