History

More progress toward dual contour rendering.

Andrzej Kapolka committed 12 years ago

Commit 78a03fb1 parent f02f95c3 files · +137 −21Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+135−19
@@ -1014,14 +1014,15 @@ void VoxelBuffer::render(bool cursor) { · 1013 unmodified lines
10141014 _vertexBuffer.bind();
10151015 _indexBuffer.bind();
10161016 }
1017+
10171018 VoxelPoint* point = 0;
10181019 glVertexPointer(3, GL_FLOAT, sizeof(VoxelPoint), &point->vertex);
10191020 glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VoxelPoint), &point->color);
10201021 glNormalPointer(GL_BYTE, sizeof(VoxelPoint), &point->normal);
10211022
1022− //glDrawRangeElements(GL_QUADS, 0, _vertexCount - 1, _indexCount, GL_UNSIGNED_INT, 0);
1023+ // glDrawRangeElements(GL_QUADS, 0, _vertexCount - 1, _indexCount, GL_UNSIGNED_INT, 0);
10231024
1024− glPointSize(5.0f);
1025+ glPointSize(3.0f);
10251026
10261027 glDrawArrays(GL_POINTS, 0, _vertexCount);
10271028
@@ -1569,7 +1570,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 541 unmodified lines
15691570 const QVector<QRgb>& contents = color->getContents();
15701571 int size = color->getSize();
15711572 int area = size * size;
1572− int highest = size - 1;
15731573 int offset3 = size + 1;
15741574 int offset5 = area + 1;
15751575 int offset6 = area + size;
@@ -1577,31 +1577,136 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 1 unmodified line
15771577
15781578 const QRgb* src = contents.constData();
15791579
1580+ int expanded = size + 1;
1581+ QVector<int> lineIndices(expanded, -1);
1582+ QVector<int> lastLineIndices(expanded, -1);
1583+ QVector<int> planeIndices(expanded * expanded, -1);
1584+ QVector<int> lastPlaneIndices(expanded * expanded, -1);
1585+
1586+ float highest = size - 1.0f;
15801587 float scale = info.size / highest;
15811588 const int ALPHA_OFFSET = 24;
1582− const int MAX_ALPHA_TOTAL = EIGHT_BIT_MAXIMUM * 8;
1583− for (int z = 0; z < highest; z++) {
1584− for (int y = 0; y < highest; y++) {
1585− for (int x = 0; x < highest; x++, src++) {
1589+ for (int z = 0; z < expanded; z++) {
1590+ for (int y = 0; y < expanded; y++) {
1591+ int lastIndex;
1592+ for (int x = 0; x < expanded; x++) {
15861593 int alpha0 = src[0] >> ALPHA_OFFSET;
1587− int alpha1 = src[1] >> ALPHA_OFFSET;
1588− int alpha2 = src[size] >> ALPHA_OFFSET;
1589− int alpha3 = src[offset3] >> ALPHA_OFFSET;
1590− int alpha4 = src[area] >> ALPHA_OFFSET;
1591− int alpha5 = src[offset5] >> ALPHA_OFFSET;
1592− int alpha6 = src[offset6] >> ALPHA_OFFSET;
1593− int alpha7 = src[offset7] >> ALPHA_OFFSET;
1594− int alphaTotal = alpha0 + alpha1 + alpha2 + alpha3 + alpha4 + alpha5 + alpha6 + alpha7;
1595− if (alphaTotal == 0 || alphaTotal == MAX_ALPHA_TOTAL) {
1594+ int alpha1 = alpha0, alpha2 = alpha0, alpha4 = alpha0;
1595+ int alphaTotal = alpha0;
1596+ int possibleTotal = EIGHT_BIT_MAXIMUM;
1597+ if (x != 0 && x != size) {
1598+ alphaTotal += (alpha1 = src[1] >> ALPHA_OFFSET);
1599+ possibleTotal += EIGHT_BIT_MAXIMUM;
1600+
1601+ if (y != 0 && y != size) {
1602+ alphaTotal += (src[offset3] >> ALPHA_OFFSET);
1603+ possibleTotal += EIGHT_BIT_MAXIMUM;
1604+
1605+ if (z != 0 && z != size) {
1606+ alphaTotal += (src[offset7] >> ALPHA_OFFSET);
1607+ possibleTotal += EIGHT_BIT_MAXIMUM;
1608+ }
1609+ }
1610+ if (z != 0 && z != size) {
1611+ alphaTotal += (src[offset5] >> ALPHA_OFFSET);
1612+ possibleTotal += EIGHT_BIT_MAXIMUM;
1613+ }
1614+ }
1615+ if (y != 0 && y != size) {
1616+ alphaTotal += (alpha2 = src[size] >> ALPHA_OFFSET);
1617+ possibleTotal += EIGHT_BIT_MAXIMUM;
1618+
1619+ if (z != 0 && z != size) {
1620+ alphaTotal += (src[offset6] >> ALPHA_OFFSET);
1621+ possibleTotal += EIGHT_BIT_MAXIMUM;
1622+ }
1623+ }
1624+ if (z != 0 && z != size) {
1625+ alphaTotal += (alpha4 = src[area] >> ALPHA_OFFSET);
1626+ possibleTotal += EIGHT_BIT_MAXIMUM;
1627+ }
1628+
1629+ bool generateQuad = (x != 0 && y != 0 && z != 0);
1630+ if (generateQuad) {
1631+ src++;
1632+ }
1633+ if (z == 0) {
1634+ qDebug() << "blerp" << x << y << z << alphaTotal << possibleTotal;
1635+ }
1636+ if (alphaTotal == 0 || alphaTotal == possibleTotal) {
15961637 continue; // no corners set/all corners set
15971638 }
1598− VoxelPoint point = { info.minimum + glm::vec3(x + 0.5f, y + 0.5f, z + 0.5f) * scale,
1639+ VoxelPoint point = { info.minimum + glm::vec3(glm::clamp(x - 0.5f, 0.0f, highest),
1640+ glm::clamp(y - 0.5f, 0.0f, highest), glm::clamp(z - 0.5f, 0.0f, highest)) * scale,
15991641 { 0, 0, 0 }, { 0, 127, 0} };
1642+ int index = vertices.size();
16001643 vertices.append(point);
1644+
1645+ if (generateQuad) {
1646+ if (alpha0 != alpha1) {
1647+ indices.append(index);
1648+ int index1 = lastLineIndices.at(x);
1649+ int index2 = lastPlaneIndices.at((y - 1) * expanded + x);
1650+ int index3 = lastPlaneIndices.at(y * expanded + x);
1651+ if (index1 == -1 || index2 == -1 || index3 == -1) {
1652+ qDebug() << index1 << index2 << index3 << x << y << z;
1653+ }
1654+ if (alpha0 == 0) {
1655+ indices.append(index3);
1656+ indices.append(index2);
1657+ indices.append(index1);
1658+ } else {
1659+ indices.append(index1);
1660+ indices.append(index2);
1661+ indices.append(index3);
1662+ }
1663+ }
1664+
1665+ if (alpha0 != alpha2) {
1666+ indices.append(index);
1667+ int index1 = lastIndex;
1668+ int index2 = lastPlaneIndices.at(y * expanded + x - 1);
1669+ int index3 = lastPlaneIndices.at(y * expanded + x);
1670+ if (index1 == -1 || index2 == -1 || index3 == -1) {
1671+ qDebug() << index1 << index2 << index3 << x << y << z;
1672+ }
1673+ if (alpha0 == 0) {
1674+ indices.append(index1);
1675+ indices.append(index2);
1676+ indices.append(index3);
1677+ } else {
1678+ indices.append(index3);
1679+ indices.append(index2);
1680+ indices.append(index1);
1681+ }
1682+ }
1683+
1684+ if (alpha0 != alpha4) {
1685+ indices.append(index);
1686+ int index1 = lastIndex;
1687+ int index2 = lastLineIndices.at(x - 1);
1688+ int index3 = lastLineIndices.at(x);
1689+ if (index1 == -1 || index2 == -1 || index3 == -1) {
1690+ qDebug() << index1 << index2 << index3 << x << y << z;
1691+ }
1692+ if (alpha0 == 0) {
1693+ indices.append(index3);
1694+ indices.append(index2);
1695+ indices.append(index1);
1696+ } else {
1697+ indices.append(index1);
1698+ indices.append(index2);
1699+ indices.append(index3);
1700+ }
1701+ }
1702+ }
1703+ lastIndex = index;
1704+ lineIndices[x] = index;
1705+ planeIndices[y * expanded + x] = index;
16011706 }
1602− src++;
1707+ lineIndices.swap(lastLineIndices);
16031708 }
1604− src += size;
1709+ planeIndices.swap(lastPlaneIndices);
16051710 }
16061711
16071712 buffer = new VoxelBuffer(vertices, indices, material->getMaterials());
@@ -1630,6 +1735,13 @@ void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const · 22 unmodified lines
16301735 data.setRoot(heightfieldBufferAttribute, root);
16311736 root->incrementReferenceCount();
16321737 }
1738+ const AttributePointer& voxelBufferAttribute =
1739+ Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute();
1740+ root = expandedPrevious.getRoot(voxelBufferAttribute);
1741+ if (root) {
1742+ data.setRoot(voxelBufferAttribute, root);
1743+ root->incrementReferenceCount();
1744+ }
16331745
16341746 PointAugmentVisitor pointAugmentVisitor(lod);
16351747 data.guideToDifferent(expandedPrevious, pointAugmentVisitor);
@@ -1833,9 +1945,13 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox · 197 unmodified lines
18331945 glEnableClientState(GL_COLOR_ARRAY);
18341946 glEnableClientState(GL_NORMAL_ARRAY);
18351947
1948+ glEnable(GL_CULL_FACE);
1949+
18361950 BufferRenderVisitor voxelRenderVisitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute());
18371951 data.guide(voxelRenderVisitor);
18381952
1953+ glDisable(GL_CULL_FACE);
1954+
18391955 glDisableClientState(GL_VERTEX_ARRAY);
18401956 glDisableClientState(GL_COLOR_ARRAY);
18411957 glDisableClientState(GL_NORMAL_ARRAY);