c++ - pass non uniform array to shader -
i have idea of fragment shader ckecks if current fragment inside polygon. vertex values of polygon supposed transfered shader array of floats. problem uniform array of floats gets dropped (location = -1) since not directly used shader.
i don't know how pass array shader other method uniform values. can direct me better solution?
tia.
edit: (better explanation)
i have array of float values represent vertices of polygon. compute min max array , pass 2 (min/max) vectors geometry shader produces quad under polygon. now, fragment shader supposed take array of polygon vertices , analyze each fragment if inside polygon. if inside, draw color, if outside draw other color.
vertex:
in vec3 inposition; void main(void) { gl_position = vec4(inposition, 1.0); }
geometry:
layout(lines) in; layout(triangle_strip) out; layout(max_vertices = 4) out; uniform mat4 u_proj; void main() { vec4 pos0 = u_proj * gl_in[0].gl_position; vec4 pos1 = u_proj * gl_in[1].gl_position; //left gl_position.x = pos0.x; gl_position.y = pos1.y; gl_position.w = pos0.w; emitvertex(); //left down gl_position = pos0; emitvertex(); //right gl_position = pos1; emitvertex(); //right down gl_position.x = pos1.x; gl_position.y = pos0.y; gl_position.w = pos1.w; emitvertex(); endprimitive(); }
fragment:
uniform float points[570]; out vec4 outcolor; void main() { int nvert = 570; float testx = gl_fragcoord.x; float testy = gl_fragcoord.y; int i; int j; bool c = false; (i = 0, j = nvert - 3; < nvert; = + 3, j = i) { if (((points[i + 1]>testy) != (points[j + 1] > testy)) && (testx < (points[j] - points[i]) * (testy - points[i + 1]) / (points[j + 1] - points[i + 1]) + points[i])) { c = !c; } } if (c == true) { outcolor = vec4(1.0, 1.0, 1.0, 1.0); } else { outcolor = vec4(0.0, 0.0, 0.0, 1.0); } }
these:
m_fill_uniprojid = glgetuniformlocation(m_fillprogram, "u_proj"); m_fill_unicount = glgetuniformlocation(m_fillprogram, "count"); m_fill_unipoints = glgetuniformlocation(m_fillprogram, "points");
each returns -1.
this how fill uniform array:
for (int = 0; < 570; ++i) { gluniform1fv(m_fill_unipoints + i, 1, &m_points->at(i)); }
'570' temporary value used in test scene know size of polygon use.
you can pass polygon vertices varying geometry shader
Comments
Post a Comment