Skip to content

Commit

Permalink
Fix floating point precision bug handling alpha channel (gazebosim#332)…
Browse files Browse the repository at this point in the history
… (gazebosim#333)

Fixes gazebosim#332
Fixes gazebosim#108

Signed-off-by: Matias N. Goldberg <[email protected]>
  • Loading branch information
darksylinc authored Jun 9, 2021
1 parent fe9b5b3 commit 88f6339
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion ogre2/src/media/materials/programs/depth_camera_final_fs.glsl
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 @@ -88,6 +88,8 @@ fragment_program DepthCameraFinalFS glsl
default_params
{
param_named inputTexture int 0

param_named_auto texResolution texture_size 0
}
}

Expand Down
4 changes: 4 additions & 0 deletions test/integration/depth_camera.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,8 @@ 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);

// Far left and right points should be red (background color)
Expand Down Expand Up @@ -453,6 +455,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 Down

0 comments on commit 88f6339

Please sign in to comment.