Array of images to shader

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
DragonChan
Prole
Posts: 3
Joined: Wed Feb 11, 2015 10:16 am

Array of images to shader

Post by DragonChan »

Capture.PNG
Capture.PNG (30.54 KiB) Viewed 1466 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
Attachments
test.love
(3.91 KiB) Downloaded 58 times
DragonChan
Prole
Posts: 3
Joined: Wed Feb 11, 2015 10:16 am

Re: Array of images to shader

Post by DragonChan »

User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Array of images to shader

Post 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.)
DragonChan
Prole
Posts: 3
Joined: Wed Feb 11, 2015 10:16 am

Re: Array of images to shader

Post by DragonChan »

In Shader:send in wiki it says you can send multiple
I didn't access out of bounds, it will crash
User avatar
slime
Solid Snayke
Posts: 3162
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

Re: Array of images to shader

Post 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!
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest