Page 1 of 1
Shader tile
Posted: Sat Mar 19, 2016 11:05 pm
by Manyrio
Hey !
I am learning Love2d GLSL shader, and if I am here it's because I have a problem :/
I want to do shadow on my tiles like this :
but when I test with shader it do that :
I send variable to my shader.
I tested to colored the textures but it's not what I want ... :
Re: Shader tile
Posted: Sat Mar 19, 2016 11:11 pm
by Nixola
We'll need to see the shader as well as the code; can you make a .love file that shows the issue? Help us help you
Re: Shader tile
Posted: Sat Mar 19, 2016 11:35 pm
by Manyrio
Here's the code :
Code: Select all
function shadwo_update()
for x = begx, endx do --math.floor((player.x)/32)+player.focus
for y = begy, endy do
if (x > begx and y > begy) and (x < endx and y < endy) then
if map[x][y] == 1 then
dark.r[x][y] = 255
dark.g[x][y] = 255
dark.b[x][y] = 255
dark.a[x][y] = 255
end
if map[x][y] ~= 1 then
dark.r[x][y] = (dark.r[x][y-1]+dark.r[x][y+1]+dark.r[x-1][y]+dark.r[x+1][y])/4.12
dark.g[x][y] = (dark.g[x][y-1]+dark.g[x][y+1]+dark.g[x-1][y]+dark.g[x+1][y])/4.12
dark.b[x][y] = (dark.b[x][y-1]+dark.b[x][y+1]+dark.b[x-1][y]+dark.b[x+1][y])/4.12
dark.a[x][y] = (dark.a[x][y-1]+dark.a[x][y+1]+dark.a[x-1][y]+dark.a[x+1][y])/4.12
end
shader.shadow:send("maskr",dark.r[x][y])
shader.shadow:send("maskg",dark.g[x][y])
shader.shadow:send("maskb",dark.b[x][y])
end
end
end
shader.shadow = love.graphics.newShader([[
extern number maskr = 0;
extern number maskg = 0;
extern number maskb = 0;
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture, vec2(screen_coords.x, screen_coords.y));
pixel.r = pixel.r-maskr/255;
pixel.g = pixel.g-maskg/255;
pixel.b = pixel.b-maskb/255;
return pixel;
}
]])
Re: Shader tile
Posted: Sun Mar 20, 2016 1:41 am
by Evine
Fixed it I think. In the shader you used the "screen_coords" while you should use "texture_coords".
Code: Select all
function shadwo_update()
for x = begx, endx do --math.floor((player.x)/32)+player.focus
for y = begy, endy do
if (x > begx and y > begy) and (x < endx and y < endy) then
if map[x][y] == 1 then
dark.r[x][y] = 255
dark.g[x][y] = 255
dark.b[x][y] = 255
dark.a[x][y] = 255
end
if map[x][y] ~= 1 then
dark.r[x][y] = (dark.r[x][y-1]+dark.r[x][y+1]+dark.r[x-1][y]+dark.r[x+1][y])/4.12
dark.g[x][y] = (dark.g[x][y-1]+dark.g[x][y+1]+dark.g[x-1][y]+dark.g[x+1][y])/4.12
dark.b[x][y] = (dark.b[x][y-1]+dark.b[x][y+1]+dark.b[x-1][y]+dark.b[x+1][y])/4.12
dark.a[x][y] = (dark.a[x][y-1]+dark.a[x][y+1]+dark.a[x-1][y]+dark.a[x+1][y])/4.12
end
shader.shadow:send("maskr",dark.r[x][y])
shader.shadow:send("maskg",dark.g[x][y])
shader.shadow:send("maskb",dark.b[x][y])
end
end
end
shader.shadow = love.graphics.newShader([[
extern number maskr = 0;
extern number maskg = 0;
extern number maskb = 0;
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords ){
vec4 pixel = Texel(texture, vec2(texture_coords.x, texture_coords.y)); // texture_coords here
pixel.r = pixel.r-maskr/255;
pixel.g = pixel.g-maskg/255;
pixel.b = pixel.b-maskb/255;
return pixel;
}
]])
Re: Shader tile
Posted: Sun Mar 20, 2016 8:51 am
by Manyrio
Hey ! Thanks, that's better but it still doesn't work
it do someting like that :
if i jump a little bit :
If i rejump a little bit :