Ivan Kuckir
Ivan Kuckir

Reputation: 2559

Photoshop "blend modes" with OpenGL

I am planning to make a simple drawing tool, which supports multiple layers and all blend modes from Photoshop.

I am considering to do the blending on the GPU (put each layer into a texture and draw 2 triangles to render each layer). But I am not sure, if it is possible to implement all the blend modes with OpenGL's blendFunc / blendEquation etc.

Another opiton is to pass all the textures + blend mode flags to one fragment shader and blend them just as I wish, but I will have to recompile FS when adding / removing some layer (sampler2D).

So what do you think? Is it possible? Are there some better ways how to use GPU for blending? Sohould I care about it now, or should I make it all on CPU and care about enhancements in the future?

BTW. it will be JavaScript program using WebGL, but I think it does not matter.

Upvotes: 1

Views: 1748

Answers (1)

przemo_li
przemo_li

Reputation: 4053

Of course you can. But it need to be done in sharers.

Load two pictures (actually can be more), render triangles. But then just use your shaders to probe both textures and mix those values with equation that is dependent on current blend mode (provided as uniform).

PS do not forget to turn off mipmaps, and filtering.

Upvotes: 1

Related Questions