我在OpenGL的选色和抗混叠方面有问题。当AA被激活时,glReadPixels的结果在目标边缘和目标交叉点上明显错误。例如:
我在一个框#32 (RGBA: 32,0,0,0)附近呈现一个框#28 (RGBA: 28,0,0,0)。使用AA,我可能得到一个错误的ReadPixel值(例如30),其中立方体和三角形重叠,或14的值在框边,由于AA算法。
我有大约4000件物品,我需要能够挑选(这是一个拼图游戏)。能够根据形状选择物体是非常重要的。
我尝试过用glDisable(GL_MULTISAMPLE)禁用AA (GL_MULTISAMPLE),但是它不适用于某些AA模式(我读到它依赖于AA实现- SS,MS,CS .)
那么,我如何选择一个底层对象呢?
发布于 2011-05-25 11:30:40
为什么不使用FBO作为您的选择缓冲区?
发布于 2015-04-12 09:51:15
我使用这个黑客:选择不只是一个像素,而是所有的3x3=9像素周围的采摘点。如果他们是一样的,我们是安全的。否则,它一定是在紧张,我们可以跳过这一点。
int renderer::pick_(int x, int y)
{
static_assert(__BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__,
"only works on little-endian architecture");
static_assert(sizeof(int) == 4,
"only works on architecture that has int size of 4");
// sort of edge detection. selection only happens at non-edge
// since the edge may cause anti-aliasing glitch
int ids[3*3];
glReadPixels(x-1, y-1, 3, 3, GL_RGBA, GL_UNSIGNED_BYTE, ids);
for (auto& id: ids) id &= 0x00FFFFFF; // mask out alpha
if (ids[0] == 0x00FFFFFF) return -1; // pure white for background
// prevent anti-aliasing glitch
bool same = true;
for (auto id: ids) same = (same && id == ids[0]);
if (same) return ids[0];
return -2; // edge
}https://stackoverflow.com/questions/6122791
复制相似问题