Page 4 of 6
Re: Love2d GLSL Shaders
Posted: Sat Mar 30, 2013 6:26 pm
by vrld
retrotails wrote:...
Note that texture_coords already is a vec2, so vec2 uv = texture_coords.xy does nothing (except make things slower). Also, color is
not a vec3, but a vec4 (red, green, blue, alpha).
spynaz wrote:So I'm guessing with "texture_coords" you change the position of the rectangle and with "pixel_coords" you change how pixelated it i
I think there might be a deeper misunderstanding what a pixel effect does. The function effect() runs on
every pixel of things you draw. For an 200x200 image, the effect function is run 200 * 200 = 40000 times, kinda (but not quite) like this:
Code: Select all
for x = 0,199 do
for y = 0,199 do
image[x][y] = effect(image, color, {x/w,y/h}, {x+ox, y+oy})
end
end
Here, w and h are the width and height of the image and ox,oy are the drawing position. The parameters to the effect function are the following:
- The image you are drawing (undefined for love.graphics.rectangle and friends).
- The current color, set with love.graphics.setColor(). Caveat: r,g,b and a range not from 0 to 255 but from 0 to 1.
- The coordinates of the pixel relative to the image origin, divided by the width/height of the image. This is also known as texture coordinates.
- The coordinates of the pixel on the screen.
Hope that helps
Re: Love2d GLSL Shaders
Posted: Sat Mar 30, 2013 6:33 pm
by slime
vrld wrote:The function effect() runs on every pixel of things you draw. For an 200x200 image, the effect function is run 200 * 200 = 40000 times
To clarify, effect() runs on every pixel on your
screen that touches things you draw. If you draw a 200x200 image upscaled 2x, then the function will run 400*400 = 160,000 times.
In this image, each dot is a pixel on the (imaginary) screen. Assuming the triangle is drawn with the "fill" mode, the red dots are pixels that the effect() function will be run on:

Re: Love2d GLSL Shaders
Posted: Sat Mar 30, 2013 7:35 pm
by spynaz
Thanks slime and vrld. That explained alot.
Re: Love2d GLSL Shaders
Posted: Sat Mar 30, 2013 7:39 pm
by spynaz
What would I set for the second parameter (Image) when I'm calling the function?
Re: Love2d GLSL Shaders
Posted: Sat Mar 30, 2013 7:46 pm
by vrld
You're not calling the function. It's more like a callback, like love.draw().
Re: Love2d GLSL Shaders
Posted: Sat Mar 30, 2013 7:47 pm
by spynaz
I meant when I return the value.
Re: Love2d GLSL Shaders
Posted: Sat Mar 30, 2013 10:25 pm
by spynaz
So, what do I set for the second parameter (image) when I return the vec4 value?
Re: Love2d GLSL Shaders
Posted: Sun Mar 31, 2013 6:33 pm
by vrld
What do you mean "set"? Could you try to rephrase/explain your question? A pseudo-code example of what you want to do could also be helpful.
Re: Love2d GLSL Shaders
Posted: Sun Mar 31, 2013 7:01 pm
by Germanunkol
spynaz wrote:So, what do I set for the second parameter (image) when I return the vec4 value?
Love "sets" all those values for you internally. You don't actually call the function, you can think of it as love calling the function for you.
So when you draw an image, then the function will be called and all the parameters will be set automatically, if you used love.graphics.setPixelEffect() before you call love.graphics.draw to draw your image.
Re: Love2d GLSL Shaders
Posted: Sun Mar 31, 2013 8:25 pm
by spynaz
Germanunkol wrote:spynaz wrote:So, what do I set for the second parameter (image) when I return the vec4 value?
Love "sets" all those values for you internally. You don't actually call the function, you can think of it as love calling the function for you.
So when you draw an image, then the function will be called and all the parameters will be set automatically, if you used love.graphics.setPixelEffect() before you call love.graphics.draw to draw your image.
Oh ok.