Preserving transparency when using shaders?
Posted: Wed Jul 25, 2018 1:41 pm
Heya,
I'm not sure why what I'm doing isn't working!
This is my code:
Disabling the shaders the screen looks like this:
But once I enabled them, the icon transparency disappears:
I'm at a loss because I don't really understand why the
line doesn't cut it. I also tried using color.a but to no avail.
Thanks for any help!!
I'm not sure why what I'm doing isn't working!
This is my code:
Code: Select all
shaders = {}
--Grayscale
shaders.grayscale = love.graphics.newShader[[
extern number factor;
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture, texture_coords );//This is the current pixel color
number average = (pixel.r+pixel.b+pixel.g)/3.0;
pixel.r = pixel.r + (average-pixel.r) * factor;
pixel.g = pixel.g + (average-pixel.g) * factor;
pixel.b = pixel.b + (average-pixel.b) * factor;
pixel.a = pixel.a;
return pixel;
}
]]
function love.load()
background = love.graphics.newImage("backing.png")
icon = love.graphics.newImage("icon.png")
love.window.setMode(background:getDimensions())
shader = false
end
function love.draw()
--Set the shader
if shader then
love.graphics.setShader(shaders.grayscale)
shaders.grayscale:send("factor",0)
end
love.graphics.draw(background)
love.graphics.setColor(1,1,1,0.2)
love.graphics.draw(icon,60,60)
love.graphics.setColor(1,1,1,1)
--Reset the shader
love.graphics.setShader()
end
Code: Select all
pixel.a = pixel.a
Thanks for any help!!