Michele,

I guess the reason why you implement it using a fragment shader is to see
a speed increase.
What speed increase can we expect using your technique (What CPU/Graphic
card are you using) ?
I was thinking of implementing something similar for BufferedImageOp (
speed up ConvolveOp for exemple ), so I'm interested in your results.
On a side note, not everybody has a "fragment shader" capable graphic
card/OpenGL driver.

Best,
Mike
******************************************
Michael TOULA
Software Engineer

Dalim Software GmbH
Strassburger Str. 6
D-77694
Kehl am Rhein
GERMANY

tel:   +49 7851 919 612
fax:  +49 7851 735 76
web:   www.dalim.com
******************************************



Michele Puccini <[EMAIL PROTECTED]>
Sent by: Discussion list for Java 2D API <[EMAIL PROTECTED]>
22/02/07 11:20
Please respond to
Michele Puccini <[EMAIL PROTECTED]>


To
[EMAIL PROTECTED]
cc

Subject
[JAVA2D] java2d Compositing -> OpenGL fragment shaders






Hello all at java2d,
Hello Chris,

after bouncing my head for some time over OpenGL, alpha compositing,
accumulated and premultiplied alpha I decided (curiosity) to take a look
at
the j2se6 source code just to see what happens behind the scenes.

All I discovered (surprise ?) is that the OpenGL codepath of java2d has to
deal with premultiplied alpha pixels. That's probably because the Porter
and
Duff compositing rules "work better" with premultiplied data ;)

But premultiplying and unpremultiplying is done in software loops, so this
generates some overhead, expecially when using java2d for creating
offscreen
graphics with unpremultiplied images (me).

So I decided to implement my very first OpenGL fragment shader that does a
SRC_OVER composite on unpremultiplied data. I'm a true beginer, so please
forgive me.

Here's the code

-----

uniform sampler2D texture;

void main()
{
  vec4 s = texture2D(texture,gl_TexCoord[0].st);
  vec4 d = gl_FragColor;

  float extra_alpha = 0.1;

  s.a = s.a * extra_alpha;

 if (s.a == 0.0) gl_FragColor = d;
 else if (s.a == 1.0) gl_FragColor = s;
 else if (d.a == 0.0) {gl_FragColor = s;}
 else
 {
     float a = s.a + d.a - s.a * d.a;
  gl_FragColor.a = a;
  gl_FragColor.r = (s.a*s.r+d.a*d.r-s.a*d.a*d.r)/a;
  gl_FragColor.g = (s.a*s.g+d.a*d.g-s.a*d.a*d.g)/a;
  gl_FragColor.b = (s.a*s.b+d.a*d.b-s.a*d.a*d.b)/a;
 }
}

-----

I works very well and, apart that compiler warning (!), the results are
1:1
the SRC_OVER I get from the Java2D software loops.

So the question: why don't implement the entire OpenGL java2d Composite
with
fragment shaders and avoid premultiplied data ?

Cheers!

Mik
============================================================================
> ClassX Development Italy  Via Francesca, 368/I I-56030 S.M. a Monte (PI)
<
> Tel.(+39)-0587-705153  Fax.(+39)-0587-705153  WEB: http://www.classx.it
<
============================================================================

===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the
body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".

Reply via email to