PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Alpha channel

I was wondering if anyone else felt the need to have an alpha channel enabled blit function. Currently, we can only change the alpha (ie blending) for the entire image (correct me if I'm wrong).

From all the particle systems that were posted here lately, it seems to me that it would look better if the particles had radial-gradient alphas. Maybe one of them did, but I'm sure some didn't.

Anyway, IF I were to take the time to try and implement it, at what level would be the best? I don't suppose the custom pixel shader would help since you couldn't pass it the alpha info. Or maybe add an extra member to the surface class? Or add a method to the rasterizer?
it's possible to restrict the render area to a rect and to set the render target to a surface instead of the back buffer so maybe combined these would work but might be too slow and would only work on rectangles
I was wondering if anyone else felt the need to have an alpha channel enabled blit function. Currently, we can only change the alpha (ie blending) for the entire image (correct me if I'm wrong).


In fact yes this would be very handy, I wanted to use a particle texture with an alpha channel, but for the demo it was enough to do general alpha blending by adding the colors, what I did was :
*dest = (*src * alpha) + *dest, for the r,g,b components, that works ok if you have a black background, else you have to blend it with real alpha info in the texture. It would be usefull to have an AlphaSurface class, with a pointer to the rgb values and a pointer to a separate alpha channel. Could be implemented by wrapping the Surface class in the AlphaSurface class and as you suggest add an extra member for the alpha pointer. Another option would be subclassing the Surface class, but I'm affraid of speed issues because of more vtable lookups. More usefull (for cache issues) but a lot more difficult would be to let the AlphaSurface contain a pointer to an uint32 containing 16 bits of rgb and an extra 8 bits for the alpha value, then there are still 8 bits unused. And of course the need for the necessary methods to load 4 channel images directly into an AlphaSurface instance.
In fact imho it would even be better that this would be the default Surface implementation. Then all the blending ops could be defined on the Surface class.
And let the swap() function only copy the rgb values to the screen, but then we're on to a major PocketHal/PocketFrog change
I've done a little modifying of PocketFrog and I've got my alpha blending working. What I did, as opposed to Max, was to add an overloaded blit method that will accept 2 surfaces. Currently, I use the second surface for my per-pixel alpha, but I was thinking it may be useful for something else.
I suppose it could be set up like the custom blit code to accept a user defined pixel function. I really don't know what all you could do with blitting from 2 images, but I though I'd mention it.

Ask if you're interested and maybe I can post code, but it's not simple since I had to modify several files to get it to work.