Help request: blendMode(?)

Hi i had copied several example of blendMode() variations, but the programs dont work anymore.
I cant figure our how to set the blendMode parameters.
I have a black icon (some pixel partially transparent) on a transparent background. I would like to display the icon inverted (white) on a blue back ground. Can anyone help me? Thanks.

If the image is “sharp”, ie there is only a handful of colours, you can simply walk through the pixels, changing them as you want. This is pretty fast.

I found this page useful for the blend operation. Someone should create the same example in Codea :slight_smile:

Thanks. @Ignatz: i know, but i would like to be able to use bendmode, it is there, so…
.@tnlogy very useful link: specially because it shows the formula that is used. Cant get the inversion effect, though, yet… [edit] btw, the guy who makes the site is really cool: looking at his projects, he could be on Codea with us!

Maybe this sounds like a request … But, Into Codea BlendMode are missing few cool blend modes,
such as Overlay and Subtract. See complete list here: Blend modes


@Simeon - Any plans to add other blending modes? Such as Overlay and Subtract

@Georgian those blend modes are not computable with OpenGL’s blend function operators. In Codea, you actually have full access to all possible blend modes computable under OpenGL by using the advanced version of the blendMode function (2 or 4 argument version).

Subtract and Overlay can be written with shaders, however. But you will need to render the scene into a texture first in order to do the compositing.

Haven’t looked up what you mean by subtract here, but I’ve implemented an erase functionality for drawing with using this blendMode.


To perform the erase, I first draw my brush strokes into a texture, and then write that texture with the blendMode above to perform an erase operation. You can see the same functionality in Photoshop touch when drawing and erasing, it first draws into a layer and then when you release the finger it performs the draw or erase operation.

@Simeon Why would you need to render into a texture? Can’t you just enable the GL_EXT_shader_framebuffer_fetch extension and use gl_LastFragData[0]?

#extension GL_EXT_shader_framebuffer_fetch : require

void main() {
    gl_FragColor = 1.0 - gl_LastFragData[0];

@mteep good point. Note that GL_EXT_shader_framebuffer_fetch is only available starting iOS 6, if you’re on iOS 5 you’ll have to render to image first.

So, just to check my understanding, in current Codea if I am on iOS 6 I can use this extension in a shader and does that mean the results of the previous renderings is available, ie between different mesh and shader render calls.

Is it only the color I can get with gl_LastFragData? Ie rgba, or can it read z as well?

.@tnlogy thanks for this trick. If you have other ones, i’ll be glad to read about them.

It works… a simple application was I moddified my shadow map example to use this on the shadow render pass. Basically means I can use this to sort the missing z-buffer on images issue.

Now just need to come up with something creative/insane to use this for :wink:

Yes, it is my understanding that gl_LastFragData[0] returns whatever the previous fragment shader that was run for that fragment/pixel wrote to gl_FragData[0] or equivalently to gl_FragColor. That is, RGBA only. See also