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

Backport mac camera floating fix #339

Merged
merged 3 commits into from
Jun 14, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,18 @@ uniform float far;
uniform float min;
uniform float max;

uniform vec4 texResolution;

void main()
{
float tolerance = 1e-6;
vec4 p = texture(inputTexture, inPs.uv0);

// Note: We use texelFetch because p.a contains an uint32 and sampling
// (even w/ point filtering) causes p.a to loss information (e.g.
// values close to 0 get rounded to 0)
//
// See https://github.com/ignitionrobotics/ign-rendering/issues/332
vec4 p = texelFetch(inputTexture, ivec2(inPs.uv0 *texResolution.xy), 0);

vec3 point = p.xyz;

Expand Down
2 changes: 2 additions & 0 deletions ogre2/src/media/materials/scripts/depth_camera.material
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ fragment_program DepthCameraFinalFS glsl
default_params
{
param_named inputTexture int 0

param_named_auto texResolution texture_size 0
}
}

Expand Down
21 changes: 14 additions & 7 deletions test/integration/depth_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,9 @@ void DepthCameraTest::DepthCameraBoxes(
unsigned int ma = *mrgba >> 0 & 0xFF;
EXPECT_EQ(0u, mr);
EXPECT_EQ(0u, mg);
// Note: If it fails here, it may be this problem again:
// https://github.com/ignitionrobotics/ign-rendering/issues/332
EXPECT_GT(mb, 0u);
EXPECT_EQ(255u, ma);

// Far left and right points should be red (background color)
float lc = pointCloudData[pcLeft + 3];
Expand All @@ -263,7 +264,6 @@ void DepthCameraTest::DepthCameraBoxes(
EXPECT_EQ(255u, lr);
EXPECT_EQ(0u, lg);
EXPECT_EQ(0u, lb);
EXPECT_EQ(255u, la);

float rc = pointCloudData[pcRight + 3];
uint32_t *rrgba = reinterpret_cast<uint32_t *>(&rc);
Expand All @@ -275,7 +275,16 @@ void DepthCameraTest::DepthCameraBoxes(
EXPECT_EQ(255u, rr);
EXPECT_EQ(0u, rg);
EXPECT_EQ(0u, rb);
EXPECT_EQ(255u, ra);

// Note: internal texture format used is RGB with no alpha channel
// We observed the values can be either 255 or 0 but graphics card
// drivers are free to fill it with any value they want.
// This should be fixed in ogre 2.2 in ign-rendering6 which forbids
// the use of RGB format.
// see https://github.com/ignitionrobotics/ign-rendering/issues/315
EXPECT_TRUE(255u == ma || 0u == ma);
EXPECT_TRUE(255u == la || 0u == la);
EXPECT_TRUE(255u == ra || 0u == ra);
}

// Check that for a box really close it returns it is not seen
Expand Down Expand Up @@ -441,6 +450,8 @@ void DepthCameraTest::DepthCameraBoxes(
unsigned int a = *rgba >> 0 & 0xFF;
EXPECT_EQ(0u, r);
EXPECT_EQ(0u, g);
// Note: If it fails here, it may be this problem again:
// https://github.com/ignitionrobotics/ign-rendering/issues/332
EXPECT_GT(b, 0u);
EXPECT_EQ(255u, a);
}
Expand All @@ -458,11 +469,7 @@ void DepthCameraTest::DepthCameraBoxes(
ignition::rendering::unloadEngine(engine->Name());
}

#ifdef __APPLE__
TEST_P(DepthCameraTest, DISABLED_DepthCameraBoxes)
#else
TEST_P(DepthCameraTest, DepthCameraBoxes)
#endif
{
DepthCameraBoxes(GetParam());
}
Expand Down
17 changes: 10 additions & 7 deletions test/integration/render_pass.cc
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ void RenderPassTest::DepthGaussianNoise(const std::string &_renderEngine)
EXPECT_NEAR(0u, mr, colorNoiseTol);
EXPECT_NEAR(0u, mg, colorNoiseTol);
EXPECT_GT(mb, 0u);
EXPECT_EQ(255u, ma);

// Far left and right points should be red (background color)
float lc = pointCloudData[pcLeft + 3];
Expand All @@ -367,7 +366,6 @@ void RenderPassTest::DepthGaussianNoise(const std::string &_renderEngine)
EXPECT_NEAR(255u, lr, colorNoiseTol);
EXPECT_NEAR(0u, lg, colorNoiseTol);
EXPECT_NEAR(0u, lb, colorNoiseTol);
EXPECT_EQ(255u, la);

float rc = pointCloudData[pcRight + 3];
uint32_t *rrgba = reinterpret_cast<uint32_t *>(&rc);
Expand All @@ -379,7 +377,16 @@ void RenderPassTest::DepthGaussianNoise(const std::string &_renderEngine)
EXPECT_NEAR(255u, rr, colorNoiseTol);
EXPECT_NEAR(0u, rg, colorNoiseTol);
EXPECT_NEAR(0u, rb, colorNoiseTol);
EXPECT_EQ(255u, ra);

// Note: internal texture format used is RGB with no alpha channel
// We observed the values can be either 255 or 0 but graphics card
// drivers are free to fill it with any value they want.
// This should be fixed in ogre 2.2 in ign-rendering6 which forbids
// the use of RGB format.
// see https://github.com/ignitionrobotics/ign-rendering/issues/315
EXPECT_TRUE(255u == ma || 0u == ma);
EXPECT_TRUE(255u == la || 0u == la);
EXPECT_TRUE(255u == ra || 0u == ra);
}

// Clean up
Expand All @@ -399,11 +406,7 @@ TEST_P(RenderPassTest, GaussianNoise)
}

/////////////////////////////////////////////////
#ifdef __APPLE__
TEST_P(RenderPassTest, DISABLED_DepthGaussianNoise)
#else
TEST_P(RenderPassTest, DepthGaussianNoise)
#endif
{
DepthGaussianNoise(GetParam());
}
Expand Down