Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 3 files). Show all
Unified · Split
| @@ -1014,14 +1014,15 @@ void VoxelBuffer::render(bool cursor) { · 1013 unmodified lines | |||
| 1014 | _vertexBuffer.bind(); | 1014 | _vertexBuffer.bind(); |
| 1015 | _indexBuffer.bind(); | 1015 | _indexBuffer.bind(); |
| 1016 | } | 1016 | } |
| 1017 | |||
| 1017 | VoxelPoint* point = 0; | 1018 | VoxelPoint* point = 0; |
| 1018 | glVertexPointer(3, GL_FLOAT, sizeof(VoxelPoint), &point->vertex); | 1019 | glVertexPointer(3, GL_FLOAT, sizeof(VoxelPoint), &point->vertex); |
| 1019 | glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VoxelPoint), &point->color); | 1020 | glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VoxelPoint), &point->color); |
| 1020 | glNormalPointer(GL_BYTE, sizeof(VoxelPoint), &point->normal); | 1021 | glNormalPointer(GL_BYTE, sizeof(VoxelPoint), &point->normal); |
| 1021 | 1022 | ||
| 1022 | //glDrawRangeElements(GL_QUADS, 0, _vertexCount - 1, _indexCount, GL_UNSIGNED_INT, 0); | 1023 | // glDrawRangeElements(GL_QUADS, 0, _vertexCount - 1, _indexCount, GL_UNSIGNED_INT, 0); |
| 1023 | 1024 | ||
| 1024 | glPointSize(5.0f); | 1025 | glPointSize(3.0f); |
| 1025 | 1026 | ||
| 1026 | glDrawArrays(GL_POINTS, 0, _vertexCount); | 1027 | glDrawArrays(GL_POINTS, 0, _vertexCount); |
| 1027 | 1028 | ||
| @@ -1569,7 +1570,6 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 541 unmodified lines | |||
| 1569 | const QVector<QRgb>& contents = color->getContents(); | 1570 | const QVector<QRgb>& contents = color->getContents(); |
| 1570 | int size = color->getSize(); | 1571 | int size = color->getSize(); |
| 1571 | int area = size * size; | 1572 | int area = size * size; |
| 1572 | int highest = size - 1; | ||
| 1573 | int offset3 = size + 1; | 1573 | int offset3 = size + 1; |
| 1574 | int offset5 = area + 1; | 1574 | int offset5 = area + 1; |
| 1575 | int offset6 = area + size; | 1575 | int offset6 = area + size; |
| @@ -1577,31 +1577,136 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 1 unmodified line | |||
| 1577 | 1577 | ||
| 1578 | const QRgb* src = contents.constData(); | 1578 | const QRgb* src = contents.constData(); |
| 1579 | 1579 | ||
| 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; | ||
| 1580 | float scale = info.size / highest; | 1587 | float scale = info.size / highest; |
| 1581 | const int ALPHA_OFFSET = 24; | 1588 | const int ALPHA_OFFSET = 24; |
| 1582 | const int MAX_ALPHA_TOTAL = EIGHT_BIT_MAXIMUM * 8; | 1589 | for (int z = 0; z < expanded; z++) { |
| 1583 | for (int z = 0; z < highest; z++) { | 1590 | for (int y = 0; y < expanded; y++) { |
| 1584 | for (int y = 0; y < highest; y++) { | 1591 | int lastIndex; |
| 1585 | for (int x = 0; x < highest; x++, src++) { | 1592 | for (int x = 0; x < expanded; x++) { |
| 1586 | int alpha0 = src[0] >> ALPHA_OFFSET; | 1593 | int alpha0 = src[0] >> ALPHA_OFFSET; |
| 1587 | int alpha1 = src[1] >> ALPHA_OFFSET; | 1594 | int alpha1 = alpha0, alpha2 = alpha0, alpha4 = alpha0; |
| 1588 | int alpha2 = src[size] >> ALPHA_OFFSET; | 1595 | int alphaTotal = alpha0; |
| 1589 | int alpha3 = src[offset3] >> ALPHA_OFFSET; | 1596 | int possibleTotal = EIGHT_BIT_MAXIMUM; |
| 1590 | int alpha4 = src[area] >> ALPHA_OFFSET; | 1597 | if (x != 0 && x != size) { |
| 1591 | int alpha5 = src[offset5] >> ALPHA_OFFSET; | 1598 | alphaTotal += (alpha1 = src[1] >> ALPHA_OFFSET); |
| 1592 | int alpha6 = src[offset6] >> ALPHA_OFFSET; | 1599 | possibleTotal += EIGHT_BIT_MAXIMUM; |
| 1593 | int alpha7 = src[offset7] >> ALPHA_OFFSET; | 1600 | |
| 1594 | int alphaTotal = alpha0 + alpha1 + alpha2 + alpha3 + alpha4 + alpha5 + alpha6 + alpha7; | 1601 | if (y != 0 && y != size) { |
| 1595 | if (alphaTotal == 0 || alphaTotal == MAX_ALPHA_TOTAL) { | 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) { | ||
| 1596 | continue; // no corners set/all corners set | 1637 | continue; // no corners set/all corners set |
| 1597 | } | 1638 | } |
| 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, | ||
| 1599 | { 0, 0, 0 }, { 0, 127, 0} }; | 1641 | { 0, 0, 0 }, { 0, 127, 0} }; |
| 1642 | int index = vertices.size(); | ||
| 1600 | vertices.append(point); | 1643 | 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; | ||
| 1601 | } | 1706 | } |
| 1602 | src++; | 1707 | lineIndices.swap(lastLineIndices); |
| 1603 | } | 1708 | } |
| 1604 | src += size; | 1709 | planeIndices.swap(lastPlaneIndices); |
| 1605 | } | 1710 | } |
| 1606 | 1711 | ||
| 1607 | buffer = new VoxelBuffer(vertices, indices, material->getMaterials()); | 1712 | buffer = new VoxelBuffer(vertices, indices, material->getMaterials()); |
| @@ -1630,6 +1735,13 @@ void DefaultMetavoxelRendererImplementation::augment(MetavoxelData& data, const · 22 unmodified lines | |||
| 1630 | data.setRoot(heightfieldBufferAttribute, root); | 1735 | data.setRoot(heightfieldBufferAttribute, root); |
| 1631 | root->incrementReferenceCount(); | 1736 | root->incrementReferenceCount(); |
| 1632 | } | 1737 | } |
| 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 | } | ||
| 1633 | 1745 | ||
| 1634 | PointAugmentVisitor pointAugmentVisitor(lod); | 1746 | PointAugmentVisitor pointAugmentVisitor(lod); |
| 1635 | data.guideToDifferent(expandedPrevious, pointAugmentVisitor); | 1747 | data.guideToDifferent(expandedPrevious, pointAugmentVisitor); |
| @@ -1833,9 +1945,13 @@ void DefaultMetavoxelRendererImplementation::render(MetavoxelData& data, Metavox · 197 unmodified lines | |||
| 1833 | glEnableClientState(GL_COLOR_ARRAY); | 1945 | glEnableClientState(GL_COLOR_ARRAY); |
| 1834 | glEnableClientState(GL_NORMAL_ARRAY); | 1946 | glEnableClientState(GL_NORMAL_ARRAY); |
| 1835 | 1947 | ||
| 1948 | glEnable(GL_CULL_FACE); | ||
| 1949 | |||
| 1836 | BufferRenderVisitor voxelRenderVisitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute()); | 1950 | BufferRenderVisitor voxelRenderVisitor(Application::getInstance()->getMetavoxels()->getVoxelBufferAttribute()); |
| 1837 | data.guide(voxelRenderVisitor); | 1951 | data.guide(voxelRenderVisitor); |
| 1838 | 1952 | ||
| 1953 | glDisable(GL_CULL_FACE); | ||
| 1954 | |||
| 1839 | glDisableClientState(GL_VERTEX_ARRAY); | 1955 | glDisableClientState(GL_VERTEX_ARRAY); |
| 1840 | glDisableClientState(GL_COLOR_ARRAY); | 1956 | glDisableClientState(GL_COLOR_ARRAY); |
| 1841 | glDisableClientState(GL_NORMAL_ARRAY); | 1957 | glDisableClientState(GL_NORMAL_ARRAY); |