Page 1 of 1
Array of images to shader
Posted: Tue Mar 17, 2015 12:06 pm
by DragonChan
- Capture.PNG (30.54 KiB) Viewed 1469 times
Code: Select all
local pixelcode = [[
extern Image images[2];
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
{
vec4 texcolor = Texel(images[0], texture_coords); // same picture set to 1 or 0
return texcolor * color;
}
]]
mainShader = love.graphics.newShader(pixelcode)
love.graphics.setShader(mainShader)
drag = love.graphics.newImage('drag.gif')
scrib = love.graphics.newImage('scrib.png')
blankimg = love.graphics.newImage('blankimg.bmp')
mainShader:send('images',scrib,drag)
love.draw = function()
love.graphics.draw(blankimg)
end
Re: Array of images to shader
Posted: Thu Mar 19, 2015 1:53 pm
by DragonChan
☺
Re: Array of images to shader
Posted: Thu Mar 19, 2015 2:41 pm
by slime
LÖVE doesn't support arrays of images in shader code.
One reason is that the version of GLSL that LÖVE uses (1.20) doesn't really support them. Another reason is that in GLSL versions which do support them, you must index into the array using a constant value that can be determined at compile-time (like a literal integer number), which makes them a lot less useful than people might expect. That restriction is mostly a hardware constraint.
(The reason you get a white block when accessing anything other than the first or second indices – i.e. images[0] or images[1] – is because anything else is outside of the array's bounds. Keep in mind GLSL arrays are 0-based rather than 1-based like Lua.)
Re: Array of images to shader
Posted: Thu Mar 19, 2015 3:13 pm
by DragonChan
In Shader:send in wiki it says you can send multiple
I didn't access out of bounds, it will crash
Re: Array of images to shader
Posted: Thu Mar 19, 2015 3:18 pm
by slime
DragonChan wrote:In Shader:send in wiki it says you can send multiple
Ah, the page wiki was wrong – I updated it to not say that. Thanks!