Page 1 of 1

"Screen" blend mode

Posted: Mon Dec 26, 2011 7:39 pm
by spairoe
Is is possible in 0.8 to set the blend mode to what in Photoshop is known as screen (GL_ONE, GL_ONE_MINUS_SRC_COLOR)? Painting grey (0.5) over grey (0.5) should result in grey-white (0.75).

Re: "Screen" blend mode

Posted: Wed Dec 28, 2011 4:49 am
by hughes
You could definitely do this with a PixelEffect. Just sample two images and put them through the math for a screen effect:

Code: Select all

result = (1.0 - ((1.0 - image1) * (1.0 - image2)))

Re: "Screen" blend mode

Posted: Wed Dec 28, 2011 8:40 pm
by spairoe
Thank you for replying.

After looking at slime's bloom shader and Photoshop math, I came up with this:

Code: Select all

#define BlendScreenf(base, blend) (1.0 - ((1.0 - base) * (1.0 - blend)))
#define Blend(base, blend, funcf) vec3(funcf(base.r, blend.r), funcf(base.g, blend.g), funcf(base.b, blend.b))
#define BlendScreen(base, blend)  Blend(base, blend, BlendScreenf)

extern Image texture;

vec4 effect(vec4 color, Image drawn, vec2 texture_coords, vec2 pixel_coords) {
	vec4 base  = Texel(drawn, texture_coords);
	vec4 blend = Texel(texture, texture_coords);

	return vec4(BlendScreen(base.rgb, blend.rgb), 1);
}
While I was figuring this out, I realised that I could only blend two Images/Canvases with this shader, and that I can't use it "on the fly", blending colours as I draw e.g. rectangles on top of each other. Is this correct? Is it somehow possible to blend colours on the fly?

Re: "Screen" blend mode

Posted: Thu Dec 29, 2011 2:41 pm
by hughes
Do you actually need the Screen blend mode, or would simple additive blending work? Try playing around with love.graphics.setBlendMode("additive")

Re: "Screen" blend mode

Posted: Sun Jan 01, 2012 8:56 pm
by spairoe
Thank you for your answers. I've abandoned the idea of using that particular blend mode. I have come to understand more about shaders, so it was not for naught.