Non-Image objects for GLSL shaders
Posted: Sun May 06, 2018 4:57 am
I just started messing with GLSL shaders tonight, and I can see how this is a very powerful tool. It took me a while, but I figured most of it out, I think..
However, I have a bit of an issue. I can't seem to figure out how to apply shaders to non-image objects, such as circles and rectangles. If I want to make a blurry rectangle, I shouldn't have to make a rectangle image and draw it to the screen using a blurring shader, I should just be able to use a shader on the rectangle drawing function. Am I wrong?
I noticed that the input for the effect() function is an Image. Is there a way to input a rectangle as an image? Here's my code:
The image is drawn fine and shaded correctly, but the rectangle does not appear at all. Keep in mind I am using love2d v11.1, so rgba values are 0 to 1. I looked for a question like this and couldn't find anything.. Hopefully this hasn't been asked before.
However, I have a bit of an issue. I can't seem to figure out how to apply shaders to non-image objects, such as circles and rectangles. If I want to make a blurry rectangle, I shouldn't have to make a rectangle image and draw it to the screen using a blurring shader, I should just be able to use a shader on the rectangle drawing function. Am I wrong?
I noticed that the input for the effect() function is an Image. Is there a way to input a rectangle as an image? Here's my code:
Code: Select all
function love.load()
shader2 = love.graphics.newShader[[
vec4 effect(vec4 color, Image texture, vec2 tc, vec2 screen_coords){
vec4 pix = Texel(texture, tc);//This is the current pixel color
pix.a = tc.x+tc.y;
return pix;
}
]]
test = love.graphics.newImage("test.png");
end
function love.draw()
love.graphics.setShader(shader2);
love.graphics.setColor(0, 1, 0, 1);
love.graphics.draw(test, 20, 20);
love.graphics.rectangle("line", 300, 300, 100, 30);
love.graphics.setShader();
end