History

More fiddling with averages.

Andrzej Kapolka committed 12 years ago

Commit 604fc841 parent c9fb73e1 file · +87 −3Browse files

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

Unified · Split

interface/src/MetavoxelSystem.cpp+87−3
@@ -2112,10 +2112,11 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 2111 unmodified lines
21122112
21132113 buffer = new VoxelBuffer(vertices, indices, material ? material->getMaterials() : QVector<SharedObjectPointer>());
21142114
2115− } else if (color) {
2115+ } else if (color && hermite) {
21162116 BufferPointVector points;
21172117
21182118 const QVector<QRgb>& colorContents = color->getContents();
2119+ const QVector<QRgb>& hermiteContents = hermite->getContents();
21192120 int size = color->getSize();
21202121 int area = size * size;
21212122 int limit = size - 1;
@@ -2129,6 +2130,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 7 unmodified lines
21292130 float step = info.size / limit;
21302131 glm::vec4 minimum(info.minimum.x + step * 0.5f, info.minimum.y + step * 0.5f, info.minimum.z + step * 0.5f, 0.0f);
21312132
2133+ const QRgb* hermiteData = hermiteContents.constData();
2134+ int hermiteStride = hermite->getSize() * VoxelHermiteData::EDGE_COUNT;
2135+ int hermiteArea = hermiteStride * hermite->getSize();
2136+
21322137 for (int z = 0; z < limit; z++) {
21332138 const QRgb* colorY = colorZ;
21342139 for (int y = 0; y < limit; y++) {
@@ -2143,14 +2148,93 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) { · 8 unmodified lines
21432148 if (alphaTotal == 0 || alphaTotal == MAX_ALPHA_TOTAL) {
21442149 continue;
21452150 }
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,
21472231 { (quint8)((qRed(c0) * a0 + qRed(c1) * a1 + qRed(c2) * a2 + qRed(c3) * a3 + qRed(c4) * a4 +
21482232 qRed(c5) * a5 + qRed(c6) * a6 + qRed(c7) * a7) / alphaTotal),
21492233 (quint8)((qGreen(c0) * a0 + qGreen(c1) * a1 + qGreen(c2) * a2 + qGreen(c3) * a3 + qGreen(c4) * a4 +
21502234 qGreen(c5) * a5 + qGreen(c6) * a6 + qGreen(c7) * a7) / alphaTotal),
21512235 (quint8)((qBlue(c0) * a0 + qBlue(c1) * a1 + qBlue(c2) * a2 + qBlue(c3) * a3 + qBlue(c4) * a4 +
21522236 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) } };
21542238 points.append(point);
21552239 }
21562240 colorY += size;