Making image white

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.
User avatar
Gunroar:Cannon()
Party member
Posts: 1088
Joined: Thu Dec 10, 2020 1:57 am

Making image white

Post by Gunroar:Cannon() »

Is there any easy way without shaders to make an image completely white? Like how to make an image be black the color can be set to (0,0,0).
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
User avatar
EngineerSmith
Prole
Posts: 38
Joined: Thu Dec 02, 2021 11:38 am
Contact:

Re: Making image white

Post by EngineerSmith »

Replace the area it's being drawn with a rectangle that's white, is the best way I can think of if you don't want to use a shader. Otherwise you could look into blend modes, but none of them can do that off the top of my head.
MrFariator
Party member
Posts: 516
Joined: Wed Oct 05, 2016 11:53 am

Re: Making image white

Post by MrFariator »

Another approach I suppose would be to use stencils, but ultimately using shaders would be the better option.
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Making image white

Post by grump »

Gunroar:Cannon() wrote: Wed Dec 29, 2021 9:10 pm without shaders
*sigh*

You can make the pixels in an ImageData white and preserve the alpha channel:

Code: Select all

local imgd = love.image.newImageData('theimage.png')
imgd:mapPixel(function(x, y, r, g, b, a)
	return 1, 1, 1, a
end)
local whiteImage = love.graphics.newImage(imgd)
User avatar
Gunroar:Cannon()
Party member
Posts: 1088
Joined: Thu Dec 10, 2020 1:57 am

Re: Making image white

Post by Gunroar:Cannon() »

EngineerSmith wrote: Wed Dec 29, 2021 9:23 pm Replace the area it's being drawn with a rectangle that's white
Won't that just draw a white rectangle?

Okay, for the sake of comparison how would one go about it with shaders?
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Making image white

Post by grump »

Gunroar:Cannon() wrote: Thu Dec 30, 2021 11:34 am Won't that just draw a white rectangle?
To be fair, "How to make an image white" is not a very clear question and open to interpretation. An example image would have been helpful. An image without alpha channel would become a white rectangle, so it's a valid suggestion.
Okay, for the sake of comparison how would one go about it with shaders?

Code: Select all

vec4 effect(vec4 color, Image img, vec2 tc, vec2 fc) {
	return vec4(color.rgb, color.a * Texel(img, tc).a);
}
That's for any color and alpha set with love.graphics.setColor, not just white.
User avatar
Gunroar:Cannon()
Party member
Posts: 1088
Joined: Thu Dec 10, 2020 1:57 am

Re: Making image white

Post by Gunroar:Cannon() »

grump wrote: Thu Dec 30, 2021 12:12 pm

Code: Select all

vec4 effect(vec4 color, Image img, vec2 tc, vec2 fc) {
	return vec4(color.rgb, color.a * Texel(img, tc).a);
}
That's for any color and alpha set with love.graphics.setColor, not just white.
Nice, it worked out :3
I was scwared it won't work with all OSs
Just 2 notes (I observed, not facts):
1) It doesn't work with love.graphics.setBlendMode("alpha", "premultiplied") (Giant white block)
2) Doesn't work with setColor, though I fixed it by changing it

Code: Select all

return vec4(1,1,1,color.a * Texel(img, tc).a);
Yay, *shaida* :3

All in all, it works! Thank you all.
Oh, and I was trying to do a flashing white effect for damage taking
Image
#gamejuice #gamefeel :3 :crazy:
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Making image white

Post by grump »

Gunroar:Cannon() wrote: Thu Dec 30, 2021 5:51 pm I was scwared it won't work with all OSs
That's unreasonable. There's always shaders running. If you don't use a custom one then a default shader is used that does pretty much the same calculations as this one, just in a slightly different way. This is a pretty basic thing that'll run on a potato.
1) It doesn't work with love.graphics.setBlendMode("alpha", "premultiplied") (Giant white block)
In that case the shader should return premultiplied colors.

Code: Select all

vec4 effect(vec4 color, Image img, vec2 tc, vec2 fc) {
  float a = color.a * Texel(img, tc).a;
  return vec4(color.rgb * a, a);
}
Are you sure you have an Image that is premultiplied? Or is it a Canvas?
2) Doesn't work with setColor
I don't believe you. You did it wrong.
User avatar
Gunroar:Cannon()
Party member
Posts: 1088
Joined: Thu Dec 10, 2020 1:57 am

Re: Making image white

Post by Gunroar:Cannon() »

To make it clear, what I mean by doesn't work with setColor is that setColor makes the image not white? Is this still wrong? I honestly don't know. I'll check it later...

Edit: Oh, yes. I use premultiplied on an image. Any bad side effects? Any other simple but cool (and maybe more useless) shader tricks? E.g. rainbow? (I dunno, just thought of that off top of head)
The risk I took was calculated,
but man, am I bad at math.

-How to be saved and born again :huh:
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Making image white

Post by grump »

Gunroar:Cannon() wrote: Fri Dec 31, 2021 3:15 am To make it clear, what I mean by doesn't work with setColor is that setColor makes the image not white?
The shader + setColor makes all pixels that color. No reason why it shouldn't. Hardcoded white is the same as setColor(1, 1, 1).
Edit: Oh, yes. I use premultiplied on an image. Any bad side effects?
Yeah, blending will give wrong results unless the Image has premultiplied alpha, which is unlikely. If it looks okay with your images then go for it.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests