Passing a table to a shader
Posted: Wed Nov 26, 2014 2:05 pm
Hi,
First of all, I'm new to Löve, to lua and to glsl shaders, so I apologize in advance if I ask something stupid .
I'm trying to achieve a simple starfield effect, and I think it should be interesting to use pixel shaders for this.
I made some tests and I'm getting there, however I do have an issue: I need to give to my shader a table of vec3.
I found in the documentation a way to do it, but it works by passing explicitly all elements of the array:
This is working, but my problem is that I want to pass a 600 vec3 array...
For the record, I did try to pass the 600 parameters to myShader:send(), and it fails with "Syntax error: main.lua:xx: function or expression too complex near 'field'".
Any idea how I could do that?
My search on this forum found two interesting topic on shaders, but none of them address this issue (viewtopic.php?f=4&t=78252 and viewtopic.php?f=4&t=32605).
I'm considering passing a 1x600 pixels image, but that seems a little overkill (and the only way I found for accessing a given pixel from an image is to use the Texel() function, which will require me to normalize my 0-599 index, forcing me to do an extra multiplication/pixel).
Also I'm concern that OpenGL may try to be smart and to antialias the pixel it will return if I am not straight on the center of the pixel, which would ruin the effect.
Long story short, I could really use a little push in the right direction here and I'm open to any suggestion!
First of all, I'm new to Löve, to lua and to glsl shaders, so I apologize in advance if I ask something stupid .
I'm trying to achieve a simple starfield effect, and I think it should be interesting to use pixel shaders for this.
I made some tests and I'm getting there, however I do have an issue: I need to give to my shader a table of vec3.
I found in the documentation a way to do it, but it works by passing explicitly all elements of the array:
Code: Select all
myShader = love.graphics.newShader[[
extern vec3 field[3];
.../...
]]
for i=0,599 do
field[i] = { i+.5,2,.5 }
end
myShader:send("field",field[0],field[1],field[2]);
For the record, I did try to pass the 600 parameters to myShader:send(), and it fails with "Syntax error: main.lua:xx: function or expression too complex near 'field'".
Any idea how I could do that?
My search on this forum found two interesting topic on shaders, but none of them address this issue (viewtopic.php?f=4&t=78252 and viewtopic.php?f=4&t=32605).
I'm considering passing a 1x600 pixels image, but that seems a little overkill (and the only way I found for accessing a given pixel from an image is to use the Texel() function, which will require me to normalize my 0-599 index, forcing me to do an extra multiplication/pixel).
Also I'm concern that OpenGL may try to be smart and to antialias the pixel it will return if I am not straight on the center of the pixel, which would ruin the effect.
Long story short, I could really use a little push in the right direction here and I'm open to any suggestion!