Love2d GLSL Shaders
Posted: Fri Mar 29, 2013 2:14 am
I have looked through lots of examples of love2d glsl shaders but I still don't get how they work and how I would make my own. I'm a total noob at shaders.
Yea. I saw you show that to someone in another forum post. But when I tried making my own, I completely failed.xXxMoNkEyMaNxXx wrote:Have you seen this one?
Code: Select all
[[
extern number t = 0.0;
uniform sampler2D tex0;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
{
vec2 uv = vec2(
mod((texture_coords.x - .5)/atan(texture_coords.y/2) + mod(t/4,1),1),
1-texture_coords.y
);
vec3 col = vec3(
texture2D(tex0,uv).x,
texture2D(tex0,uv).y,
texture2D(tex0,uv).z
);
//texture2D(tex0,uv).xyz*50.0/cLength;
return vec4( col, 1.0 );
}
]]
Code: Select all
function love.load()
effect = love.graphics.newPixelEffect [[
extern number t = 0.0;
uniform sampler2D tex0;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
{
vec3 col {
(10, 20, 10)
}
return vec4( col, 1.0 );
}
]]
end
function love.draw()
love.graphics.setPixelEffect(effect)
love.graphics.rectangle('fill', 10,305,790,285)
end
local t = 0
function love.update(dt)
t = t + dt
effect:send("t", dt)
end
spynaz wrote:Ok so I tried to test the how the color works but I got an error msg saying that it can't compile it.
Code: Select all
[[
extern number t = 0.0;
uniform sampler2D tex0;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
{
vec3 col = vec3(10, 20, 10);
return vec4( col, 1.0 );
}
]]
Code: Select all
[[
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, t);
return vec4( col);
}
]]
Code: Select all
effect:send('t', math.mod(dt, 1))