mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 23:14:34 +02:00
Starting on materials attributes, fixed bug with Hermite deltas.
This commit is contained in:
parent
33faffd9d4
commit
0bd800faf2
3 changed files with 30 additions and 3 deletions
|
@ -1828,6 +1828,10 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
|
||||||
}
|
}
|
||||||
glm::vec3 center;
|
glm::vec3 center;
|
||||||
glm::vec3 normal;
|
glm::vec3 normal;
|
||||||
|
const int MAX_MATERIALS_PER_VERTEX = 4;
|
||||||
|
quint8 materials[4];
|
||||||
|
glm::vec4 materialWeights;
|
||||||
|
float totalWeight = 0.0f;
|
||||||
int red = 0, green = 0, blue = 0;
|
int red = 0, green = 0, blue = 0;
|
||||||
for (int i = 0; i < crossingCount; i++) {
|
for (int i = 0; i < crossingCount; i++) {
|
||||||
const EdgeCrossing& crossing = crossings[i];
|
const EdgeCrossing& crossing = crossings[i];
|
||||||
|
@ -1836,13 +1840,34 @@ int VoxelAugmentVisitor::visit(MetavoxelInfo& info) {
|
||||||
red += qRed(crossing.color);
|
red += qRed(crossing.color);
|
||||||
green += qGreen(crossing.color);
|
green += qGreen(crossing.color);
|
||||||
blue += qBlue(crossing.color);
|
blue += qBlue(crossing.color);
|
||||||
|
if (crossing.material != 0) {
|
||||||
|
for (int j = 0; j < MAX_MATERIALS_PER_VERTEX; j++) {
|
||||||
|
if (materials[j] == crossing.material) {
|
||||||
|
materialWeights[j] += 1.0f;
|
||||||
|
totalWeight += 1.0f;
|
||||||
|
break;
|
||||||
|
|
||||||
|
} else if (materials[j] == 0.0f) {
|
||||||
|
materials[j] = crossing.material;
|
||||||
|
materialWeights[j] = 1.0f;
|
||||||
|
totalWeight += 1.0f;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
normal = glm::normalize(normal);
|
normal = glm::normalize(normal);
|
||||||
center /= crossingCount;
|
center /= crossingCount;
|
||||||
|
if (totalWeight > 0.0f) {
|
||||||
|
materialWeights *= (EIGHT_BIT_MAXIMUM / totalWeight);
|
||||||
|
}
|
||||||
VoxelPoint point = { info.minimum + (glm::vec3(clampedX, clampedY, clampedZ) +
|
VoxelPoint point = { info.minimum + (glm::vec3(clampedX, clampedY, clampedZ) +
|
||||||
center * EIGHT_BIT_MAXIMUM_RECIPROCAL) * scale,
|
center * EIGHT_BIT_MAXIMUM_RECIPROCAL) * scale,
|
||||||
{ (quint8)(red / crossingCount), (quint8)(green / crossingCount), (quint8)(blue / crossingCount) },
|
{ (quint8)(red / crossingCount), (quint8)(green / crossingCount), (quint8)(blue / crossingCount) },
|
||||||
{ (char)(normal.x * 127.0f), (char)(normal.y * 127.0f), (char)(normal.z * 127.0f) } };
|
{ (char)(normal.x * 127.0f), (char)(normal.y * 127.0f), (char)(normal.z * 127.0f) },
|
||||||
|
{ materials[0], materials[1], materials[2], materials[3] },
|
||||||
|
{ (quint8)materialWeights[0], (quint8)materialWeights[1], (quint8)materialWeights[2],
|
||||||
|
(quint8)materialWeights[3] } };
|
||||||
int index = vertices.size();
|
int index = vertices.size();
|
||||||
vertices.append(point);
|
vertices.append(point);
|
||||||
|
|
||||||
|
|
|
@ -220,6 +220,8 @@ public:
|
||||||
glm::vec3 vertex;
|
glm::vec3 vertex;
|
||||||
quint8 color[3];
|
quint8 color[3];
|
||||||
char normal[3];
|
char normal[3];
|
||||||
|
quint8 materials[4];
|
||||||
|
quint8 materialWeights[4];
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Contains the information necessary to render a voxel block.
|
/// Contains the information necessary to render a voxel block.
|
||||||
|
|
|
@ -1907,8 +1907,8 @@ void VoxelHermiteData::writeDelta(Bitstream& out, const VoxelHermiteDataPointer&
|
||||||
bool differenceZ = false;
|
bool differenceZ = false;
|
||||||
for (int y = 0; y < _size; y++) {
|
for (int y = 0; y < _size; y++) {
|
||||||
bool differenceY = false;
|
bool differenceY = false;
|
||||||
for (int x = 0; x < _size; x++) {
|
for (int x = 0; x < _size; x++, src += EDGE_COUNT, ref += EDGE_COUNT) {
|
||||||
if (*src++ != *ref++ || *src++ != *ref++ || *src++ != *ref++) {
|
if (src[0] != ref[0] || src[1] != ref[1] || src[2] != ref[2]) {
|
||||||
minX = qMin(minX, x);
|
minX = qMin(minX, x);
|
||||||
maxX = qMax(maxX, x);
|
maxX = qMax(maxX, x);
|
||||||
differenceY = differenceZ = true;
|
differenceY = differenceZ = true;
|
||||||
|
|
Loading…
Reference in a new issue