Skip to content

Commit

Permalink
Don't crash if directly set low level materials are used in sensors (g…
Browse files Browse the repository at this point in the history
…azebosim#593)

* Don't crash if directly set low level materials are used in sensors

Signed-off-by: Matias N. Goldberg <[email protected]>

* PointCloudPoint needs a _solid version

Signed-off-by: Matias N. Goldberg <[email protected]>

Co-authored-by: Ian Chen <[email protected]>
  • Loading branch information
darksylinc and iche033 authored Mar 22, 2022
1 parent f3c4003 commit 8bb21b4
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 32 deletions.
17 changes: 15 additions & 2 deletions ogre2/src/Ogre2GpuRays.cc
Original file line number Diff line number Diff line change
Expand Up @@ -315,12 +315,25 @@ void Ogre2LaserRetroMaterialSwitcher::passPreExecute(
// to keep vertex deformation consistent; so we use
// a cloned material with a different pixel shader
// https://github.com/ignitionrobotics/ign-rendering/issues/544
//
// material may be a nullptr if we called setMaterial directly
// (i.e. it's not using Ogre2Material interface).
// In those cases we fallback to PBS in the current IORM mode.
auto material = Ogre::MaterialManager::getSingleton().getByName(
subItem->getMaterial()->getName() + "_solid",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (material->getNumSupportedTechniques() > 0u)
if (material)
{
subItem->setMaterial(material);
if (material->getLoadingState() == Ogre::Resource::LOADSTATE_UNLOADED)
{
// Manually defined materials like PointCloudPoint_solid need this
material->load();
}

if (material->getNumSupportedTechniques() > 0u)
{
subItem->setMaterial(material);
}
}
else
{
Expand Down
17 changes: 15 additions & 2 deletions ogre2/src/Ogre2MaterialSwitcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,25 @@ void Ogre2MaterialSwitcher::cameraPreRenderScene(
// to keep vertex deformation consistent; so we use
// a cloned material with a different pixel shader
// https://github.com/ignitionrobotics/ign-rendering/issues/544
//
// material may be a nullptr if we called setMaterial directly
// (i.e. it's not using Ogre2Material interface).
// In those cases we fallback to PBS in the current IORM mode.
auto material = Ogre::MaterialManager::getSingleton().getByName(
subItem->getMaterial()->getName() + "_solid",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (material->getNumSupportedTechniques() > 0u)
if (material)
{
subItem->setMaterial(material);
if (material->getLoadingState() == Ogre::Resource::LOADSTATE_UNLOADED)
{
// Manually defined materials like PointCloudPoint_solid need this
material->load();
}

if (material->getNumSupportedTechniques() > 0u)
{
subItem->setMaterial(material);
}
}
else
{
Expand Down
18 changes: 16 additions & 2 deletions ogre2/src/Ogre2SegmentationMaterialSwitcher.cc
Original file line number Diff line number Diff line change
Expand Up @@ -307,12 +307,26 @@ void Ogre2SegmentationMaterialSwitcher::cameraPreRenderScene(
// to keep vertex deformation consistent; so we use
// a cloned material with a different pixel shader
// https://github.com/ignitionrobotics/ign-rendering/issues/544
//
// material may be a nullptr if we called setMaterial directly
// (i.e. it's not using Ogre2Material interface).
// In those cases we fallback to PBS in the current IORM mode.
auto material = Ogre::MaterialManager::getSingleton().getByName(
subItem->getMaterial()->getName() + "_solid",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (material->getNumSupportedTechniques() > 0u)
if (material)
{
subItem->setMaterial(material);
if (material->getLoadingState() ==
Ogre::Resource::LOADSTATE_UNLOADED)
{
// Manually defined materials like PointCloudPoint_solid need this
material->load();
}

if (material->getNumSupportedTechniques() > 0u)
{
subItem->setMaterial(material);
}
}
else
{
Expand Down
38 changes: 34 additions & 4 deletions ogre2/src/Ogre2ThermalCamera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,27 @@ void Ogre2ThermalCameraMaterialSwitcher::cameraPreRenderScene(
// to keep vertex deformation consistent; so we use
// a cloned material with a different pixel shader
// https://github.com/ignitionrobotics/ign-rendering/issues/544
//
// material may be a nullptr if we called setMaterial directly
// (i.e. it's not using Ogre2Material interface).
// In those cases we fallback to PBS in the current IORM mode.
auto material = Ogre::MaterialManager::getSingleton().getByName(
subItem->getMaterial()->getName() + "_solid",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (material->getNumSupportedTechniques() > 0u)
if (material)
{
subItem->setMaterial(material);
if (material->getLoadingState() ==
Ogre::Resource::LOADSTATE_UNLOADED)
{
// Manually defined materials like PointCloudPoint_solid
// need this
material->load();
}

if (material->getNumSupportedTechniques() > 0u)
{
subItem->setMaterial(material);
}
}
else
{
Expand Down Expand Up @@ -494,12 +509,27 @@ void Ogre2ThermalCameraMaterialSwitcher::cameraPreRenderScene(
// to keep vertex deformation consistent; so we use
// a cloned material with a different pixel shader
// https://github.com/ignitionrobotics/ign-rendering/issues/544
//
// material may be a nullptr if we called setMaterial directly
// (i.e. it's not using Ogre2Material interface).
// In those cases we fallback to PBS in the current IORM mode.
auto material = Ogre::MaterialManager::getSingleton().getByName(
subItem->getMaterial()->getName() + "_solid",
Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
if (material->getNumSupportedTechniques() > 0u)
if (material)
{
subItem->setMaterial(material);
if (material->getLoadingState() ==
Ogre::Resource::LOADSTATE_UNLOADED)
{
// Manually defined materials like PointCloudPoint_solid
// need this
material->load();
}

if (material->getNumSupportedTechniques() > 0u)
{
subItem->setMaterial(material);
}
}
else
{
Expand Down
1 change: 1 addition & 0 deletions ogre2/src/media/materials/programs/GLSL/point_vs.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ out vec3 ptColor;
out gl_PerVertex
{
vec4 gl_Position;
float gl_PointSize;
};

void main()
Expand Down
22 changes: 0 additions & 22 deletions ogre2/src/media/materials/scripts/picker.material
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,6 @@ vertex_program plaincolor_vs_GLSL glsl
}
}

fragment_program plaincolor_fs_GLSL glsl
{
source plain_color_fs.glsl

default_params
{
param_named inColor float4 1 1 1 1
}
}

// Metal shaders
vertex_program plaincolor_vs_Metal metal
{
Expand All @@ -36,25 +26,13 @@ vertex_program plaincolor_vs_Metal metal
}
}

fragment_program plaincolor_fs_Metal metal
{
source plain_color_fs.metal
shader_reflection_pair_hint plaincolor_vs_Metal
}

// Unified shaders
vertex_program plaincolor_vs unified
{
delegate plaincolor_vs_GLSL
delegate plaincolor_vs_Metal
}

fragment_program plaincolor_fs unified
{
delegate plaincolor_fs_GLSL
delegate plaincolor_fs_Metal
}

material ign-rendering/plain_color
{
// Material has one technique
Expand Down
24 changes: 24 additions & 0 deletions ogre2/src/media/materials/scripts/picker.program
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// GLSL shaders
fragment_program plaincolor_fs_GLSL glsl
{
source plain_color_fs.glsl

default_params
{
param_named inColor float4 1 1 1 1
}
}

// Metal shaders
fragment_program plaincolor_fs_Metal metal
{
source plain_color_fs.metal
shader_reflection_pair_hint plaincolor_vs_Metal
}

// Unified shaders
fragment_program plaincolor_fs unified
{
delegate plaincolor_fs_GLSL
delegate plaincolor_fs_Metal
}
18 changes: 18 additions & 0 deletions ogre2/src/media/materials/scripts/point_cloud_point.material
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,21 @@ material PointCloudPoint
}
}
}

// For sensors
material PointCloudPoint_solid
{
technique
{
pass
{
point_size_attenuation on
point_sprites on
vertex_program_ref PointCloudVS {}
fragment_program_ref plaincolor_fs
{
param_named_auto inColor custom 1
}
}
}
}

0 comments on commit 8bb21b4

Please sign in to comment.