actionscript-3flashadobemolehillagal

Problems with photoshop-like "lighten" fragment shader


I'm tagging this in OpenGL because I think it's relevant to that space (albeit a different naming).

I'm trying to get photoshop-like blending to work in Flash 11 which uses OpenGL (ES2?). I'm having particular issues with lighten, which I believe should be:

outputColor.rgb = max(base.rgb, blend.rgb);

I believe I am having issues because my layers have transparency. However, even when I pre-multiply my layers, I still am having issues (the image is too dark still).

Am I missing a step here? (This is AGAL, Adobe's gl assembly)

[Shader.Fragment]
tex ft0, v0, fs0 <2d,nearest,nomip,clamp>
tex ft1, v0, fs1 <2d,nearest,nomip,clamp>

// premultiply
mul ft2, ft1.xyzw, ft1.wwww

// premultiplied values
max oc, ft0, ft2

Solution

  • Pay attention, you are also multiplying alpha by itself.

    So instead of having ( r.a, g.a, b.a, a ), you are outputting ( r.a, g.a, b.a, a.a ), which will lead to darker image if blended with a black background

    You may try doing this :

    // premultiply
    mul ft2, ft1.xyzw, ft1.wwww
    mov ft2.w, ft1.w
    
    // premultiplied values
    max oc, ft0, ft2