Page 1 of 1
Shaders? How Can I Use This COOL THING!
Posted: Sun Jan 27, 2013 6:27 am
by TheP3
Hi,
So, I have not really ever programmed any glsl shader, and I saw that Love2D supports them! Making all kinds of cool FX. I really want to learn how to use glsl with Love2D! Can anyone point to the wiki location/demos for programming Love2D with shaders! I really like advice too, because, I have not seen a set example on how to use shaders in Love2D.
Thanks!
Re: Shaders? How Can I Use This COOL THING!
Posted: Sun Jan 27, 2013 10:47 am
by xXxMoNkEyMaNxXx
Look through the old forum posts, and find lots of projects using glsl. (Try a search). Examine what they do, then look at the code. The main thing you need is the effect function. I'm sure you can figure it out
To start, take a look at my file Trippy.love, somewhere...
Re: Shaders? How Can I Use This COOL THING!
Posted: Sun Jan 27, 2013 10:50 am
by xXxMoNkEyMaNxXx
Re: Shaders? How Can I Use This COOL THING!
Posted: Sun Jan 27, 2013 9:40 pm
by TheP3
Thank you,
Do you think maybe you could go into detail about the shader
Code: Select all
extern number t;
vec4 effect(vec4 colour, Image img, vec2 txy, vec2 sxy)
{
return vec4(pow(cos(sxy.x/20+t),2),pow(sin(sxy.y/20+t),2),abs(1/(1+tan(length(sxy/20)+t))),1);
}
I understand how you pass an argument into the t(var?). However, how does it know to apply that shader just to the rectangle? Also, you never called or executed effect. How did that get executed? Is it a default for Love2D or something? One last thing, the effect function was not called, so how did it get its arguments for: vec4 colour, Image img, vec2 txy, vec2 sxy?
Re: Shaders? How Can I Use This COOL THING!
Posted: Sun Jan 27, 2013 9:57 pm
by Zer0
TheP3 wrote:However, how does it know to apply that shader just to the rectangle?
The pixelEffect ( shader ) only applies to things being rendered ( in this case the square )
TheP3 wrote:Also, you never called or executed effect. How did that get executed? Is it a default for Love2D or something? One last thing, the effect function was not called, so how did it get its arguments for: vec4 colour, Image img, vec2 txy, vec2 sxy?
The effect function is called by default onto everything that is rendered on screen ( it will say )
A pixel with color 1,0,0,1 not part of an image and at coordinates 15,18 will give
{1,0,0,1} as color
nil as image ( I think )
nil as txy ( there's no image so no image coordinates )
{15,18} as sxy
essential part: effect() is called for every pixel rendered in the window
Re: Shaders? How Can I Use This COOL THING!
Posted: Sun Jan 27, 2013 10:02 pm
by TheP3
Zer0 wrote:TheP3 wrote:However, how does it know to apply that shader just to the rectangle?
The pixelEffect ( shader ) only applies to things being rendered ( in this case the square )
TheP3 wrote:Also, you never called or executed effect. How did that get executed? Is it a default for Love2D or something? One last thing, the effect function was not called, so how did it get its arguments for: vec4 colour, Image img, vec2 txy, vec2 sxy?
The effect function is called by default onto everything that is rendered on screen ( it will say )
A pixel with color 1,0,0,1 not part of an image and at coordinates 15,18 will give
{1,0,0,1} as color
nil as image ( I think )
nil as txy ( there's no image so no image coordinates )
{15,18} as sxy
essential part: effect() is called for every pixel rendered in the window
Are there any other shader functions Love2D comes with? Is there a wiki page? I really don't feel like looking through the source... haha
Re: Shaders? How Can I Use This COOL THING!
Posted: Sun Jan 27, 2013 10:11 pm
by Zer0
TheP3 wrote:Are there any other shader functions Love2D comes with? Is there a wiki page? I really don't feel like looking through the source... haha
https://www.love2d.org/wiki/love.graphi ... ixelEffect
https://www.love2d.org/wiki/PixelEffect
wiki pages