Skip to content
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

Apply particle scattering effect to depth cameras #251

Merged
merged 33 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ca342de
add support for 8 bit thermal camera
iche033 Feb 5, 2021
b7c0fe2
Merge branch 'ign-rendering4' into thermal_8bit
iche033 Feb 5, 2021
aab3c9e
doc
iche033 Feb 5, 2021
aa2fb9a
update test and changelog
iche033 Feb 5, 2021
43c80a9
style, feedback changes
iche033 Feb 8, 2021
8a5bf29
add more doc
iche033 Feb 9, 2021
a90cb18
fix particle size
iche033 Feb 10, 2021
3357ac5
disable particles in thermal camera view
iche033 Feb 10, 2021
d58deef
remove comments
iche033 Feb 10, 2021
4afde4e
update example
iche033 Feb 10, 2021
2c681f4
Merge branch 'ign-rendering4' into thermal_particles
adlarkin Feb 10, 2021
7b38ed1
update fix
iche033 Feb 12, 2021
d31a73d
feedback changes
iche033 Feb 12, 2021
4ff85d3
tweak particle params in test
iche033 Feb 12, 2021
0f61514
Merge branch 'thermal_particles' of github.com:ignitionrobotics/ign-r…
iche033 Feb 12, 2021
1b628ec
Merge branch 'ign-rendering4' into thermal_particles
iche033 Feb 12, 2021
35af1ab
fix build
iche033 Feb 12, 2021
aaa6cf8
Merge branch 'thermal_particles' of github.com:ignitionrobotics/ign-r…
iche033 Feb 12, 2021
ab8970e
wip: particle affector
iche033 Feb 13, 2021
bf1e80c
Merge branch 'particle_size' into thermal_particles
iche033 Feb 13, 2021
1359594
particle scatter effect working
iche033 Feb 14, 2021
1e49998
remove effector code
iche033 Feb 14, 2021
b84603c
reduce particle depth buffer size
iche033 Feb 14, 2021
dc37c79
add test
iche033 Feb 16, 2021
2c0633d
update comment
iche033 Feb 16, 2021
18fd616
Merge branch 'ign-rendering4' into thermal_particles
iche033 Feb 16, 2021
733bc91
remove unused function
iche033 Feb 17, 2021
c0d4ef0
Merge branch 'ign-rendering4' into thermal_particles
adlarkin Feb 17, 2021
b73e9d6
Merge branch 'thermal_particles' into depth_particles
adlarkin Feb 17, 2021
963bc43
feedback changes
iche033 Feb 17, 2021
f7b1838
remove unused var
iche033 Feb 17, 2021
7c76651
Merge branch 'ign-rendering4' into depth_particles
adlarkin Feb 17, 2021
3f71f83
Apply particle scattering effect to lidars (#252)
iche033 Feb 17, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions ogre2/include/ignition/rendering/ogre2/Ogre2Includes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
#include <OgreHardwarePixelBuffer.h>
#include <OgreShadowCameraSetupPSSM.h>
#include <OgreDepthBuffer.h>
#include <OgreParticleAffector.h>
#include <OgreParticleAffectorFactory.h>
#include <OgreParticleEmitter.h>
#include <OgreParticleSystem.h>

Expand Down
168 changes: 163 additions & 5 deletions ogre2/src/Ogre2DepthCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
#include "ignition/rendering/ogre2/Ogre2DepthCamera.hh"
#include "ignition/rendering/ogre2/Ogre2GaussianNoisePass.hh"
#include "ignition/rendering/ogre2/Ogre2Includes.hh"
#include "ignition/rendering/ogre2/Ogre2ParticleEmitter.hh"
#include "ignition/rendering/ogre2/Ogre2RenderEngine.hh"
#include "ignition/rendering/ogre2/Ogre2RenderTarget.hh"
#include "ignition/rendering/ogre2/Ogre2RenderTypes.hh"
#include "ignition/rendering/ogre2/Ogre2Scene.hh"
#include "ignition/rendering/ogre2/Ogre2Sensor.hh"


namespace ignition
{
namespace rendering
Expand Down Expand Up @@ -128,6 +128,13 @@ class ignition::rendering::Ogre2DepthCameraPrivate
public: ignition::common::EventT<void(const float *,
unsigned int, unsigned int, unsigned int,
const std::string &)> newDepthFrame;

/// \brief standard deviation of particle noise
public: double particleStddev = 0.01;

/// \brief Particle scatter ratio. This is used to determine the ratio of
/// particles that will detected by the depth camera
public: double particleScatterRatio = 0.1;
};

using namespace ignition;
Expand Down Expand Up @@ -421,6 +428,10 @@ void Ogre2DepthCamera::CreateDepthTexture()
this->Scene()->BackgroundColor().G(),
this->Scene()->BackgroundColor().B());
psParams->setNamedConstant("backgroundColor", bg);
psParams->setNamedConstant("particleStddev",
static_cast<float>(this->dataPtr->particleStddev));
psParams->setNamedConstant("particleScatterRatio",
static_cast<float>(this->dataPtr->particleScatterRatio));

std::string matDepthFinalName = "DepthCameraFinal";
Ogre::MaterialPtr matDepthFinal =
Expand Down Expand Up @@ -449,6 +460,22 @@ void Ogre2DepthCamera::CreateDepthTexture()
this->dataPtr->ogreCompositorWorkspaceDef = wsDefName;
if (!ogreCompMgr->hasWorkspaceDefinition(wsDefName))
{
// The depth camera compositor does a few passes in order to simulate
// particles effects in depth / point cloud image data
//
// render scene (color) with particles, c1
// render scene (depth) without particles, d1
// render scene (grayscale) with particles only, g2
// render scene (depth) with particles only, d2
//
// if g2 is non-zero // pixel with particle
// if d2 < d1 // particle is in view
// apply noise and scatterbility to d2
// set depth data to d2
// else
// set depth data to d1
// set color data to c1

// We need to programmatically create the compositor because we need to
// configure it to use the cloned depth material created earlier.
// The compositor node definition is equivalent to the following:
Expand All @@ -457,10 +484,12 @@ void Ogre2DepthCamera::CreateDepthTexture()
// {
// texture rt0 target_width target_height PF_FLOAT32_RGBA
// texture rt1 target_width target_height PF_FLOAT32_RGBA
// // colorTexture shares same depth buffer as depthTexture
// texture colorTexture target_width target_height PF_R8G8B8
// depth_texture depth_format PF_D32_FLOAT
// texture depthTexture target_width target_height PF_D32_FLOAT
// texture particleTexture target_width target_height PF_L8
// // particleDepthTexture shares same depth buffer as particleTexture
// texture particleDepthTexture target_width target_height PF_D32_FLOAT
// target colorTexture
// {
// pass clear
Expand All @@ -471,6 +500,37 @@ void Ogre2DepthCamera::CreateDepthTexture()
// {
// }
// }
// target depthTexture
// {
// pass clear
// {
// colour_value 0.0 0.0 0.0 1.0
// }
// pass render_scene
// {
// visibility_mask 0x11011111
// }
// }
// target particleTexture
// {
// pass clear
// {
// }
// pass render_scene
// {
// visibility_mask 0x00100000
// }
// }
// target particleDepthTexture
// {
// pass clear
// {
// }
// pass render_scene
// {
// visibility_mask 0x00100000
// }
// }
// target rt0
// {
// pass clear
Expand Down Expand Up @@ -568,7 +628,45 @@ void Ogre2DepthCamera::CreateDepthTexture()
colorTexDef->preferDepthTexture = true;
colorTexDef->fsaaExplicitResolve = false;

baseNodeDef->setNumTargetPass(2);
Ogre::TextureDefinitionBase::TextureDefinition *particleTexDef =
baseNodeDef->addTextureDefinition("particleTexture");
particleTexDef->textureType = Ogre::TEX_TYPE_2D;
particleTexDef->width = 0;
particleTexDef->height = 0;
particleTexDef->depth = 1;
particleTexDef->numMipmaps = 0;
particleTexDef->widthFactor = 0.5;
particleTexDef->heightFactor = 0.5;
particleTexDef->formatList = {Ogre::PF_L8};
particleTexDef->fsaa = 0;
particleTexDef->uav = false;
particleTexDef->automipmaps = false;
particleTexDef->hwGammaWrite = Ogre::TextureDefinitionBase::BoolFalse;
particleTexDef->depthBufferId = Ogre::DepthBuffer::POOL_DEFAULT;
particleTexDef->depthBufferFormat = Ogre::PF_UNKNOWN;
particleTexDef->preferDepthTexture = false;
particleTexDef->fsaaExplicitResolve = false;

Ogre::TextureDefinitionBase::TextureDefinition *particleDepthTexDef =
baseNodeDef->addTextureDefinition("particleDepthTexture");
particleDepthTexDef->textureType = Ogre::TEX_TYPE_2D;
particleDepthTexDef->width = 0;
particleDepthTexDef->height = 0;
particleDepthTexDef->depth = 1;
particleDepthTexDef->numMipmaps = 0;
particleDepthTexDef->widthFactor = 0.5;
particleDepthTexDef->heightFactor = 0.5;
particleDepthTexDef->formatList = {Ogre::PF_D32_FLOAT};
particleDepthTexDef->fsaa = 0;
particleDepthTexDef->uav = false;
particleDepthTexDef->automipmaps = false;
particleDepthTexDef->hwGammaWrite = Ogre::TextureDefinitionBase::BoolFalse;
particleDepthTexDef->depthBufferId = Ogre::DepthBuffer::POOL_NON_SHAREABLE;
particleDepthTexDef->depthBufferFormat = Ogre::PF_UNKNOWN;
particleDepthTexDef->fsaaExplicitResolve = false;
adlarkin marked this conversation as resolved.
Show resolved Hide resolved

baseNodeDef->setNumTargetPass(5);
adlarkin marked this conversation as resolved.
Show resolved Hide resolved

Ogre::CompositorTargetDef *colorTargetDef =
baseNodeDef->addTargetPass("colorTexture");
colorTargetDef->setNumPasses(2);
Expand All @@ -583,15 +681,73 @@ void Ogre2DepthCamera::CreateDepthTexture()
Ogre::CompositorPassSceneDef *passScene =
static_cast<Ogre::CompositorPassSceneDef *>(
colorTargetDef->addPass(Ogre::PASS_SCENE));
passScene->mVisibilityMask = IGN_VISIBILITY_ALL
& ~(IGN_VISIBILITY_GUI | IGN_VISIBILITY_SELECTABLE);
passScene->mVisibilityMask = IGN_VISIBILITY_ALL;

// todo(anyone) Fix shadows. The shadow compositor node gets rebuilt
// when the number of shadow-casting light changes so we end up with
// invalid shadow node here. See Ogre2Scene::PreRender function on how
// it destroys and triggers a compositor rebuild in OgreCamera when
// the number of shadow-casting light changes
// passScene->mShadowNode = "PbsMaterialsShadowNode";
}

Ogre::CompositorTargetDef *depthTargetDef =
baseNodeDef->addTargetPass("depthTexture");
depthTargetDef->setNumPasses(2);
{
// clear pass
Ogre::CompositorPassClearDef *passClear =
static_cast<Ogre::CompositorPassClearDef *>(
depthTargetDef->addPass(Ogre::PASS_CLEAR));
passClear->mColourValue = Ogre::ColourValue(this->FarClipPlane(),
this->FarClipPlane(), this->FarClipPlane());

// scene pass
Ogre::CompositorPassSceneDef *passScene =
static_cast<Ogre::CompositorPassSceneDef *>(
depthTargetDef->addPass(Ogre::PASS_SCENE));
// depth texute does not contain particles
passScene->mVisibilityMask = IGN_VISIBILITY_ALL
& ~Ogre2ParticleEmitter::kParticleVisibilityFlags;
}

Ogre::CompositorTargetDef *particleTargetDef =
baseNodeDef->addTargetPass("particleTexture");
particleTargetDef->setNumPasses(2);
{
// clear pass
Ogre::CompositorPassClearDef *passClear =
static_cast<Ogre::CompositorPassClearDef *>(
particleTargetDef->addPass(Ogre::PASS_CLEAR));
passClear->mColourValue = Ogre::ColourValue::Black;

// scene pass
Ogre::CompositorPassSceneDef *passScene =
static_cast<Ogre::CompositorPassSceneDef *>(
particleTargetDef->addPass(Ogre::PASS_SCENE));
passScene->mVisibilityMask =
Ogre2ParticleEmitter::kParticleVisibilityFlags;
}

Ogre::CompositorTargetDef *particleDepthTargetDef =
baseNodeDef->addTargetPass("particleDepthTexture");
particleDepthTargetDef->setNumPasses(2);
{
// clear pass
Ogre::CompositorPassClearDef *passClear =
static_cast<Ogre::CompositorPassClearDef *>(
particleDepthTargetDef->addPass(Ogre::PASS_CLEAR));
passClear->mColourValue = Ogre::ColourValue(this->FarClipPlane(),
this->FarClipPlane(), this->FarClipPlane());

// scene pass
Ogre::CompositorPassSceneDef *passScene =
static_cast<Ogre::CompositorPassSceneDef *>(
particleDepthTargetDef->addPass(Ogre::PASS_SCENE));
passScene->mVisibilityMask =
Ogre2ParticleEmitter::kParticleVisibilityFlags;
}

// rt0 target - converts depth to xyz
Ogre::CompositorTargetDef *inTargetDef =
baseNodeDef->addTargetPass("rt0");
Expand All @@ -611,6 +767,8 @@ void Ogre2DepthCamera::CreateDepthTexture()
passQuad->mMaterialName = this->dataPtr->depthMaterial->getName();
passQuad->addQuadTextureSource(0, "depthTexture", 0);
passQuad->addQuadTextureSource(1, "colorTexture", 0);
passQuad->addQuadTextureSource(2, "particleTexture", 0);
passQuad->addQuadTextureSource(3, "particleDepthTexture", 0);
passQuad->mFrustumCorners =
Ogre::CompositorPassQuadDef::VIEW_SPACE_CORNERS;
}
Expand Down
86 changes: 84 additions & 2 deletions ogre2/src/Ogre2GpuRays.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "ignition/rendering/RenderTypes.hh"
#include "ignition/rendering/ogre2/Ogre2Conversions.hh"
#include "ignition/rendering/ogre2/Ogre2Includes.hh"
#include "ignition/rendering/ogre2/Ogre2ParticleEmitter.hh"
#include "ignition/rendering/ogre2/Ogre2RenderTarget.hh"
#include "ignition/rendering/ogre2/Ogre2RenderTypes.hh"
#include "ignition/rendering/ogre2/Ogre2Scene.hh"
Expand Down Expand Up @@ -162,6 +163,13 @@ class ignition::rendering::Ogre2GpuRaysPrivate
/// \brief Pointer to material switcher
public: std::unique_ptr<Ogre2LaserRetroMaterialSwitcher>
laserRetroMaterialSwitcher[6];

/// \brief standard deviation of particle noise
public: double particleStddev = 0.01;

/// \brief Particle scatter ratio. This is used to determine the ratio of
/// particles that will detected by the depth camera
public: double particleScatterRatio = 0.1;
};

using namespace ignition;
Expand Down Expand Up @@ -607,6 +615,10 @@ void Ogre2GpuRays::Setup1stPass()
static_cast<float>(this->dataMaxVal));
psParams->setNamedConstant("min",
static_cast<float>(this->dataMinVal));
psParams->setNamedConstant("particleStddev",
static_cast<float>(this->dataPtr->particleStddev));
psParams->setNamedConstant("particleScatterRatio",
static_cast<float>(this->dataPtr->particleScatterRatio));

// Create 1st pass compositor
auto engine = Ogre2RenderEngine::Instance();
Expand All @@ -622,6 +634,8 @@ void Ogre2GpuRays::Setup1stPass()
// in 0 rt_input
// texture depthTexture target_width target_height PF_D32_FLOAT
// texture colorTexture target_width target_height PF_R8G8B8
// texture particleTexture target_width target_height PF_L8
// texture particleDepthTexture target_width target_height PF_D32_FLOAT
// target colorTexture
// {
// pass clear
Expand All @@ -630,6 +644,18 @@ void Ogre2GpuRays::Setup1stPass()
// }
// pass render_scene
// {
// visibility_mask 0x11011111
// }
// }
// target particleTexture
// {
// pass clear
// {
// colour_value 0.0 0.0 0.0 1.0
// }
// pass render_scene
// {
// visibility_mask 0.00100000
// }
// }
// target rt_input
Expand Down Expand Up @@ -697,7 +723,42 @@ void Ogre2GpuRays::Setup1stPass()
colorTexDef->preferDepthTexture = true;
colorTexDef->fsaaExplicitResolve = false;

nodeDef->setNumTargetPass(2);
Ogre::TextureDefinitionBase::TextureDefinition *particleDepthTexDef =
nodeDef->addTextureDefinition("particleDepthTexture");
particleDepthTexDef->textureType = Ogre::TEX_TYPE_2D;
particleDepthTexDef->width = 0;
particleDepthTexDef->height = 0;
particleDepthTexDef->depth = 1;
particleDepthTexDef->numMipmaps = 0;
particleDepthTexDef->widthFactor = 0.5;
particleDepthTexDef->heightFactor = 0.5;
particleDepthTexDef->formatList = {Ogre::PF_D32_FLOAT};
particleDepthTexDef->fsaa = 0;
particleDepthTexDef->uav = false;
particleDepthTexDef->automipmaps = false;
particleDepthTexDef->hwGammaWrite = Ogre::TextureDefinitionBase::BoolFalse;
particleDepthTexDef->depthBufferId = Ogre::DepthBuffer::POOL_DEFAULT;

Ogre::TextureDefinitionBase::TextureDefinition *particleTexDef =
nodeDef->addTextureDefinition("particleTexture");
particleTexDef->textureType = Ogre::TEX_TYPE_2D;
particleTexDef->width = 0;
particleTexDef->height = 0;
particleTexDef->depth = 1;
particleTexDef->numMipmaps = 0;
particleTexDef->widthFactor = 0.5;
particleTexDef->heightFactor = 0.5;
particleTexDef->formatList = {Ogre::PF_R8G8B8};
particleTexDef->fsaa = 0;
particleTexDef->uav = false;
particleTexDef->automipmaps = false;
particleTexDef->hwGammaWrite = Ogre::TextureDefinitionBase::BoolFalse;
particleTexDef->depthBufferId = Ogre::DepthBuffer::POOL_DEFAULT;
particleTexDef->depthBufferFormat = Ogre::PF_D32_FLOAT;
particleTexDef->preferDepthTexture = true;
particleTexDef->fsaaExplicitResolve = false;

nodeDef->setNumTargetPass(3);

Ogre::CompositorTargetDef *colorTargetDef =
nodeDef->addTargetPass("colorTexture");
Expand All @@ -713,7 +774,26 @@ void Ogre2GpuRays::Setup1stPass()
static_cast<Ogre::CompositorPassSceneDef *>(
colorTargetDef->addPass(Ogre::PASS_SCENE));
// set camera custom visibility mask when rendering laser retro
passScene->mVisibilityMask = 0x01000000;
passScene->mVisibilityMask = 0x01000000 &
~Ogre2ParticleEmitter::kParticleVisibilityFlags;
}

Ogre::CompositorTargetDef *particleTargetDef =
nodeDef->addTargetPass("particleTexture");
particleTargetDef->setNumPasses(2);
{
// clear pass
Ogre::CompositorPassClearDef *passClear =
static_cast<Ogre::CompositorPassClearDef *>(
particleTargetDef->addPass(Ogre::PASS_CLEAR));
passClear->mColourValue = Ogre::ColourValue::Black;
// scene pass
Ogre::CompositorPassSceneDef *passScene =
static_cast<Ogre::CompositorPassSceneDef *>(
particleTargetDef->addPass(Ogre::PASS_SCENE));
// set camera custom visibility mask when rendering laser retro
passScene->mVisibilityMask =
Ogre2ParticleEmitter::kParticleVisibilityFlags;
}

// rt_input target - converts depth to range
Expand All @@ -733,6 +813,8 @@ void Ogre2GpuRays::Setup1stPass()
passQuad->mMaterialName = this->dataPtr->matFirstPass->getName();
passQuad->addQuadTextureSource(0, "depthTexture", 0);
passQuad->addQuadTextureSource(1, "colorTexture", 0);
passQuad->addQuadTextureSource(2, "particleDepthTexture", 0);
passQuad->addQuadTextureSource(3, "particleTexture", 0);
passQuad->mFrustumCorners =
Ogre::CompositorPassQuadDef::VIEW_SPACE_CORNERS;
}
Expand Down
Loading