// getCorner: return cached/new corner with the given lattice location const HashedCubeCorner *IsoSurfacePolygonizer::getCorner(int i, int j, int k) { const Point3DKey key(i, j, k, 0); const HashedCubeCorner *result = m_cornerMap.get(key); if(result != NULL) { m_statistics.m_cornerHits++; return result; } else { HashedCubeCorner corner(key, getCornerPoint(key)); corner.setValue(evaluate(corner)); m_cornerMap.put(key, corner); return m_cornerMap.get(key); } }
void occlusionCulling(std::list<std::shared_ptr<DRBData>> &list, bool drawDebugLines) { SCOPE_profile_cpu_function("Camera system"); auto depthMap = GetRenderThread()->getDepthMapManager().getReadableMap(); //for (auto &e : cameraList->meshs) //{ // readableDepthMap->testBox() //} if (depthMap.isValid() == false) { return; } auto j = list.begin(); while (j != std::end(list)) { auto &d = *j; auto mesh = std::static_pointer_cast<DRBMeshData>(d); if (mesh->hadRenderMode(AGE_OCCLUDER)) { ++j; continue; } auto BB = mesh->getAABB(); glm::vec2 minPoint = glm::vec2(1); glm::vec2 maxPoint = glm::vec2(-1); float minZ = std::numeric_limits<float>::max(); for (std::size_t i = 0; i < 8; ++i) { auto point = depthMap->getMV() * d->getTransformation() * glm::vec4(BB.getCornerPoint(i), 1.0f); point /= point.w; if (point.x < -1) { point.x = -1; } if (point.y < -1) { point.y = -1; } if (point.x > 1) { point.x = 1; } if (point.y > 1) { point.y = 1; } minPoint.x = std::min(minPoint.x, point.x); minPoint.y = std::min(minPoint.y, point.y); maxPoint.x = std::max(maxPoint.x, point.x); maxPoint.y = std::max(maxPoint.y, point.y); point.z = (point.z + 1.0f) * 0.5f; minZ = std::min(minZ, point.z); } glm::uvec2 screenMin(((minPoint + glm::vec2(1)) / glm::vec2(2)) * glm::vec2(depthMap->getMipmapWidth(), depthMap->getMipmapHeight())); glm::uvec2 screenMax(((maxPoint + glm::vec2(1)) / glm::vec2(2)) * glm::vec2(depthMap->getMipmapWidth(), depthMap->getMipmapHeight())); if (minZ < 0) { minZ = 0; } if (depthMap->testBox((uint32_t)(minZ * (1 << 24)), screenMin, screenMax) == false) { list.erase(j++); continue; } if (drawDebugLines) { GetRenderThread()->getQueue()->emplaceTask<AGE::Commands::ToRender::Draw2DQuad>(glm::vec2(minPoint.x, minPoint.y), glm::vec2(minPoint.x, maxPoint.y), glm::vec2(maxPoint.x, maxPoint.y), glm::vec2(maxPoint.x, minPoint.y), glm::vec3(0, 1, 0)); } ++j; } }