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

Flip heightmap's Y position on Ogre 2 and add sanity checks for NaN #585

Merged
merged 5 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
1. Increase particle emitter quota
* [Pull request #562](https://github.com/ignitionrobotics/ign-rendering/pull/562)

1.Make sure shader param exists before setting its value
1. Make sure shader param exists before setting its value
* [Pull request #558](https://github.com/ignitionrobotics/ign-rendering/pull/558)

1. Backport wave changes
Expand Down
18 changes: 12 additions & 6 deletions Migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@ Deprecated code produces compile-time warnings. These warning serve as
notification to users that their code should be upgraded. The next major
release will remove the deprecated code.

## Ignition Rendering 6.2.1 to 6.X

### Modifications

1. Ogre 2 heightmaps: the Y position sign was flipped

1. `Scene::SetTime` is often unset. Ignition's `Ogre2` now defaults to 60hz otherwise rendering won't advance forward.
+ Mostly affects Particles.
+ Also may affect gaussian postprocessing and other filters dependant on time.
+ Previous behavior was using real time instead of simulation time, which is wrong.
+ See https://github.com/ignitionrobotics/ign-rendering/issues/556 for details.

## Ignition Rendering 5.x to 6.x

### Modifications
Expand Down Expand Up @@ -40,12 +52,6 @@ release will remove the deprecated code.
1. **depth_camera_fs.glsl** and **depth_camera_final_fs.glsl**
+ Far clipping changed from clipping by depth to clipping by range, i.e. distance to point, so that the data generated will never exceed the specified max range of the camera.

1. `Scene::SetTime` is often unset. Ignition's `Ogre2` now defaults to 60hz otherwise rendering won't advance forward.
+ Mostly affects Particles.
+ Also may affect gaussian postprocessing and other filters dependant on time.
+ Previous behavior was using real time instead of simulation time, which is wrong.
+ See https://github.com/ignitionrobotics/ign-rendering/issues/556 for details.

## Ignition Rendering 4.0 to 4.1

## ABI break
Expand Down
2 changes: 1 addition & 1 deletion examples/heightmap/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ void buildScene(ScenePtr _scene)
textureC2.SetDiffuse("../media/dirt_diffusespecular.png");
textureC2.SetNormal("../media/flat_normal.png");
desc2.AddTexture(textureC2);
desc2.SetPosition({30, 0, 0});
desc2.SetPosition({30, 10, 0});
auto heightmapGeom2 = _scene->CreateHeightmap(desc2);

auto vis2 = _scene->CreateVisual();
Expand Down
9 changes: 8 additions & 1 deletion ogre/src/OgreHeightmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,14 @@ void OgreHeightmap::Init()
for (unsigned int x = 0; x < vertSize; ++x)
{
int index = (vertSize - y - 1) * vertSize + x;
this->dataPtr->heights.push_back(lookup[index] - minElevation);

// Sanity check in case we get NaNs from ign-common, this prevents a crash
// in Ogre
auto value = lookup[index];
if (!std::isfinite(value))
value = minElevation;

this->dataPtr->heights.push_back(value - minElevation);
}
}

Expand Down
11 changes: 9 additions & 2 deletions ogre2/src/Ogre2Heightmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,13 @@ void Ogre2Heightmap::Init()
for (unsigned int x = 0; x < newWidth; ++x)
{
const size_t index = y * srcWidth + x;
const float heightVal = lookup[index];
float heightVal = lookup[index];

// Sanity check in case we get NaNs from ign-common, this prevents a crash
// in Ogre
if (!std::isfinite(heightVal))
heightVal = minElevation;

minElevation = std::min(minElevation, heightVal);
maxElevation = std::max(maxElevation, heightVal);
this->dataPtr->heights.push_back(heightVal);
Expand Down Expand Up @@ -208,9 +214,10 @@ void Ogre2Heightmap::Init()
const math::Vector3d newSize = this->descriptor.Size() *
math::Vector3d(1.0, 1.0, heightDiff);

// The position's Y sign ends up flipped
math::Vector3d center(
this->descriptor.Position().X(),
this->descriptor.Position().Y(),
-this->descriptor.Position().Y(),
chapulina marked this conversation as resolved.
Show resolved Hide resolved
this->descriptor.Position().Z() + newSize.Z() * 0.5 + minElevation);

Ogre::Root *ogreRoot = Ogre2RenderEngine::Instance()->OgreRoot();
Expand Down