Making image white
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Gunroar:Cannon()
- Party member
- Posts: 1088
- Joined: Thu Dec 10, 2020 1:57 am
Making image white
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).
- EngineerSmith
- Prole
- Posts: 38
- Joined: Thu Dec 02, 2021 11:38 am
- Contact:
Re: Making image white
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.
-
- Party member
- Posts: 516
- Joined: Wed Oct 05, 2016 11:53 am
Re: Making image white
Another approach I suppose would be to use stencils, but ultimately using shaders would be the better option.
Re: Making image white
*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)
- Gunroar:Cannon()
- Party member
- Posts: 1088
- Joined: Thu Dec 10, 2020 1:57 am
Re: Making image white
Won't that just draw a white rectangle?EngineerSmith wrote: ↑Wed Dec 29, 2021 9:23 pm Replace the area it's being drawn with a rectangle that's white
Okay, for the sake of comparison how would one go about it with shaders?
Re: Making image white
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);
}
- Gunroar:Cannon()
- Party member
- Posts: 1088
- Joined: Thu Dec 10, 2020 1:57 am
Re: Making image white
Nice, it worked outgrump wrote: ↑Thu Dec 30, 2021 12:12 pmThat's for any color and alpha set with love.graphics.setColor, not just white.Code: Select all
vec4 effect(vec4 color, Image img, vec2 tc, vec2 fc) { return vec4(color.rgb, color.a * Texel(img, tc).a); }
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);
All in all, it works! Thank you all.
Oh, and I was trying to do a flashing white effect for damage taking
#gamejuice #gamefeel
Re: Making image white
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.
In that case the shader should return premultiplied colors.1) It doesn't work with love.graphics.setBlendMode("alpha", "premultiplied") (Giant white block)
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);
}
I don't believe you. You did it wrong.2) Doesn't work with setColor
- Gunroar:Cannon()
- Party member
- Posts: 1088
- Joined: Thu Dec 10, 2020 1:57 am
Re: Making image white
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)
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)
Re: Making image 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).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?
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.Edit: Oh, yes. I use premultiplied on an image. Any bad side effects?
Who is online
Users browsing this forum: Google [Bot] and 8 guests