"Screen" blend mode

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
spairoe
Prole
Posts: 3
Joined: Mon Dec 26, 2011 7:33 pm

"Screen" blend mode

Post 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).
User avatar
hughes
Prole
Posts: 21
Joined: Fri Oct 28, 2011 3:10 am

Re: "Screen" blend mode

Post 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)))
spairoe
Prole
Posts: 3
Joined: Mon Dec 26, 2011 7:33 pm

Re: "Screen" blend mode

Post 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?
User avatar
hughes
Prole
Posts: 21
Joined: Fri Oct 28, 2011 3:10 am

Re: "Screen" blend mode

Post by hughes »

Do you actually need the Screen blend mode, or would simple additive blending work? Try playing around with love.graphics.setBlendMode("additive")
spairoe
Prole
Posts: 3
Joined: Mon Dec 26, 2011 7:33 pm

Re: "Screen" blend mode

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot] and 6 guests