Using alpha channel of textures?

Started by
1 comment, last by MatrixCubed 17 years, 4 months ago
Hello all, I've developed a sprite engine using OpenGL, and one of the features I'd like to have is the ability to render sprites' shadows. Each sprite in my engine uses a 32-bit RGBA texture. Is there a method of rendering a textured (unlit) polygon with alpha testing (for color-key discarding of pixels) to the color buffer such that I may use only the alpha channel to define a "shadow-texture"? For example, using the stone on the left, which uses its alpha channel to define color key (e.g. the green area), whose pixels I reject using alpha testing. I'd like to somehow use that alpha channel to define a texture similar to the one on the right, such that I might blend it with the color buffer to create a sprite "shadow". I can pre-generate such textures at texture load-time, but I'd like to know if there is a method of doing this realtime? Thanks in advance,
Advertisement
You can just use the original texture. Render it with color (0,0,0,a), where a is an alpha value corresponding to the desired translucency of the shadow. This will automatically discard the unused parts of the image (e.g. those with an alpha value of 0), but you can use alpha testing in conjunction with the alpha blending as well (I'm guessing this could be a bit faster since you can reject texels before applying blending, but I might be wrong about this).
Thanks for pointing out the blatantly obvious I was searching for a much more complex solution, without realizing the simplicity of the question!

This topic is closed to new replies.

Advertisement