gpt4 book ai didi

c++ - 均匀优化(- 1 个值)

转载 作者:太空宇宙 更新时间:2023-11-04 13:53:16 25 4
gpt4 key购买 nike

考虑以下片段着色器:

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.countpolygon.points 被优化掉了?

最佳答案

@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);
}
}

result

感谢所有的帮助。

关于c++ - 均匀优化(- 1 个值),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22628166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com