We can send variable values to the shader just before we call love.graphics.polygon(...). How do I ensure that for each vertex I get a different variable value.
As an example I have this code:
straightforward define vertex position, X offsets and the shader:
Code: Select all
poly = {100, 200, 600, 300, 300, 500} --polygon coordinates
xoffsets = {100, -100, 20} --the offsets (as a variable mostly because I need to access them from multiple places)
me = love.graphics.newShader(--[[code below]])
Code: Select all
love.graphics.setColor(255, 255, 255)
--no shader
love.graphics.polygon('fill', poly)
love.graphics.setColor(255, 0, 0)
love.graphics.setShader(me)
m:send("xoffsets", xoffsets[1], xoffsets[2], xoffsets[3])
me:send("maxp", 2)
--what I get
love.graphics.polygon('line', poly)
love.graphics.setShader()
love.graphics.setColor(0, 255, 0)
--what I want, not a correct solution though
love.graphics.polygon('line', poly[1]+xoffsets[1], poly[2], poly[3]+xoffsets[2], poly[4], poly[5]+xoffsets[3], poly[6])
Code: Select all
extern float xoffsets[3]; //array for X offsets
int pointer; //(pseudo)pointer to xoffsets array
extern int maxp; //maximum value of pointer (we have this many vertices on this specific shape)
#ifdef VERTEX
vec4 position( mat4 transform_projection, vec4 vertex_position )
{
float xoffset = xoffsets[pointer];
pointer++;
if (maxp < pointer) {
pointer = 0;
}
vertex_position = vec4(vertex_position[0]+xoffset, vertex_position[1], vertex_position[2], vertex_position[3]);
return transform_projection * vertex_position;
}
#endif
#ifdef PIXEL
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
{
//always TRUE, need to have this, otherwise maxp doesn't exist (defined but not used) HELP??
if (maxp < 1000) {
vec4 texcolor = Texel(texture, texture_coords);
return texcolor * color;
}
}
#endif
Can this be done in shaders, and if so, how can I deliver theese additional attributes?