mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 16:18:05 +02:00
Finished adding concept of density to the voxel server, objects now appear more visible at a distance in an appealing way.
This commit is contained in:
parent
b7c680e3e7
commit
3ec16695f4
1 changed files with 16 additions and 21 deletions
|
@ -161,7 +161,6 @@ void VoxelNode::safeDeepDeleteChildAtIndex(int childIndex, bool& stagedForDeleti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// will average the child colors...
|
// will average the child colors...
|
||||||
void VoxelNode::setColorFromAverageOfChildren() {
|
void VoxelNode::setColorFromAverageOfChildren() {
|
||||||
int colorArray[4] = {0,0,0,0};
|
int colorArray[4] = {0,0,0,0};
|
||||||
|
@ -177,22 +176,19 @@ void VoxelNode::setColorFromAverageOfChildren() {
|
||||||
density += _children[i]->getDensity();
|
density += _children[i]->getDensity();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (_childCount > 0) {
|
|
||||||
// If there are children, density is sum of child densities
|
|
||||||
density /= (float) NUMBER_OF_CHILDREN;
|
density /= (float) NUMBER_OF_CHILDREN;
|
||||||
} else {
|
//
|
||||||
// If there are no children
|
// The VISIBLE_ABOVE_DENSITY sets the density of matter above which an averaged color voxel will
|
||||||
density = 1.f;
|
// be set. It is an important physical constant in our universe. A number below 0.5 will cause
|
||||||
}
|
// things to get 'fatter' at a distance, because upward averaging will make larger voxels out of
|
||||||
|
// less data, which is (probably) going to be preferable because it gives a sense that there is
|
||||||
if (colorArray[3] > 0) {
|
// something out there to go investigate. A number above 0.5 would cause the world to become
|
||||||
printf("children: %d, density = %4.2f\n", colorArray[3], density);
|
// more 'empty' at a distance. Exactly 0.5 would match the physical world, at least for materials
|
||||||
}
|
// that are not shiny and have equivalent ambient reflectance.
|
||||||
|
//
|
||||||
const float VISIBLE_ABOVE_DENSITY = 0.0f;
|
const float VISIBLE_ABOVE_DENSITY = 0.10f;
|
||||||
nodeColor newColor = { 0, 0, 0, 0};
|
nodeColor newColor = { 0, 0, 0, 0};
|
||||||
// if (density > VISIBLE_ABOVE_DENSITY) {
|
if (density > VISIBLE_ABOVE_DENSITY) {
|
||||||
if (colorArray[3] > 0) {
|
|
||||||
// The density of material in the space of the voxel sets whether it is actually colored
|
// The density of material in the space of the voxel sets whether it is actually colored
|
||||||
for (int c = 0; c < 3; c++) {
|
for (int c = 0; c < 3; c++) {
|
||||||
// set the average color value
|
// set the average color value
|
||||||
|
@ -201,9 +197,7 @@ void VoxelNode::setColorFromAverageOfChildren() {
|
||||||
// set the alpha to 1 to indicate that this isn't transparent
|
// set the alpha to 1 to indicate that this isn't transparent
|
||||||
newColor[3] = 1;
|
newColor[3] = 1;
|
||||||
}
|
}
|
||||||
// actually set our color, note, if we didn't have enough children
|
// Set the color from the average of the child colors, and update the density
|
||||||
// this will be the default value all zeros, and therefore be marked as
|
|
||||||
// transparent with a 4th element of 0
|
|
||||||
setColor(newColor);
|
setColor(newColor);
|
||||||
setDensity(density);
|
setDensity(density);
|
||||||
}
|
}
|
||||||
|
@ -232,20 +226,21 @@ void VoxelNode::setFalseColored(bool isFalseColored) {
|
||||||
_falseColored = isFalseColored;
|
_falseColored = isFalseColored;
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
markWithChangedTime();
|
markWithChangedTime();
|
||||||
|
_density = 1.0f; // If color set, assume leaf, re-averaging will update density if needed.
|
||||||
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
void VoxelNode::setColor(const nodeColor& color) {
|
void VoxelNode::setColor(const nodeColor& color) {
|
||||||
if (_trueColor[0] != color[0] || _trueColor[1] != color[1] || _trueColor[2] != color[2]) {
|
if (_trueColor[0] != color[0] || _trueColor[1] != color[1] || _trueColor[2] != color[2]) {
|
||||||
//printLog("VoxelNode::setColor() was: (%d,%d,%d) is: (%d,%d,%d)\n",
|
|
||||||
// _trueColor[0],_trueColor[1],_trueColor[2],color[0],color[1],color[2]);
|
|
||||||
memcpy(&_trueColor,&color,sizeof(nodeColor));
|
memcpy(&_trueColor,&color,sizeof(nodeColor));
|
||||||
if (!_falseColored) {
|
if (!_falseColored) {
|
||||||
memcpy(&_currentColor,&color,sizeof(nodeColor));
|
memcpy(&_currentColor,&color,sizeof(nodeColor));
|
||||||
}
|
}
|
||||||
_isDirty = true;
|
_isDirty = true;
|
||||||
markWithChangedTime();
|
markWithChangedTime();
|
||||||
|
_density = 1.0f; // If color set, assume leaf, re-averaging will update density if needed.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue