-
Notifications
You must be signed in to change notification settings - Fork 276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enabling Global Illumination (GI VCT) for sensors in SDF #2550
Merged
Merged
Changes from 3 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
4afb41b
Hack to enable GI for sensors
athenaz2 e36edfd
Parse and set SDF parameters for GI VCT
athenaz2 bd93e33
Add doxygen comments and cleaned up code a bit
athenaz2 f401172
Update src/systems/sensors/Sensors.cc
athenaz2 f82c68e
Add comments documenting helper funcs as well as clarifying comments;…
athenaz2 5a1d4ee
Add GI demo SDF as example
athenaz2 bb70589
Add test scene SDFs and test file
athenaz2 f725194
Minor codecheck modification
athenaz2 843c0c8
Minor var rename
athenaz2 407ab1c
Merge branch 'gz-sim8' into athenaz/gi_for_sensors
azeey 0ab686a
Add surrounding box in SDF, set test expectations to be more stark
athenaz2 8738398
Minor codecheck modification for SDF, disable GIEnabled test for macO…
athenaz2 56b841b
Comment out GINotEnabled test to check segfault issue
athenaz2 0293b5f
Disable test if MESA_GL_VERSION_OVERRIDE env var is set
athenaz2 db226c2
Add GI tutorial
athenaz2 e310454
At end of RenderThread, reset giVct shared ptr
athenaz2 420231d
Merge branch 'gz-sim8' into athenaz/gi_for_sensors
athenaz2 3f64dd0
Trim trailing whitespace
athenaz2 6a7a6c2
Merge branch 'athenaz/gi_for_sensors' of https://github.com/athenaz2/…
athenaz2 10f1b37
Merge branch 'gz-sim8' into athenaz/gi_for_sensors
athenaz2 7f49293
Apply suggestions from code review
athenaz2 f04599f
Apply suggestions from code review
athenaz2 95530a6
Remove commented out sections in SDFs, remove GUI plugins from SDF be…
athenaz2 f03476b
remove whitespace
iche033 966f48c
hide scene manager and view control gui plugins
iche033 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,11 +64,71 @@ | |
|
||
#include "gz/sim/rendering/Events.hh" | ||
#include "gz/sim/rendering/RenderUtil.hh" | ||
#include "gz/rendering/GlobalIlluminationVct.hh" | ||
|
||
using namespace gz; | ||
using namespace sim; | ||
using namespace systems; | ||
|
||
/// \brief GI parameters holding default data | ||
struct GiDefaultData | ||
{ | ||
/// \brief See rendering::GlobalIlluminationVct::SetResolution | ||
math::Vector3d resolution{16, 16, 16}; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetOctantCount | ||
math::Vector3d octantCount{1, 1, 1}; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetBounceCount | ||
uint32_t bounceCount = 6; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetHighQuality | ||
bool highQuality = true; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetAnisotropic | ||
bool anisotropic = true; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetThinWallCounter | ||
float thinWallCounter = 1.0f; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetConserveMemory | ||
bool conserveMemory = false; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::DebugVisualizationMode | ||
uint32_t debugVisMode = rendering::GlobalIlluminationVct::DVM_None; | ||
}; | ||
|
||
/// \brief GI VCT flag and parameters | ||
struct GiVctParameters | ||
{ | ||
/// \brief VCT enabled flag | ||
bool enabled = false; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetResolution | ||
uint32_t resolution[3]; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetOctantCount | ||
uint32_t octantCount[3]; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetBounceCount | ||
uint32_t bounceCount; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetHighQuality | ||
bool highQuality; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetAnisotropic | ||
bool anisotropic; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetThinWallCounter | ||
float thinWallCounter; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::SetConserveMemory | ||
bool conserveMemory; | ||
|
||
/// \brief See rendering::GlobalIlluminationVct::DebugVisualizationMode | ||
uint32_t debugVisMode; | ||
}; | ||
|
||
// Private data class. | ||
class gz::sim::systems::SensorsPrivate | ||
{ | ||
|
@@ -89,6 +149,18 @@ class gz::sim::systems::SensorsPrivate | |
/// generate sensor data | ||
public: rendering::ScenePtr scene; | ||
|
||
/// \brief Pointer to GlobalIlluminationVct | ||
public: rendering::GlobalIlluminationVctPtr giVct; | ||
|
||
/// \brief GI VCT parameters passed to giVct | ||
public: GiVctParameters giVctParameters; | ||
|
||
/// \brief Default GI data | ||
public: GiDefaultData giDefaultData; | ||
|
||
/// \brief GI built flag | ||
public: bool giBuilt = false; | ||
|
||
/// \brief Temperature used by thermal camera. Defaults to temperature at | ||
/// sea level | ||
public: double ambientTemperature = 288.15; | ||
|
@@ -288,6 +360,28 @@ void SensorsPrivate::WaitForInit() | |
#endif | ||
this->scene = this->renderUtil.Scene(); | ||
this->scene->SetCameraPassCountPerGpuFlush(6u); | ||
|
||
if (this->giVctParameters.enabled) | ||
{ | ||
this->giVct = this->scene->CreateGlobalIlluminationVct(); | ||
this->giVct->SetParticipatingVisuals( | ||
rendering::GlobalIlluminationBase::DYNAMIC_VISUALS | | ||
rendering::GlobalIlluminationBase::STATIC_VISUALS); | ||
|
||
this->giVct->SetResolution(this->giVctParameters.resolution); | ||
this->giVct->SetOctantCount(this->giVctParameters.octantCount); | ||
this->giVct->SetBounceCount(this->giVctParameters.bounceCount); | ||
this->giVct->SetAnisotropic(this->giVctParameters.anisotropic); | ||
this->giVct->SetHighQuality(this->giVctParameters.highQuality); | ||
this->giVct->SetConserveMemory(this->giVctParameters.conserveMemory); | ||
this->giVct->SetThinWallCounter(this->giVctParameters.thinWallCounter); | ||
|
||
this->giVct->SetDebugVisualization( | ||
rendering::GlobalIlluminationVct::DVM_None); | ||
|
||
this->scene->SetActiveGlobalIllumination(this->giVct); | ||
} | ||
|
||
this->initialized = true; | ||
} | ||
|
||
|
@@ -359,6 +453,19 @@ void SensorsPrivate::RunOnce() | |
// We only need to do this once per frame It is important to call | ||
// sensors::RenderingSensor::SetManualSceneUpdate and set it to true | ||
// so we don't waste cycles doing one scene graph update per sensor | ||
|
||
if (!this->giBuilt) | ||
{ | ||
if (this->giVctParameters.enabled) | ||
{ | ||
this->giVct->Build(); | ||
this->giVct->SetDebugVisualization( | ||
static_cast<rendering::GlobalIlluminationVct::DebugVisualizationMode> | ||
(this->giVctParameters.debugVisMode)); | ||
this->giBuilt = true; | ||
} | ||
} | ||
|
||
this->scene->PreRender(); | ||
} | ||
|
||
|
@@ -521,6 +628,52 @@ Sensors::~Sensors() | |
this->dataPtr->Stop(); | ||
} | ||
|
||
//TODO: why does math::Vector3d work but not math::Vector3i? | ||
static void ConvertDoubleToUInt32x3(sdf::ElementConstPtr _parentElem, | ||
const char* _childName, uint32_t _valueToSet[3], math::Vector3d _defaultValue) | ||
{ | ||
math::Vector3d parsedValues = (_parentElem == nullptr) ? | ||
_defaultValue : _parentElem->Get<math::Vector3d>(_childName, _defaultValue).first; | ||
|
||
_valueToSet[0] = static_cast<uint32_t>(parsedValues[0]); | ||
_valueToSet[1] = static_cast<uint32_t>(parsedValues[1]); | ||
_valueToSet[2] = static_cast<uint32_t>(parsedValues[2]); | ||
} | ||
|
||
static void ConvertDoubleToUInt32x3(uint32_t _valueToSet[3], math::Vector3d _defaultValue) | ||
{ | ||
ConvertDoubleToUInt32x3(nullptr, "", _valueToSet, _defaultValue); | ||
} | ||
athenaz2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
static void SetDebugVisMode(const std::string &_text, | ||
uint32_t &_modeToSet, uint32_t _defaultMode) | ||
{ | ||
if (_text == "albedo") | ||
{ | ||
_modeToSet = rendering::GlobalIlluminationVct::DVM_Albedo; | ||
} | ||
else if (_text == "normal") | ||
{ | ||
_modeToSet = rendering::GlobalIlluminationVct::DVM_Normal; | ||
} | ||
else if (_text == "emissive") | ||
{ | ||
_modeToSet = rendering::GlobalIlluminationVct::DVM_Emissive; | ||
} | ||
else if (_text == "lighting") | ||
{ | ||
_modeToSet = rendering::GlobalIlluminationVct::DVM_Lighting; | ||
} | ||
else if (_text == "none") | ||
{ | ||
_modeToSet = rendering::GlobalIlluminationVct::DVM_None; | ||
} | ||
else | ||
{ | ||
_modeToSet = _defaultMode; | ||
} | ||
} | ||
|
||
////////////////////////////////////////////////// | ||
void Sensors::Configure(const Entity &/*_id*/, | ||
const std::shared_ptr<const sdf::Element> &_sdf, | ||
|
@@ -549,6 +702,54 @@ void Sensors::Configure(const Entity &/*_id*/, | |
if (_sdf->HasElement("ambient_light")) | ||
this->dataPtr->ambientLight = _sdf->Get<math::Color>("ambient_light"); | ||
|
||
// Get the global illumination technique and its parameters, if specified | ||
if (_sdf->HasElement("global_illumination")) | ||
{ | ||
if (engineName != "ogre2") | ||
{ | ||
gzerr << "Global illumination is only supported by the ogre2 render engine" << std::endl; | ||
} | ||
else | ||
{ | ||
auto giElem = _sdf->FindElement("global_illumination"); | ||
std::string giType = giElem->GetAttribute("type")->GetAsString(); | ||
if (giType == "vct") | ||
{ | ||
this->dataPtr->giVctParameters.enabled = giElem->Get<bool>("enabled", this->dataPtr->giVctParameters.enabled).first; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrap lines to 80char There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Checked style with codecheck in f82c68e |
||
|
||
if (giElem->HasElement("resolution")) | ||
athenaz2 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
ConvertDoubleToUInt32x3(giElem, "resolution", this->dataPtr->giVctParameters.resolution, this->dataPtr->giDefaultData.resolution); | ||
else | ||
ConvertDoubleToUInt32x3(this->dataPtr->giVctParameters.resolution, this->dataPtr->giDefaultData.resolution); | ||
|
||
if (giElem->HasElement("octant_count")) | ||
ConvertDoubleToUInt32x3(giElem, "octant_count", this->dataPtr->giVctParameters.octantCount, this->dataPtr->giDefaultData.octantCount); | ||
else | ||
ConvertDoubleToUInt32x3(this->dataPtr->giVctParameters.octantCount, this->dataPtr->giDefaultData.octantCount); | ||
|
||
this->dataPtr->giVctParameters.bounceCount = giElem->Get<uint32_t>("bounce_count", this->dataPtr->giVctParameters.bounceCount).first; | ||
this->dataPtr->giVctParameters.highQuality = giElem->Get<bool>("high_quality", this->dataPtr->giVctParameters.highQuality).first; | ||
this->dataPtr->giVctParameters.anisotropic = giElem->Get<bool>("anisotropic", this->dataPtr->giVctParameters.anisotropic).first; | ||
this->dataPtr->giVctParameters.thinWallCounter = giElem->Get<float>("thin_wall_counter", this->dataPtr->giVctParameters.thinWallCounter).first; | ||
this->dataPtr->giVctParameters.conserveMemory = giElem->Get<bool>("conserve_memory", this->dataPtr->giVctParameters.conserveMemory).first; | ||
|
||
if (giElem->HasElement("debug_vis_mode")) | ||
{ | ||
const std::string text = giElem->Get<std::string>("debug_vis_mode", "none").first; | ||
SetDebugVisMode(text, this->dataPtr->giVctParameters.debugVisMode, this->dataPtr->giDefaultData.debugVisMode); | ||
} | ||
} | ||
else if (giType == "civct") | ||
{ | ||
//todo: add CIVCT here. should also check if apiBackend is vulkan | ||
gzerr << "GI CI VCT is not supported" << std::endl; | ||
} else | ||
{ | ||
gzerr << "GI method type [" << giType << "] is not supported." << std::endl; | ||
} | ||
} | ||
} | ||
|
||
this->dataPtr->renderUtil.SetEngineName(engineName); | ||
#ifdef __APPLE__ | ||
if (apiBackend.empty()) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like
math::Vector3i
is not one of the supported types: https://github.com/gazebosim/sdformat/blob/ba1bf8fedc0b6063d4312ad312e515e28f71cfb9/include/sdf/Param.hh#L529-L537