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 ... :
Shader tile
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Shader tile
function love.load() end
function love.update(dt) end
function love.draw() end
function love.update(dt) end
function love.draw() end
Re: Shader tile
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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Shader tile
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;
}
]])
function love.load() end
function love.update(dt) end
function love.draw() end
function love.update(dt) end
function love.draw() end
Re: Shader tile
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;
}
]])
Artal, A .PSD loader: https://github.com/EvineDev/Artal
Re: Shader tile
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 :
it do someting like that :
if i jump a little bit :
If i rejump a little bit :
function love.load() end
function love.update(dt) end
function love.draw() end
function love.update(dt) end
function love.draw() end
Who is online
Users browsing this forum: Google [Bot] and 4 guests