1

I am trying to implement layer function like photoshop. Here is what I want to draw..

http://s19.postimage.org/6n8eejbkz/image.png

But It is drawn like below

http://s19.postimage.org/hpdhcz5nn/image.png

It is using two layers. made with 2 texture framebuffers one for background, the other one for drawing. textures are mix with fragment shader.

mediump  vec4 tex0_color = texture2D(texunit0,TexCoordOut);  // bg texture
mediump  vec4 tex1_color = texture2D(texunit1,TexCoordOut);  // drawing texture 
mediump  vec4 mix_color  = mix(tex0_color,tex1_color,tex1_color.a);

and each draw on drawing layer is performed with vertex point sprite

highp float a = DestinationColor.a * texture2D(texunit0,gl_PointCoord).a;
gl_FragColor  = vec4(DestinationColor.rgb,a);

and blend functions setted like below..

glEnable    (GL_BLEND);
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

Could you give me some advice?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Mark Yang
  • 226
  • 3
  • 16

2 Answers2

3

Shaders are not made to perform blending operations since it requires both reading and writing to the target texture, which can only be done synchronously, resulting in very poor performance. Such synchronism can only be implemented in the non-programmable pipeline for now.

You might consider having two textures, one for reading and another for writing. Once you have applied your brush, switch them.

Yno
  • 786
  • 4
  • 9
  • Yno, I personally implemented all the Photoshop blending modes in shaders using 3 FBOs.No pure performance at all.But that is something not easy for OpenGL beginners. :) – Michael IV Sep 06 '12 at 08:03
  • Could you show me hint ? or sample code it will be great help – Mark Yang Sep 06 '12 at 08:29
1

I think you are after this.Also take a look at this article if you need to implement a wide range of Photoshop like blending modes via GLSL.Using hardware blending is pretty limited compared to what you can do using shaders.

Community
  • 1
  • 1
Michael IV
  • 11,016
  • 12
  • 92
  • 223