Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 3 files). Show all
Unified · Split
| @@ -620,6 +620,22 @@ void PointBuffer::render(bool cursor) { · 619 unmodified lines | |||
| 620 | _buffer.release(); | 620 | _buffer.release(); |
| 621 | } | 621 | } |
| 622 | 622 | ||
| 623 | VoxelPointBuffer::VoxelPointBuffer(const BufferPointVector& points) : | ||
| 624 | PointBuffer(points) { | ||
| 625 | } | ||
| 626 | |||
| 627 | void VoxelPointBuffer::render(bool cursor) { | ||
| 628 | DefaultMetavoxelRendererImplementation::getPointProgram().bind(); | ||
| 629 | |||
| 630 | glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); | ||
| 631 | |||
| 632 | PointBuffer::render(cursor); | ||
| 633 | |||
| 634 | glDisable(GL_VERTEX_PROGRAM_POINT_SIZE_ARB); | ||
| 635 | |||
| 636 | DefaultMetavoxelRendererImplementation::getBaseVoxelProgram().bind(); | ||
| 637 | } | ||
| 638 | |||
| 623 | const int HeightfieldBuffer::HEIGHT_BORDER = 1; | 639 | const int HeightfieldBuffer::HEIGHT_BORDER = 1; |
| 624 | const int HeightfieldBuffer::SHARED_EDGE = 1; | 640 | const int HeightfieldBuffer::SHARED_EDGE = 1; |
| 625 | const int HeightfieldBuffer::HEIGHT_EXTENSION = 2 * HeightfieldBuffer::HEIGHT_BORDER + HeightfieldBuffer::SHARED_EDGE; | 641 | const int HeightfieldBuffer::HEIGHT_EXTENSION = 2 * HeightfieldBuffer::HEIGHT_BORDER + HeightfieldBuffer::SHARED_EDGE; |
| @@ -1117,7 +1133,10 @@ AttributeValue BufferDataAttribute::inherit(const AttributeValue& parentValue) c · 491 unmodified lines | |||
| 1117 | 1133 | ||
| 1118 | void DefaultMetavoxelRendererImplementation::init() { | 1134 | void DefaultMetavoxelRendererImplementation::init() { |
| 1119 | if (!_pointProgram.isLinked()) { | 1135 | if (!_pointProgram.isLinked()) { |
| 1120 | _pointProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + "shaders/metavoxel_point.vert"); | 1136 | _pointProgram.addShaderFromSourceFile(QGLShader::Vertex, Application::resourcesPath() + |
| 1137 | "shaders/metavoxel_point.vert"); | ||
| 1138 | _pointProgram.addShaderFromSourceFile(QGLShader::Fragment, Application::resourcesPath() + | ||
| 1139 | "shaders/metavoxel_voxel_base.frag"); | ||
| 1121 | _pointProgram.link(); | 1140 | _pointProgram.link(); |
| 1122 | 1141 | ||
| 1123 | _pointProgram.bind(); | 1142 | _pointProgram.bind(); |
| @@ -1560,11 +1579,11 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 436 unmodified lines | |||
| 1560 | if (!info.isLeaf) { | 1579 | if (!info.isLeaf) { |
| 1561 | return DEFAULT_ORDER; | 1580 | return DEFAULT_ORDER; |
| 1562 | } | 1581 | } |
| 1563 | VoxelBuffer* buffer = NULL; | 1582 | BufferData* buffer = NULL; |
| 1564 | VoxelColorDataPointer color = info.inputValues.at(0).getInlineValue<VoxelColorDataPointer>(); | 1583 | VoxelColorDataPointer color = info.inputValues.at(0).getInlineValue<VoxelColorDataPointer>(); |
| 1565 | VoxelMaterialDataPointer material = info.inputValues.at(1).getInlineValue<VoxelMaterialDataPointer>(); | 1584 | VoxelMaterialDataPointer material = info.inputValues.at(1).getInlineValue<VoxelMaterialDataPointer>(); |
| 1566 | VoxelHermiteDataPointer hermite = info.inputValues.at(2).getInlineValue<VoxelHermiteDataPointer>(); | 1585 | VoxelHermiteDataPointer hermite = info.inputValues.at(2).getInlineValue<VoxelHermiteDataPointer>(); |
| 1567 | if (color && hermite) { | 1586 | if (color && hermite && material) { |
| 1568 | QVector<VoxelPoint> vertices; | 1587 | QVector<VoxelPoint> vertices; |
| 1569 | QVector<int> indices; | 1588 | QVector<int> indices; |
| 1570 | 1589 | ||
| @@ -2092,6 +2111,53 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 521 unmodified lines | |||
| 2092 | } | 2111 | } |
| 2093 | 2112 | ||
| 2094 | buffer = new VoxelBuffer(vertices, indices, material ? material->getMaterials() : QVector<SharedObjectPointer>()); | 2113 | buffer = new VoxelBuffer(vertices, indices, material ? material->getMaterials() : QVector<SharedObjectPointer>()); |
| 2114 | |||
| 2115 | } else if (color) { | ||
| 2116 | BufferPointVector points; | ||
| 2117 | |||
| 2118 | const QVector<QRgb>& colorContents = color->getContents(); | ||
| 2119 | int size = color->getSize(); | ||
| 2120 | int area = size * size; | ||
| 2121 | int limit = size - 1; | ||
| 2122 | |||
| 2123 | const QRgb* colorZ = colorContents.constData(); | ||
| 2124 | int offset3 = size + 1; | ||
| 2125 | int offset5 = area + 1; | ||
| 2126 | int offset6 = area + size; | ||
| 2127 | int offset7 = offset6 + 1; | ||
| 2128 | const int MAX_ALPHA_TOTAL = MetavoxelNode::CHILD_COUNT * EIGHT_BIT_MAXIMUM; | ||
| 2129 | float step = info.size / limit; | ||
| 2130 | glm::vec4 minimum(info.minimum.x + step * 0.5f, info.minimum.y + step * 0.5f, info.minimum.z + step * 0.5f, 0.0f); | ||
| 2131 | |||
| 2132 | for (int z = 0; z < limit; z++) { | ||
| 2133 | const QRgb* colorY = colorZ; | ||
| 2134 | for (int y = 0; y < limit; y++) { | ||
| 2135 | const QRgb* colorX = colorY; | ||
| 2136 | for (int x = 0; x < limit; x++) { | ||
| 2137 | QRgb c0 = colorX[0], c1 = colorX[1], c2 = colorX[size], c3 = colorX[offset3], c4 = colorX[area], | ||
| 2138 | c5 = colorX[offset5], c6 = colorX[offset6], c7 = colorX[offset7]; | ||
| 2139 | colorX++; | ||
| 2140 | int a0 = qAlpha(c0), a1 = qAlpha(c1), a2 = qAlpha(c2), a3 = qAlpha(c3), | ||
| 2141 | a4 = qAlpha(c4), a5 = qAlpha(c5), a6 = qAlpha(c6), a7 = qAlpha(c7); | ||
| 2142 | int alphaTotal = a0 + a1 + a2 + a3 + a4 + a5 + a6 + a7; | ||
| 2143 | if (alphaTotal == 0 || alphaTotal == MAX_ALPHA_TOTAL) { | ||
| 2144 | continue; | ||
| 2145 | } | ||
| 2146 | BufferPoint point = { minimum + glm::vec4(x, y, z, 1.0f) * step, | ||
| 2147 | { (quint8)((qRed(c0) * a0 + qRed(c1) * a1 + qRed(c2) * a2 + qRed(c3) * a3 + qRed(c4) * a4 + | ||
| 2148 | qRed(c5) * a5 + qRed(c6) * a6 + qRed(c7) * a7) / alphaTotal), | ||
| 2149 | (quint8)((qGreen(c0) * a0 + qGreen(c1) * a1 + qGreen(c2) * a2 + qGreen(c3) * a3 + qGreen(c4) * a4 + | ||
| 2150 | qGreen(c5) * a5 + qGreen(c6) * a6 + qGreen(c7) * a7) / alphaTotal), | ||
| 2151 | (quint8)((qBlue(c0) * a0 + qBlue(c1) * a1 + qBlue(c2) * a2 + qBlue(c3) * a3 + qBlue(c4) * a4 + | ||
| 2152 | qBlue(c5) * a5 + qBlue(c6) * a6 + qBlue(c7) * a7) / alphaTotal) }, | ||
| 2153 | { 0, 127, 0 } }; | ||
| 2154 | points.append(point); | ||
| 2155 | } | ||
| 2156 | colorY += size; | ||
| 2157 | } | ||
| 2158 | colorZ += area; | ||
| 2159 | } | ||
| 2160 | buffer = new VoxelPointBuffer(points); | ||
| 2095 | } | 2161 | } |
| 2096 | BufferDataPointer pointer(buffer); | 2162 | BufferDataPointer pointer(buffer); |
| 2097 | info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer)); | 2163 | info.outputValues[0] = AttributeValue(_outputs.at(0), encodeInline(pointer)); |