Shader tile

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Manyrio
Prole
Posts: 29
Joined: Sat Feb 06, 2016 10:12 am

Shader tile

Post 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 :
Image
but when I test with shader it do that :
Image
I send variable to my shader.
I tested to colored the textures but it's not what I want ... :
Image
function love.load() end
function love.update(dt) end
function love.draw() end
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Shader tile

Post 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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Manyrio
Prole
Posts: 29
Joined: Sat Feb 06, 2016 10:12 am

Re: Shader tile

Post 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;
  }
]])
function love.load() end
function love.update(dt) end
function love.draw() end
User avatar
Evine
Citizen
Posts: 72
Joined: Wed May 28, 2014 11:46 pm

Re: Shader tile

Post 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;
  }
]])
Artal, A .PSD loader: https://github.com/EvineDev/Artal
Manyrio
Prole
Posts: 29
Joined: Sat Feb 06, 2016 10:12 am

Re: Shader tile

Post by Manyrio »

Hey ! Thanks, that's better but it still doesn't work :(
it do someting like that :
Image
if i jump a little bit :
Image
If i rejump a little bit :
Image
function love.load() end
function love.update(dt) end
function love.draw() end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], slime and 175 guests