History

Remove the "render lower detail as points" option. It doesn't seem too promising.

Andrzej Kapolka committed 12 years ago

Commit 37eff681 parent b5b82ed4 files · +34 −224Browse files

Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 4 files). Show all

Unified · Split

interface/src/MetavoxelSystem.cpp+34−206
@@ -640,63 +640,6 @@ void PointBuffer::render(bool cursor) { · 639 unmodified lines
640 _buffer.release();640 _buffer.release();
641}641}
642 642
643VoxelPointBuffer::VoxelPointBuffer(const BufferPointVector& points, const QVector<glm::vec3>& hermite) :
644 PointBuffer(points),
645 _hermite(hermite),
646 _hermiteCount(hermite.size()) {
647}
648
649static void renderHermiteData(QVector<glm::vec3>& hermite, int hermiteCount, QOpenGLBuffer& hermiteBuffer) {
650 if (hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {
651 if (!hermiteBuffer.isCreated()) {
652 hermiteBuffer.create();
653 hermiteBuffer.bind();
654 hermiteBuffer.allocate(hermite.constData(), hermite.size() * sizeof(glm::vec3));
655 hermite.clear();
656
657 } else {
658 hermiteBuffer.bind();
659 }
660
661 glDisableClientState(GL_COLOR_ARRAY);
662 glDisableClientState(GL_NORMAL_ARRAY);
663
664 glVertexPointer(3, GL_FLOAT, 0, 0);
665
666 Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().bind();
667
668 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
669 glNormal3f(0.0f, 1.0f, 0.0f);
670
671 glLineWidth(2.0f);
672
673 glDrawArrays(GL_LINES, 0, hermiteCount);
674
675 glLineWidth(1.0f);
676
677 DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind();
678
679 glEnableClientState(GL_COLOR_ARRAY);
680 glEnableClientState(GL_NORMAL_ARRAY);
681
682 hermiteBuffer.release();
683 }
684}
685
686void VoxelPointBuffer::render(bool cursor) {
687 DefaultMetavoxelRendererImplementation::getPointProgram().bind();
688
689 glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
690
691 PointBuffer::render(cursor);
692
693 glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB);
694
695 DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind();
696
697 renderHermiteData(_hermite, _hermiteCount, _hermiteBuffer);
698}
699
700const int HeightfieldBuffer::HEIGHT_BORDER = 1;643const int HeightfieldBuffer::HEIGHT_BORDER = 1;
701const int HeightfieldBuffer::SHARED_EDGE = 1;644const int HeightfieldBuffer::SHARED_EDGE = 1;
702const int HeightfieldBuffer::HEIGHT_EXTENSION = 2 * HeightfieldBuffer::HEIGHT_BORDER + HeightfieldBuffer::SHARED_EDGE;645const int HeightfieldBuffer::HEIGHT_EXTENSION = 2 * HeightfieldBuffer::HEIGHT_BORDER + HeightfieldBuffer::SHARED_EDGE;
@@ -1175,7 +1118,38 @@ void VoxelBuffer::render(bool cursor) { · 472 unmodified lines
1175 _vertexBuffer.release();1118 _vertexBuffer.release();
1176 _indexBuffer.release();1119 _indexBuffer.release();
1177 1120
1178 renderHermiteData(_hermite, _hermiteCount, _hermiteBuffer);1121 if (_hermiteCount > 0 && Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData)) {
1122 if (!_hermiteBuffer.isCreated()) {
1123 _hermiteBuffer.create();
1124 _hermiteBuffer.bind();
1125 _hermiteBuffer.allocate(_hermite.constData(), _hermite.size() * sizeof(glm::vec3));
1126 _hermite.clear();
1127
1128 } else {
1129 _hermiteBuffer.bind();
1130 }
1131
1132 glDisableClientState(GL_COLOR_ARRAY);
1133 glDisableClientState(GL_NORMAL_ARRAY);
1134
1135 glVertexPointer(3, GL_FLOAT, 0, 0);
1136
1137 Application::getInstance()->getDeferredLightingEffect()->getSimpleProgram().bind();
1138
1139 glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
1140 glNormal3f(0.0f, 1.0f, 0.0f);
1141
1142 glLineWidth(1.0f);
1143
1144 glDrawArrays(GL_LINES, 0, _hermiteCount);
1145
1146 DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind();
1147
1148 glEnableClientState(GL_COLOR_ARRAY);
1149 glEnableClientState(GL_NORMAL_ARRAY);
1150
1151 _hermiteBuffer.release();
1152 }
1179}1153}
1180 1154
1181BufferDataAttribute::BufferDataAttribute(const QString& name) :1155BufferDataAttribute::BufferDataAttribute(const QString& name) :
@@ -1644,14 +1618,12 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 462 unmodified lines
1644 if (!info.isLeaf) {1618 if (!info.isLeaf) {
1645 return DEFAULT_ORDER;1619 return DEFAULT_ORDER;
1646 }1620 }
1647 const int EDGES_PER_CUBE = 12;
1648
1649 BufferData* buffer = NULL;1621 BufferData* buffer = NULL;
1650 VoxelColorDataPointer color = info.inputValues.at(0).getInlineValue<VoxelColorDataPointer>();1622 VoxelColorDataPointer color = info.inputValues.at(0).getInlineValue<VoxelColorDataPointer>();
1651 VoxelMaterialDataPointer material = info.inputValues.at(1).getInlineValue<VoxelMaterialDataPointer>();1623 VoxelMaterialDataPointer material = info.inputValues.at(1).getInlineValue<VoxelMaterialDataPointer>();
1652 VoxelHermiteDataPointer hermite = info.inputValues.at(2).getInlineValue<VoxelHermiteDataPointer>();1624 VoxelHermiteDataPointer hermite = info.inputValues.at(2).getInlineValue<VoxelHermiteDataPointer>();
1653 1625
1654 if (color && hermite && (material || !Menu::getInstance()->isOptionChecked(MenuOption::LowerDetailAsPoints))) {1626 if (color && hermite) {
1655 QVector<VoxelPoint> vertices;1627 QVector<VoxelPoint> vertices;
1656 QVector<int> indices;1628 QVector<int> indices;
1657 QVector<glm::vec3> hermiteSegments;1629 QVector<glm::vec3> hermiteSegments;
@@ -1686,6 +1658,7 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 28 unmodified lines
1686 QVector<AxisIndex> planeIndices(expanded * expanded);1658 QVector<AxisIndex> planeIndices(expanded * expanded);
1687 QVector<AxisIndex> lastPlaneIndices(expanded * expanded);1659 QVector<AxisIndex> lastPlaneIndices(expanded * expanded);
1688 1660
1661 const int EDGES_PER_CUBE = 12;
1689 EdgeCrossing crossings[EDGES_PER_CUBE];1662 EdgeCrossing crossings[EDGES_PER_CUBE];
1690 1663
1691 float highest = size - 1.0f;1664 float highest = size - 1.0f;
@@ -2187,151 +2160,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 495 unmodified lines
2187 }2160 }
2188 buffer = new VoxelBuffer(vertices, indices, hermiteSegments,2161 buffer = new VoxelBuffer(vertices, indices, hermiteSegments,
2189 material ? material->getMaterials() : QVector<SharedObjectPointer>());2162 material ? material->getMaterials() : QVector<SharedObjectPointer>());
2190
2191 } else if (color && hermite) {
2192 BufferPointVector points;
2193 QVector<glm::vec3> hermiteSegments;
2194
2195 const QVector<QRgb>& colorContents = color->getContents();
2196 const QVector<QRgb>& hermiteContents = hermite->getContents();
2197 int size = color->getSize();
2198 int area = size * size;
2199 int limit = size - 1;
2200
2201 const QRgb* colorZ = colorContents.constData();
2202 int offset3 = size + 1;
2203 int offset5 = area + 1;
2204 int offset6 = area + size;
2205 int offset7 = offset6 + 1;
2206 const int MAX_ALPHA_TOTAL = MetavoxelNode::CHILD_COUNT * EIGHT_BIT_MAXIMUM;
2207 float step = info.size / limit;
2208 glm::vec4 minimum(info.minimum.x + step * 0.5f, info.minimum.y + step * 0.5f, info.minimum.z + step * 0.5f, 0.0f);
2209
2210 const QRgb* hermiteData = hermiteContents.constData();
2211 int hermiteStride = hermite->getSize() * VoxelHermiteData::EDGE_COUNT;
2212 int hermiteArea = hermiteStride * hermite->getSize();
2213 bool displayHermite = Menu::getInstance()->isOptionChecked(MenuOption::DisplayHermiteData);
2214
2215 EdgeCrossing crossings[EDGES_PER_CUBE];
2216
2217 for (int z = 0; z < limit; z++) {
2218 const QRgb* colorY = colorZ;
2219 for (int y = 0; y < limit; y++) {
2220 const QRgb* colorX = colorY;
2221 for (int x = 0; x < limit; x++) {
2222 QRgb c0 = colorX[0], c1 = colorX[1], c2 = colorX[size], c3 = colorX[offset3], c4 = colorX[area],
2223 c5 = colorX[offset5], c6 = colorX[offset6], c7 = colorX[offset7];
2224 colorX++;
2225 int a0 = qAlpha(c0), a1 = qAlpha(c1), a2 = qAlpha(c2), a3 = qAlpha(c3),
2226 a4 = qAlpha(c4), a5 = qAlpha(c5), a6 = qAlpha(c6), a7 = qAlpha(c7);
2227 int alphaTotal = a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7;
2228 if (alphaTotal == 0 || alphaTotal == MAX_ALPHA_TOTAL) {
2229 continue;
2230 }
2231 const QRgb* hermiteBase = hermiteData + z * hermiteArea + y * hermiteStride +
2232 x * VoxelHermiteData::EDGE_COUNT;
2233 int crossingCount = 0;
2234 if (a0 != a1) {
2235 QRgb hermite = hermiteBase[0];
2236 EdgeCrossing& crossing = crossings[crossingCount++];
2237 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f);
2238 crossing.normal = unpackNormal(hermite);
2239 }
2240 if (a0 != a2) {
2241 QRgb hermite = hermiteBase[1];
2242 EdgeCrossing& crossing = crossings[crossingCount++];
2243 crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);
2244 crossing.normal = unpackNormal(hermite);
2245 }
2246 if (a0 != a4) {
2247 QRgb hermite = hermiteBase[2];
2248 EdgeCrossing& crossing = crossings[crossingCount++];
2249 crossing.point = glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2250 crossing.normal = unpackNormal(hermite);
2251 }
2252 if (a1 != a3) {
2253 QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 1];
2254 EdgeCrossing& crossing = crossings[crossingCount++];
2255 crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f);
2256 crossing.normal = unpackNormal(hermite);
2257 }
2258 if (a1 != a5) {
2259 QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 2];
2260 EdgeCrossing& crossing = crossings[crossingCount++];
2261 crossing.point = glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2262 crossing.normal = unpackNormal(hermite);
2263 }
2264 if (a2 != a3) {
2265 QRgb hermite = hermiteBase[hermiteStride];
2266 EdgeCrossing& crossing = crossings[crossingCount++];
2267 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f);
2268 crossing.normal = unpackNormal(hermite);
2269 }
2270 if (a2 != a6) {
2271 QRgb hermite = hermiteBase[hermiteStride + 2];
2272 EdgeCrossing& crossing = crossings[crossingCount++];
2273 crossing.point = glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2274 crossing.normal = unpackNormal(hermite);
2275 }
2276 if (a3 != a7) {
2277 QRgb hermite = hermiteBase[hermiteStride + VoxelHermiteData::EDGE_COUNT + 2];
2278 EdgeCrossing& crossing = crossings[crossingCount++];
2279 crossing.point = glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL);
2280 crossing.normal = unpackNormal(hermite);
2281 }
2282 if (a4 != a5) {
2283 QRgb hermite = hermiteBase[hermiteArea];
2284 EdgeCrossing& crossing = crossings[crossingCount++];
2285 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f);
2286 crossing.normal = unpackNormal(hermite);
2287 }
2288 if (a4 != a6) {
2289 QRgb hermite = hermiteBase[hermiteArea + 1];
2290 EdgeCrossing& crossing = crossings[crossingCount++];
2291 crossing.point = glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);
2292 crossing.normal = unpackNormal(hermite);
2293 }
2294 if (a5 != a7) {
2295 QRgb hermite = hermiteBase[hermiteArea + VoxelHermiteData::EDGE_COUNT + 1];
2296 EdgeCrossing& crossing = crossings[crossingCount++];
2297 crossing.point = glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f);
2298 crossing.normal = unpackNormal(hermite);
2299 }
2300 if (a6 != a7) {
2301 QRgb hermite = hermiteBase[hermiteArea + hermiteStride];
2302 EdgeCrossing& crossing = crossings[crossingCount++];
2303 crossing.point = glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f);
2304 crossing.normal = unpackNormal(hermite);
2305 }
2306 glm::vec3 normal;
2307 glm::vec3 position;
2308 for (int i = 0; i < crossingCount; i++) {
2309 const EdgeCrossing& crossing = crossings[i];
2310 position += crossing.point;
2311 normal += crossing.normal;
2312 if (displayHermite) {
2313 glm::vec3 base = glm::vec3(minimum) + (glm::vec3(x, y, z) + crossing.point) * step;
2314 hermiteSegments.append(base);
2315 hermiteSegments.append(base + crossing.normal * step);
2316 }
2317 }
2318 normal = safeNormalize(normal);
2319 BufferPoint point = { minimum + (glm::vec4(x, y, z, 1.0f) +
2320 glm::vec4(position / (float)crossingCount, 0.0f)) * step,
2321 { (quint8)((qRed(c0) * a0 + qRed(c1) * a1 + qRed(c2) * a2 + qRed(c3) * a3 + qRed(c4) * a4 +
2322 qRed(c5) * a5 + qRed(c6) * a6 + qRed(c7) * a7) / alphaTotal),
2323 (quint8)((qGreen(c0) * a0 + qGreen(c1) * a1 + qGreen(c2) * a2 + qGreen(c3) * a3 + qGreen(c4) * a4 +
2324 qGreen(c5) * a5 + qGreen(c6) * a6 + qGreen(c7) * a7) / alphaTotal),
2325 (quint8)((qBlue(c0) * a0 + qBlue(c1) * a1 + qBlue(c2) * a2 + qBlue(c3) * a3 + qBlue(c4) * a4 +
2326 qBlue(c5) * a5 + qBlue(c6) * a6 + qBlue(c7) * a7) / alphaTotal) },
2327 { (quint8)(normal.x * 127.0f), (quint8)(normal.y * 127.0f), (quint8)(normal.z * 127.0f) } };
2328 points.append(point);
2329 }
2330 colorY += size;
2331 }
2332 colorZ += area;
2333 }
2334 buffer = new VoxelPointBuffer(points, hermiteSegments);
2335 }2163 }
2336 BufferDataPointer pointer(buffer);2164 BufferDataPointer pointer(buffer);
2337 info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));2165 info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer));