Page 3 of 6

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 5:26 am
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.

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 6:27 am
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.

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 7:15 am
by spynaz
Oh I get it now.

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 7:47 am
by xXxMoNkEyMaNxXx
Squaring or square-rooting transparencies looks the best (I can't remember which)

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 8:01 am
by spynaz
What's the difference?

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 10:23 am
by xXxMoNkEyMaNxXx
It looks better...

I should be square rooting that looks good, of my ambiguous post of last.

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 2:35 pm
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?

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 4:39 pm
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.

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 4:42 pm
by bartbes
To make your code not make me cringe:

Code: Select all

vec2 uv = texture_coords.xy;
vec3 col = texture2D(tex0, uv).rgb;

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 4:46 pm
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.