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
spynaz
Party member
Posts: 152
Joined: Thu Feb 28, 2013 5:49 am

Re: Love2d GLSL Shaders

Post by spynaz »

Well anyway, I want to focus back on the color equation that retrotails gave me so I can get a better understanding of how it tweens the transparency.

The equation was this:

cos(abs(mod(t,1) - .5)*3.14)

So basically what it does here is, first, gets the modulus of "t" and 1 and subtracts 0.5 from it. Then it takes the absolute value of "mod(t,1)-.5" and multiplies it by the first 3 integers of pi. And then it figures out the cosine of all that which equals the transparency. I'm just wondering how does that slowly change the transparency back in forth. I know that sin is used to create the wavy movement though.
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: Love2d GLSL Shaders

Post by retrotails »

spynaz wrote:Well anyway, I want to focus back on the color equation that retrotails gave me so I can get a better understanding of how it tweens the transparency.

The equation was this:

cos(abs(mod(t,1) - .5)*3.14)

So basically what it does here is, first, gets the modulus of "t" and 1 and subtracts 0.5 from it. Then it takes the absolute value of "mod(t,1)-.5" and multiplies it by the first 3 integers of pi. And then it figures out the cosine of all that which equals the transparency. I'm just wondering how does that slowly change the transparency back in forth. I know that sin is used to create the wavy movement though.
"t" goes from 0 to 1 and repeats. If I subtract .5 it'll go from -.5 to .5. Then I make it absolute so it goes from .5 to 0 and back to .5, a smooth linear pulse. I take that and multiply it by pi just so I can have cosine smooth it.
User avatar
spynaz
Party member
Posts: 152
Joined: Thu Feb 28, 2013 5:49 am

Re: Love2d GLSL Shaders

Post by spynaz »

Oh I get it now.
User avatar
xXxMoNkEyMaNxXx
Party member
Posts: 206
Joined: Thu Jan 10, 2013 6:16 am
Location: Canada

Re: Love2d GLSL Shaders

Post by xXxMoNkEyMaNxXx »

Squaring or square-rooting transparencies looks the best (I can't remember which)
User avatar
spynaz
Party member
Posts: 152
Joined: Thu Feb 28, 2013 5:49 am

Re: Love2d GLSL Shaders

Post by spynaz »

What's the difference?
User avatar
xXxMoNkEyMaNxXx
Party member
Posts: 206
Joined: Thu Jan 10, 2013 6:16 am
Location: Canada

Re: Love2d GLSL Shaders

Post by xXxMoNkEyMaNxXx »

It looks better...

I should be square rooting that looks good, of my ambiguous post of last.
User avatar
spynaz
Party member
Posts: 152
Joined: Thu Feb 28, 2013 5:49 am

Re: Love2d GLSL Shaders

Post by spynaz »

Ok. Well I only used this transparency effect just to learn a bit more so that I could start creating my own. I already know what I can do with color, but I still need to know what the rest of the things are used for.

So I'm guessing with "texture_coords" you change the position of the rectangle and with "pixel_coords" you change how pixelated it is?
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: Love2d GLSL Shaders

Post by retrotails »

spynaz wrote:Ok. Well I only used this transparency effect just to learn a bit more so that I could start creating my own. I already know what I can do with color, but I still need to know what the rest of the things are used for.

So I'm guessing with "texture_coords" you change the position of the rectangle and with "pixel_coords" you change how pixelated it is?
texture_coords.xyz gives you the position of the pixel in the loop on the texture. You can use that to modify UV coordinates however.

Code: Select all

vec2 uv         = vec2(
    texture_coords.x,
    texture_coords.y
);
vec3 col        = vec3(
    texture2D(tex0,uv).x,
    texture2D(tex0,uv).y,
    texture2D(tex0,uv).z
);

That makes a new variable called 'uv' with texture coordinates, which you can modify.
The vec3() holds color information with x=r, y=g, z=b.
You can also modify all 3 at once with something like 'col += .5'

pixel_coords are the same as texture_coords except it gives you the pixel instead of a number between 0 and 1.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Love2d GLSL Shaders

Post by bartbes »

To make your code not make me cringe:

Code: Select all

vec2 uv = texture_coords.xy;
vec3 col = texture2D(tex0, uv).rgb;
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: Love2d GLSL Shaders

Post by retrotails »

bartbes wrote:To make your code not make me cringe:

Code: Select all

vec2 uv = texture_coords.xy;
vec3 col = texture2D(tex0, uv).rgb;
eh, I copy and paste it and do a few things like invert texture_coords.y, add a noise function at different strengths for each color etc. then I cut it down.
Post Reply

Who is online

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