Showing the changes to interface/src/MetavoxelSystem.cpp (1 of 1 file). Show all
Unified · Split
| @@ -2112,10 +2112,11 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 2111 unmodified lines | |||
| 2112 | 2112 | ||
| 2113 | buffer = new VoxelBuffer(vertices, indices, material ? material->getMaterials() : QVector<SharedObjectPointer>()); | 2113 | buffer = new VoxelBuffer(vertices, indices, material ? material->getMaterials() : QVector<SharedObjectPointer>()); |
| 2114 | 2114 | ||
| 2115 | } else if (color) { | 2115 | } else if (color && hermite) { |
| 2116 | BufferPointVector points; | 2116 | BufferPointVector points; |
| 2117 | 2117 | ||
| 2118 | const QVector<QRgb>& colorContents = color->getContents(); | 2118 | const QVector<QRgb>& colorContents = color->getContents(); |
| 2119 | const QVector<QRgb>& hermiteContents = hermite->getContents(); | ||
| 2119 | int size = color->getSize(); | 2120 | int size = color->getSize(); |
| 2120 | int area = size * size; | 2121 | int area = size * size; |
| 2121 | int limit = size - 1; | 2122 | int limit = size - 1; |
| @@ -2129,6 +2130,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines | |||
| 2129 | float step = info.size / limit; | 2130 | 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 | 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 | ||
| 2133 | const QRgb* hermiteData = hermiteContents.constData(); | ||
| 2134 | int hermiteStride = hermite->getSize() * VoxelHermiteData::EDGE_COUNT; | ||
| 2135 | int hermiteArea = hermiteStride * hermite->getSize(); | ||
| 2136 | |||
| 2132 | for (int z = 0; z < limit; z++) { | 2137 | for (int z = 0; z < limit; z++) { |
| 2133 | const QRgb* colorY = colorZ; | 2138 | const QRgb* colorY = colorZ; |
| 2134 | for (int y = 0; y < limit; y++) { | 2139 | for (int y = 0; y < limit; y++) { |
| @@ -2143,14 +2148,93 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines | |||
| 2143 | if (alphaTotal == 0 || alphaTotal == MAX_ALPHA_TOTAL) { | 2148 | if (alphaTotal == 0 || alphaTotal == MAX_ALPHA_TOTAL) { |
| 2144 | continue; | 2149 | continue; |
| 2145 | } | 2150 | } |
| 2146 | BufferPoint point = { minimum + glm::vec4(x, y, z, 1.0f) * step, | 2151 | const QRgb* hermiteBase = hermiteData + z * hermiteArea + y * hermiteStride + |
| 2152 | x * VoxelHermiteData::EDGE_COUNT; | ||
| 2153 | glm::vec3 normal; | ||
| 2154 | glm::vec3 position; | ||
| 2155 | int crossingCount = 0; | ||
| 2156 | if (a0 != a1) { | ||
| 2157 | QRgb hermite = hermiteBase[0]; | ||
| 2158 | position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 0.0f); | ||
| 2159 | normal += unpackNormal(hermite); | ||
| 2160 | crossingCount++; | ||
| 2161 | } | ||
| 2162 | if (a0 != a2) { | ||
| 2163 | QRgb hermite = hermiteBase[1]; | ||
| 2164 | position += glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); | ||
| 2165 | normal += unpackNormal(hermite); | ||
| 2166 | crossingCount++; | ||
| 2167 | } | ||
| 2168 | if (a0 != a4) { | ||
| 2169 | QRgb hermite = hermiteBase[2]; | ||
| 2170 | position += glm::vec3(0.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | ||
| 2171 | normal += unpackNormal(hermite); | ||
| 2172 | crossingCount++; | ||
| 2173 | } | ||
| 2174 | if (a1 != a3) { | ||
| 2175 | QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 1]; | ||
| 2176 | position += glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f); | ||
| 2177 | normal += unpackNormal(hermite); | ||
| 2178 | crossingCount++; | ||
| 2179 | } | ||
| 2180 | if (a1 != a5) { | ||
| 2181 | QRgb hermite = hermiteBase[VoxelHermiteData::EDGE_COUNT + 2]; | ||
| 2182 | position += glm::vec3(1.0f, 0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | ||
| 2183 | normal += unpackNormal(hermite); | ||
| 2184 | crossingCount++; | ||
| 2185 | } | ||
| 2186 | if (a2 != a3) { | ||
| 2187 | QRgb hermite = hermiteBase[hermiteStride]; | ||
| 2188 | position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 0.0f); | ||
| 2189 | normal += unpackNormal(hermite); | ||
| 2190 | crossingCount++; | ||
| 2191 | } | ||
| 2192 | if (a2 != a6) { | ||
| 2193 | QRgb hermite = hermiteBase[hermiteStride + 2]; | ||
| 2194 | position += glm::vec3(0.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | ||
| 2195 | normal += unpackNormal(hermite); | ||
| 2196 | crossingCount++; | ||
| 2197 | } | ||
| 2198 | if (a3 != a7) { | ||
| 2199 | QRgb hermite = hermiteBase[hermiteStride + VoxelHermiteData::EDGE_COUNT + 2]; | ||
| 2200 | position += glm::vec3(1.0f, 1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL); | ||
| 2201 | normal += unpackNormal(hermite); | ||
| 2202 | crossingCount++; | ||
| 2203 | } | ||
| 2204 | if (a4 != a5) { | ||
| 2205 | QRgb hermite = hermiteBase[hermiteArea]; | ||
| 2206 | position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 0.0f, 1.0f); | ||
| 2207 | normal += unpackNormal(hermite); | ||
| 2208 | crossingCount++; | ||
| 2209 | } | ||
| 2210 | if (a4 != a6) { | ||
| 2211 | QRgb hermite = hermiteBase[hermiteArea + 1]; | ||
| 2212 | position += glm::vec3(0.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); | ||
| 2213 | normal += unpackNormal(hermite); | ||
| 2214 | crossingCount++; | ||
| 2215 | } | ||
| 2216 | if (a5 != a7) { | ||
| 2217 | QRgb hermite = hermiteBase[hermiteArea + VoxelHermiteData::EDGE_COUNT + 1]; | ||
| 2218 | position += glm::vec3(1.0f, qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f); | ||
| 2219 | normal += unpackNormal(hermite); | ||
| 2220 | crossingCount++; | ||
| 2221 | } | ||
| 2222 | if (a6 != a7) { | ||
| 2223 | QRgb hermite = hermiteBase[hermiteArea + hermiteStride]; | ||
| 2224 | position += glm::vec3(qAlpha(hermite) * EIGHT_BIT_MAXIMUM_RECIPROCAL, 1.0f, 1.0f); | ||
| 2225 | normal += unpackNormal(hermite); | ||
| 2226 | crossingCount++; | ||
| 2227 | } | ||
| 2228 | normal = safeNormalize(normal); | ||
| 2229 | BufferPoint point = { minimum + (glm::vec4(x, y, z, 1.0f) + | ||
| 2230 | glm::vec4(position / (float)crossingCount, 0.0f)) * step, | ||
| 2147 | { (quint8)((qRed(c0) * a0 + qRed(c1) * a1 + qRed(c2) * a2 + qRed(c3) * a3 + qRed(c4) * a4 + | 2231 | { (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), | 2232 | 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 + | 2233 | (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), | 2234 | 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 + | 2235 | (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) }, | 2236 | qBlue(c5) * a5 + qBlue(c6) * a6 + qBlue(c7) * a7) / alphaTotal) }, |
| 2153 | { 0, 127, 0 } }; | 2237 | { (quint8)(normal.x * 127.0f), (quint8)(normal.y * 127.0f), (quint8)(normal.z * 127.0f) } }; |
| 2154 | points.append(point); | 2238 | points.append(point); |
| 2155 | } | 2239 | } |
| 2156 | colorY += size; | 2240 | colorY += size; |