From 5ec9017d3bb92135a8a58141020194e2c826f87e Mon Sep 17 00:00:00 2001 From: Andrzej Kapolka Date: Wed, 11 Dec 2013 18:00:17 -0800 Subject: [PATCH] More metavoxel bits. --- interface/src/Application.cpp | 19 +++++++++++++- interface/src/Application.h | 1 + interface/src/Menu.cpp | 3 ++- interface/src/Menu.h | 1 + interface/src/renderer/MetavoxelSystem.cpp | 26 ++++++++++++------- interface/src/renderer/MetavoxelSystem.h | 3 +++ .../metavoxels/src/AttributeRegistry.cpp | 6 ++--- libraries/metavoxels/src/AttributeRegistry.h | 13 ++++++++++ 8 files changed, 58 insertions(+), 14 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 2a8e7f4651..65305918d7 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2320,6 +2320,15 @@ void Application::updateParticles(float deltaTime) { } } +void Application::updateMetavoxels(float deltaTime) { + bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); + PerformanceWarning warn(showWarnings, "Application::updateMetavoxels()"); + + if (Menu::getInstance()->isOptionChecked(MenuOption::Metavoxels)) { + _metavoxels.simulate(deltaTime); + } +} + void Application::updateTransmitter(float deltaTime) { bool showWarnings = Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings); PerformanceWarning warn(showWarnings, "Application::updateTransmitter()"); @@ -2465,6 +2474,7 @@ void Application::update(float deltaTime) { updateAvatars(deltaTime, mouseRayOrigin, mouseRayDirection); //loop through all the other avatars and simulate them... updateMyAvatarSimulation(deltaTime); // Simulate myself updateParticles(deltaTime); // Simulate particle cloud movements + updateMetavoxels(deltaTime); // update metavoxels updateTransmitter(deltaTime); // transmitter drive or pick updateCamera(deltaTime); // handle various camera tweaks like off axis projection updateDialogs(deltaTime); // update various stats dialogs if present @@ -2999,7 +3009,14 @@ void Application::displaySide(Camera& whichCamera, bool selfAvatarOnly) { _voxels.render(Menu::getInstance()->isOptionChecked(MenuOption::VoxelTextures)); } } - + + // also, metavoxels + if (Menu::getInstance()->isOptionChecked(MenuOption::Metavoxels)) { + PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), + "Application::displaySide() ... metavoxels..."); + _metavoxels.render(); + } + // render the ambient occlusion effect if enabled if (Menu::getInstance()->isOptionChecked(MenuOption::AmbientOcclusion)) { PerformanceWarning warn(Menu::getInstance()->isOptionChecked(MenuOption::PipelineWarnings), diff --git a/interface/src/Application.h b/interface/src/Application.h index c1e178838b..54f18c1080 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -269,6 +269,7 @@ private: void updateThreads(float deltaTime); void updateMyAvatarSimulation(float deltaTime); void updateParticles(float deltaTime); + void updateMetavoxels(float deltaTime); void updateTransmitter(float deltaTime); void updateCamera(float deltaTime); void updateDialogs(float deltaTime); diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 13510067cd..0794522b58 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -281,7 +281,8 @@ Menu::Menu() : addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::ParticleCloud, 0, false); addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Shadows, 0, false); - + addCheckableActionToQMenuAndActionHash(renderOptionsMenu, MenuOption::Metavoxels, 0, false); + QMenu* voxelOptionsMenu = developerMenu->addMenu("Voxel Options"); diff --git a/interface/src/Menu.h b/interface/src/Menu.h index aa3b925517..b6ea1ae8b5 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -209,6 +209,7 @@ namespace MenuOption { const QString Login = "Login"; const QString LookAtIndicator = "Look-at Indicator"; const QString LookAtVectors = "Look-at Vectors"; + const QString Metavoxels = "Metavoxels"; const QString Mirror = "Mirror"; const QString MoveWithLean = "Move with Lean"; const QString NewVoxelCullingMode = "New Voxel Culling Mode"; diff --git a/interface/src/renderer/MetavoxelSystem.cpp b/interface/src/renderer/MetavoxelSystem.cpp index d813ac1653..7cb5987bb7 100644 --- a/interface/src/renderer/MetavoxelSystem.cpp +++ b/interface/src/renderer/MetavoxelSystem.cpp @@ -10,16 +10,16 @@ #include "MetavoxelSystem.h" -class DebugVisitor : public MetavoxelVisitor { +class PointVisitor : public MetavoxelVisitor { public: virtual bool visit(const MetavoxelInfo& info); }; -bool DebugVisitor::visit(const MetavoxelInfo& info) { +bool PointVisitor::visit(const MetavoxelInfo& info) { QRgb color = info.attributeValues.at(0).getInlineValue(); - qDebug("%g %g %g %g %d %d %d %d\n", info.minimum.x, info.minimum.y, info.minimum.z, info.size, - qRed(color), qGreen(color), qBlue(color), qAlpha(color)); + QRgb normal = info.attributeValues.at(1).getInlineValue(); + return true; } @@ -29,12 +29,20 @@ void MetavoxelSystem::init() { p1 += 1; p1 += 2; - AttributePointer diffuseColor = AttributeRegistry::getInstance()->getAttribute("diffuseColor"); + AttributePointer color = AttributeRegistry::getInstance()->getAttribute("color"); void* white = encodeInline(qRgba(0xFF, 0xFF, 0xFF, 0xFF)); - _data.setAttributeValue(p1, AttributeValue(diffuseColor, &white)); - - DebugVisitor visitor; - _data.visitVoxels(QVector() << diffuseColor, visitor); + _data.setAttributeValue(p1, AttributeValue(color, &white)); } +void MetavoxelSystem::simulate(float deltaTime) { + QVector attributes; + attributes << AttributeRegistry::getInstance()->getColorAttribute(); + attributes << AttributeRegistry::getInstance()->getNormalAttribute(); + PointVisitor visitor; + _data.visitVoxels(attributes, visitor); +} + +void MetavoxelSystem::render() { + +} diff --git a/interface/src/renderer/MetavoxelSystem.h b/interface/src/renderer/MetavoxelSystem.h index 107f6f49f4..ffb73290f3 100644 --- a/interface/src/renderer/MetavoxelSystem.h +++ b/interface/src/renderer/MetavoxelSystem.h @@ -17,6 +17,9 @@ public: void init(); + void simulate(float deltaTime); + void render(); + private: MetavoxelData _data; diff --git a/libraries/metavoxels/src/AttributeRegistry.cpp b/libraries/metavoxels/src/AttributeRegistry.cpp index 7c2a98049e..96083908bd 100644 --- a/libraries/metavoxels/src/AttributeRegistry.cpp +++ b/libraries/metavoxels/src/AttributeRegistry.cpp @@ -10,8 +10,9 @@ AttributeRegistry AttributeRegistry::_instance; -AttributeRegistry::AttributeRegistry() { - registerAttribute(AttributePointer(new QRgbAttribute("diffuseColor"))); +AttributeRegistry::AttributeRegistry() : + _colorAttribute(registerAttribute(new QRgbAttribute("color"))), + _normalAttribute(registerAttribute(new QRgbAttribute("normal"))) { } AttributePointer AttributeRegistry::registerAttribute(AttributePointer attribute) { @@ -91,7 +92,6 @@ void* QRgbAttribute::createAveraged(void* values[]) const { totalBlue += qBlue(value); totalAlpha += qAlpha(value); } - const int SHIFT_FACTOR = 3; return encodeInline(qRgba(totalRed / AVERAGE_COUNT, totalGreen / AVERAGE_COUNT, totalBlue / AVERAGE_COUNT, totalAlpha / AVERAGE_COUNT)); } diff --git a/libraries/metavoxels/src/AttributeRegistry.h b/libraries/metavoxels/src/AttributeRegistry.h index f8eef1788d..a2e56ae3a5 100644 --- a/libraries/metavoxels/src/AttributeRegistry.h +++ b/libraries/metavoxels/src/AttributeRegistry.h @@ -29,6 +29,11 @@ public: AttributeRegistry(); + /// Registers an attribute with the system. The registry assumes ownership of the object. + /// \return either the pointer passed as an argument, if the attribute wasn't already registered, or the existing + /// attribute + AttributePointer registerAttribute(Attribute* attribute) { return registerAttribute(AttributePointer(attribute)); } + /// Registers an attribute with the system. /// \return either the pointer passed as an argument, if the attribute wasn't already registered, or the existing /// attribute @@ -37,11 +42,19 @@ public: /// Retrieves an attribute by name. AttributePointer getAttribute(const QString& name) const { return _attributes.value(name); } + /// Returns a reference to the standard QRgb "color" attribute. + const AttributePointer& getColorAttribute() const { return _colorAttribute; } + + /// Returns a reference to the standard QRgb "normal" attribute. + const AttributePointer& getNormalAttribute() const { return _normalAttribute; } + private: static AttributeRegistry _instance; QHash _attributes; + AttributePointer _colorAttribute; + AttributePointer _normalAttribute; }; /// Converts a value to a void pointer.