function love.load()
effect = love.graphics.newPixelEffect [[
extern int time;
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
{
return vec4(float(time)/2000.f , float(time)/100.f , 0.5f , 0.3f);
// return vec4((1.0+sin(time))/2.0, abs(cos(time)), abs(sin(time)), 1.0);
}
]]
end
function love.draw()
-- boring white
love.graphics.setPixelEffect()
love.graphics.rectangle('fill', 10,10,790,285)
-- LOOK AT THE PRETTY COLORS!
love.graphics.setPixelEffect(effect)
love.graphics.rectangle('fill', 10,305,790,285)
end
local t = 0
function love.update(dt)
t = t + dt
t= math.floor(t*100)
effect:send("time", t)
end
And the error itself :
graphics.lua:1339 Incalid operation
- Trying to send the wrong value type to shader variable, or
- Trying to send array values with wrong dimension, or
- invalid variable name
LÖVE 0.8.0 doesn't support extern ints in shaders. Lua can't distinguish between an integral number that should be a float, and one that should be an int, so it always tries to send all Lua numbers as floats. You could just change the "extern int" to "extern float" and it should work the same, as long as you're sending integral numbers.
In LÖVE 0.9.0 you will be able to use the Shader:sendInt method if you need to.
Also note that accessing large arrays in a shader might cause some performance issues, but that's probably not something to worry about until it becomes a real problem.
I guess it would be more correct/clear to use "extern number"? That way, you know that you're referring to a Lua number. It won't make any practical difference, but I find it easier to read.
function love.load()
effect = love.graphics.newPixelEffect [[
extern number maperx;
//extern number blocksize;
//extern vec2 mass[512];
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
{
number test = maperx *2.0f;
return vec4(1.0,1.0,1.0,1.0);
}
]]
end
It says that the variable maperx is either nonexistant or never used. I need to implicitly use the "maperx" in the return function for the code to work properly. I do realise that shaders tend to ommit unused variables but this is quite weird.
function love.load()
effect = love.graphics.newPixelEffect [[
extern number maperx;
//extern number blocksize;
//extern vec2 mass[512];
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
{
number test = maperx *2.0f;
return vec4(1.0,1.0,1.0,1.0);
}
]]
end
It says that the variable maperx is either nonexistant or never used. I need to implicitly use the "maperx" in the return function for the code to work properly. I do realise that shaders tend to ommit unused variables but this is quite weird.
Is there a point in calculating "test"? If not, can't you just comment it out? Or what kind of solution are you looking for?
I just want to make sure that once my shader code gets big I won't have to spend a couple of hours figuring what's wrong while one of my variables has been thrown away just because. I need to make sure all the things I introduce stay there.
I have managed to get some effects out of the cumbersome Love2d (no srsly, the bugs are killing me when I want to do something more advanced).
I diagnosed an issue that I find hard to solve.
My draw function consists of a loop and with each cycle I send an array of data to the shader. The problem is a black blining square on the screen. The problem is visible whenever I send data in the loop function.
I tried to used canvas as I thought there might have been a problem with double/triple buffering. It changed nothing. Whenever I send data to the shader in a loop within the draw function I get the horrible results.