Shaders? How Can I Use This COOL THING!

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.
Post Reply
User avatar
TheP3
Citizen
Posts: 62
Joined: Tue Dec 20, 2011 9:20 pm

Shaders? How Can I Use This COOL THING!

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

:D Thanks!
I write rules for my computer... I'm not the ruler of the world(yet)... Also, I livestream stuff http://NateAGeek.com/Live
User avatar
xXxMoNkEyMaNxXx
Party member
Posts: 206
Joined: Thu Jan 10, 2013 6:16 am
Location: Canada

Re: Shaders? How Can I Use This COOL THING!

Post 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...
User avatar
xXxMoNkEyMaNxXx
Party member
Posts: 206
Joined: Thu Jan 10, 2013 6:16 am
Location: Canada

Re: Shaders? How Can I Use This COOL THING!

Post by xXxMoNkEyMaNxXx »

User avatar
TheP3
Citizen
Posts: 62
Joined: Tue Dec 20, 2011 9:20 pm

Re: Shaders? How Can I Use This COOL THING!

Post by TheP3 »

xXxMoNkEyMaNxXx wrote:Here:
viewtopic.php?f=4&t=12354
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?
I write rules for my computer... I'm not the ruler of the world(yet)... Also, I livestream stuff http://NateAGeek.com/Live
User avatar
Zer0
Citizen
Posts: 59
Joined: Sat Oct 06, 2012 9:55 am
Location: Sweden
Contact:

Re: Shaders? How Can I Use This COOL THING!

Post 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
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
User avatar
TheP3
Citizen
Posts: 62
Joined: Tue Dec 20, 2011 9:20 pm

Re: Shaders? How Can I Use This COOL THING!

Post 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
I write rules for my computer... I'm not the ruler of the world(yet)... Also, I livestream stuff http://NateAGeek.com/Live
User avatar
Zer0
Citizen
Posts: 59
Joined: Sat Oct 06, 2012 9:55 am
Location: Sweden
Contact:

Re: Shaders? How Can I Use This COOL THING!

Post 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
If you can't fix it, Kill it with fire. ( Preferably before it lays eggs. )
Post Reply

Who is online

Users browsing this forum: No registered users and 88 guests