请考虑以下片段着色器:
uniform PolygonData
{
int count;
float points[1024];
} polygon;
out vec4 outColor;
void main()
{
float j;
for (int i = 0; i < polygon.count; ++i)
{
j = polygon.points[i++];
j = polygon.points[i++];
j = polygon.points[i++];
}
outColor = vec4(1, 1, j, 1);
}
为什么 polygon.count 和 polygon.points 优化了?
答案 0 :(得分:0)
@GuyRT
是。就是这样。从那里我得到了我超过最大统一阵列大小的结论。
这就是我在做的事情:
顶点:
in vec3 inPosition;
void main(void)
{
gl_Position = vec4(inPosition, 1.0);
}
几何:
layout(lines) in;
layout(triangle_strip) out;
layout(max_vertices = 4) out;
out vec3 worldPos;
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 up
gl_Position.x = pos0.x;
gl_Position.y = pos1.y;
gl_Position.w = pos0.w;
worldPos = gl_Position.xyz;
EmitVertex();
//left down
gl_Position = pos0;
worldPos = gl_Position.xyz;
EmitVertex();
//right up
gl_Position = pos1;
worldPos = gl_Position.xyz;
EmitVertex();
//right down
gl_Position.x = pos1.x;
gl_Position.y = pos0.y;
gl_Position.w = pos1.w;
worldPos = gl_Position.xyz;
EmitVertex();
EndPrimitive();
}
片段:
struct PolyData
{
int count;
float points[256];
};
uniform PolyData p;
uniform mat4 u_proj;
in vec3 worldPos;
out vec4 outColor;
void main()
{
float testx = worldPos.x;
float testy = worldPos.y;
bool c = false;
int i;
int j;
for (i = 0, j = p.count - 4; i < p.count; j = i, i = i + 3)
{
vec4 i_vec = u_proj * vec4(p.points[i], p.points[i + 1], 0, 1.0);
vec4 j_vec = u_proj * vec4(p.points[j], p.points[j + 1], 0, 1.0);
if ( (i_vec.y >= testy) != (j_vec.y >= testy) && (testx <= (j_vec.x - i_vec.x) * (testy - i_vec.y) / (j_vec.y - i_vec.y) + i_vec.x))
c = !c;
}
if (c == true)
{
outColor = vec4(1, 1, 0, 1);
}
else
{
outColor = vec4(0, 0, 0, 0);
}
}
感谢您的帮助。