Love2d GLSL Shaders
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- xXxMoNkEyMaNxXx
- Party member
- Posts: 206
- Joined: Thu Jan 10, 2013 6:16 am
- Location: Canada
Re: Love2d GLSL Shaders
What does "uniform sampler2D tex0;" do?
Re: Love2d GLSL Shaders
I don't know. :/xXxMoNkEyMaNxXx wrote:What does "uniform sampler2D tex0;" do?
Check out my latest game: http://love2d.org/forums/viewtopic.php?f=5&t=33349
- retrotails
- Party member
- Posts: 212
- Joined: Wed Apr 18, 2012 12:37 am
Re: Love2d GLSL Shaders
It stops the compiler from complaining. So it's been at the top of all my shaders.xXxMoNkEyMaNxXx wrote:What does "uniform sampler2D tex0;" do?
Re: Love2d GLSL Shaders
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.
Check out my latest game: http://love2d.org/forums/viewtopic.php?f=5&t=33349
- retrotails
- Party member
- Posts: 212
- Joined: Wed Apr 18, 2012 12:37 am
Re: Love2d GLSL Shaders
Well, that's what happens when I don't test code.spynaz wrote:That didn't do anything except just the rectangle was invisible.
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
Alright that works but what does "math.mod" and "mod" do?
Check out my latest game: http://love2d.org/forums/viewtopic.php?f=5&t=33349
- retrotails
- Party member
- Posts: 212
- Joined: Wed Apr 18, 2012 12:37 am
Re: Love2d GLSL Shaders
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.)spynaz wrote:Alright that works but what does "math.mod" and "mod" do?
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
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.
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.
Last edited by spynaz on Sat Mar 30, 2013 5:10 am, edited 1 time in total.
Check out my latest game: http://love2d.org/forums/viewtopic.php?f=5&t=33349
- xXxMoNkEyMaNxXx
- Party member
- Posts: 206
- Joined: Thu Jan 10, 2013 6:16 am
- Location: Canada
Re: Love2d GLSL Shaders
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.
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
Yea, I already knew it. Lol. But I like what you said that it works kind of like a clock.
Check out my latest game: http://love2d.org/forums/viewtopic.php?f=5&t=33349
Who is online
Users browsing this forum: Google [Bot] and 7 guests