Love2d GLSL Shaders

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
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Love2d GLSL Shaders

Post 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
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
slime
Solid Snayke
Posts: 3176
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Love2d GLSL Shaders

Post 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:

Image
User avatar
spynaz
Party member
Posts: 152
Joined: Thu Feb 28, 2013 5:49 am

Re: Love2d GLSL Shaders

Post by spynaz »

Thanks slime and vrld. That explained alot.
User avatar
spynaz
Party member
Posts: 152
Joined: Thu Feb 28, 2013 5:49 am

Re: Love2d GLSL Shaders

Post by spynaz »

What would I set for the second parameter (Image) when I'm calling the function?
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Love2d GLSL Shaders

Post by vrld »

You're not calling the function. It's more like a callback, like love.draw().
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
spynaz
Party member
Posts: 152
Joined: Thu Feb 28, 2013 5:49 am

Re: Love2d GLSL Shaders

Post by spynaz »

I meant when I return the value.
User avatar
spynaz
Party member
Posts: 152
Joined: Thu Feb 28, 2013 5:49 am

Re: Love2d GLSL Shaders

Post by spynaz »

So, what do I set for the second parameter (image) when I return the vec4 value?
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Love2d GLSL Shaders

Post 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
Germanunkol
Party member
Posts: 712
Joined: Fri Jun 22, 2012 4:54 pm
Contact:

Re: Love2d GLSL Shaders

Post 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.
trAInsported - Write AI to control your trains
Bandana (Dev blog) - Platformer featuring an awesome little ninja by Micha and me
GridCars - Our jam entry for LD31
Germanunkol.de
User avatar
spynaz
Party member
Posts: 152
Joined: Thu Feb 28, 2013 5:49 am

Re: Love2d GLSL Shaders

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests