Skip to content

Commit

Permalink
Merge 3a4383e into 996c58d
Browse files Browse the repository at this point in the history
  • Loading branch information
iche033 authored Mar 4, 2022
2 parents 996c58d + 3a4383e commit a3d2bbe
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 7 deletions.
35 changes: 30 additions & 5 deletions ogre2/src/Ogre2GpuRays.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,11 @@ class ignition::rendering::Ogre2GpuRaysPrivate
using namespace ignition;
using namespace rendering;

/// \brief A map of ogre sub item pointer to their original low level material
/// \todo(anyone) Added here for ABI compatibity. Move to private class
/// in ign-rendering7
std::map<Ogre2LaserRetroMaterialSwitcher *,
std::map<Ogre::SubItem *, Ogre::MaterialPtr>> laserRetroMaterialMap;

//////////////////////////////////////////////////
Ogre2LaserRetroMaterialSwitcher::Ogre2LaserRetroMaterialSwitcher(
Expand Down Expand Up @@ -230,7 +235,6 @@ void Ogre2LaserRetroMaterialSwitcher::cameraPreRenderScene(
// swap item to use v1 shader material
// Note: keep an eye out for performance impact on switching materials
// on the fly. We are not doing this often so should be ok.
this->datablockMap.clear();
auto itor = this->scene->OgreSceneManager()->getMovableObjectIterator(
Ogre::ItemFactory::FACTORY_TYPE_NAME);
while (itor.hasMoreElements())
Expand Down Expand Up @@ -304,9 +308,18 @@ void Ogre2LaserRetroMaterialSwitcher::cameraPreRenderScene(
subItem->setCustomParameter(this->customParamIdx,
Ogre::Vector4(color, color, color, 1.0));

Ogre::HlmsDatablock *datablock = subItem->getDatablock();
this->datablockMap[subItem] = datablock;

// case when item is using low level materials
// e.g. shaders
if (!subItem->getMaterial().isNull())
{
laserRetroMaterialMap[this][subItem] = subItem->getMaterial();
}
// regular Pbs Hlms datablock
else
{
Ogre::HlmsDatablock *datablock = subItem->getDatablock();
this->datablockMap[subItem] = datablock;
}
subItem->setMaterial(this->laserRetroSourceMaterial);
}
itor.moveNext();
Expand All @@ -324,12 +337,24 @@ void Ogre2LaserRetroMaterialSwitcher::cameraPostRenderScene(
subItem->setDatablock(it.second);
}

auto laserRetroIt = laserRetroMaterialMap.find(this);
if (laserRetroIt != laserRetroMaterialMap.end())
{
for (auto it : laserRetroIt->second)
{
Ogre::SubItem *subItem = it.first;
subItem->setMaterial(it.second);
}
}

Ogre::Pass *pass =
this->laserRetroSourceMaterial->getBestTechnique()->getPass(0u);
pass->getVertexProgramParameters()->setNamedConstant(
"ignMinClipDistance", 0.0f );
}

this->datablockMap.clear();
laserRetroMaterialMap[this].clear();
}

//////////////////////////////////////////////////
Ogre2GpuRays::Ogre2GpuRays()
Expand Down
15 changes: 13 additions & 2 deletions ogre2/src/Ogre2MaterialSwitcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ using namespace rendering;


/// \brief A map of ogre sub item pointer to their original low level material
/// \todo(anyone) Added here for ABI compatibity This can be removed once
/// ign-rendering7 switches to Hlms customization for "switching" materials
/// \todo(anyone) Added here for ABI compatibity. Move to private class
/// in ign-rendering7
std::map<Ogre2MaterialSwitcher *,
std::map<Ogre::SubItem *, Ogre::MaterialPtr>> materialMap;

Expand Down Expand Up @@ -110,6 +110,17 @@ void Ogre2MaterialSwitcher::cameraPreRenderScene(
{
materialMap[this][subItem] = subItem->getMaterial();
subItem->setMaterial(this->plainMaterial);
auto technique = subItem->getMaterial()->getTechnique(0);

if (technique && !technique->isDepthWriteEnabled() &&
!technique->isDepthCheckEnabled())
{
subItem->setMaterial(this->plainOverlayMaterial);
}
else
{
subItem->setMaterial(this->plainMaterial);
}
}
// regular Pbs Hlms datablock
else
Expand Down
21 changes: 21 additions & 0 deletions test/integration/camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "test_config.h" // NOLINT(build/include)

#include "ignition/rendering/Camera.hh"
#include "ignition/rendering/GpuRays.hh"
#include "ignition/rendering/RenderEngine.hh"
#include "ignition/rendering/RenderingIface.hh"
#include "ignition/rendering/Scene.hh"
Expand Down Expand Up @@ -663,6 +664,25 @@ void CameraTest::ShaderSelection(const std::string &_renderEngine)
camera->SetHFOV(IGN_PI / 2);
root->AddChild(camera);

// Create a gpu ray
// laser retro material switching may also affect shader materials
const double hMinAngle = -IGN_PI/2.0;
const double hMaxAngle = IGN_PI/2.0;
const double minRange = 0.1;
const double maxRange = 10.0;
const int hRayCount = 320;
const int vRayCount = 1;
GpuRaysPtr gpuRays = scene->CreateGpuRays("gpu_rays");
gpuRays->SetWorldPosition(0, 0, 0);
gpuRays->SetNearClipPlane(minRange);
gpuRays->SetFarClipPlane(maxRange);
gpuRays->SetAngleMin(hMinAngle);
gpuRays->SetAngleMax(hMaxAngle);
gpuRays->SetRayCount(hRayCount);

gpuRays->SetVerticalRayCount(vRayCount);
root->AddChild(gpuRays);

if (_renderEngine == "ogre2")
{
// worldviewproj_matrix is a constant defined by ogre.
Expand All @@ -681,6 +701,7 @@ void CameraTest::ShaderSelection(const std::string &_renderEngine)
for (auto i = 0; i < 30; ++i)
{
camera->Update();
gpuRays->Update();
}

// capture a frame
Expand Down

0 comments on commit a3d2bbe

Please sign in to comment.