I’m trying to port the GIMP divide blend filter code to GLSL. I’ve been able to do this for various other blend modes, but for some reason this is just not working.
Here is the C gimp code (SVG based):
if (layA == 0.0 || inCa / layCa > inA / layA)
outCa = layA * inA + layCa * (1 - inA) + inCa * (1 - layA);
else
outCa = inCa * layA * layA / layCa + layCa * (1 - inA) + inCa * (1 - layA));
Here is the ported code:
mediump float r;
if (overlay.a == 0.0 || base.r / overlay.r > base.a / overlay.a)
r = overlay.a * base.a + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);
else
r = base.r * overlay.a * overlay.a / overlay.r + overlay.r * (1.0 - base.a) + base.r * (1.0 - overlay.a);
I do this for each channel and then merge the result using vec4.
My GLSL code provides a completely different result than the GIMP C code. Unless I’ve been looking at the code for 2 hours and missed an error, I’m thinking it must be an operand order error. Or some GLSL thing that is not similar to C.
Any ideas?
Update:
How it looks like: https://i.stack.imgur.com/SnxjW.jpg
How it should look like: https://i.stack.imgur.com/LjcZi.png
The problem was in my code. I was extracting the initial values as lowp.