Page 2 of 6

Re: Love2d GLSL Shaders

Posted: Fri Mar 29, 2013 11:09 pm
by xXxMoNkEyMaNxXx
What does "uniform sampler2D tex0;" do?

Re: Love2d GLSL Shaders

Posted: Fri Mar 29, 2013 11:12 pm
by spynaz
xXxMoNkEyMaNxXx wrote:What does "uniform sampler2D tex0;" do?
I don't know. :/

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 12:57 am
by retrotails
xXxMoNkEyMaNxXx wrote:What does "uniform sampler2D tex0;" do?
It stops the compiler from complaining. So it's been at the top of all my shaders.

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 2:56 am
by spynaz
Retrotails, the GLSL code you told me didn't do anything to the rectangle. It only made it invisible and no matter what I change the color values to, it still was invisible.

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 3:11 am
by retrotails
spynaz wrote:That didn't do anything except just the rectangle was invisible.
Well, that's what happens when I don't test code.

Code: Select all

function love.load()
    t = 0
    shader = love.graphics.newPixelEffect [[
        extern number t      = 0.0;
        uniform sampler2D tex0;
        vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
        {
            vec4 col = vec4(1, 1, 1, cos(abs(mod(t,1) - .5)*3.14));
            return vec4( col);
        }
    ]]
end
function love.update(dt)
    t = t + dt
    if love.keyboard.isDown('escape') then love.event.quit() end
    shader:send('t', t)
end
function love.draw()
    love.graphics.setPixelEffect(shader)
    love.graphics.rectangle('fill', love.mouse.getX(), love.mouse.getY(), 64, 64)
    love.graphics.setPixelEffect()
end

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 3:21 am
by spynaz
Alright that works but what does "math.mod" and "mod" do?

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 4:21 am
by retrotails
spynaz wrote:Alright that works but what does "math.mod" and "mod" do?
The same thing, you just need 'math.' in front of it for Lua. It takes the remainder of something (or something like that, I don't know the wording.)
It basically subtracts the second number from the first until it's smaller then the 2nd number.
"mod(x, 1)" will just take a number and give you the decimal, so mod(69.2017, 1) = 0.2017
I like wolfram for playing with things
http://www.wolframalpha.com/input/?i=mod%2869.1%2C+1%29

http://www.wolframalpha.com/input/?i=mod%28x%2C+1%29

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 5:05 am
by spynaz
Oh now I know, mod is modulus. But there are 2 ways to use it in Lua:

math.mod(10, 3) = 1
10 % 3 = 1

And modulus doesn't give you the decimal, it gives you the remainder of what is needed to make the second number go into the first. As you can see in the example above, 3 does not go into 10 but it goes into 9 which is only 1 number away from 10 so the value is 1.

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 5:08 am
by xXxMoNkEyMaNxXx
I can describe mod in one word:
clock

What's 14 o' clock?
14 mod 12 = 2

This gives you the idea of how it works, but there's one difference:
12 mod 12 is 0, not still 12 o' clock.
11.999 mod 12 = 11.999
12.000 mod 12 = 0.000
12.001 mod 12 = 0.001

As a side note:
You can, however, make it work like a clock like this:
(n-1)%12+1
Where % means mod. (It actually does in Lua, C++, and I suspect many other programming languages, but you can't do % on vectors in GLSL, you have to use mod(a,b))

EDIT: Dangit, you already knew about it.

Re: Love2d GLSL Shaders

Posted: Sat Mar 30, 2013 5:16 am
by spynaz
Yea, I already knew it. Lol. But I like what you said that it works kind of like a clock.