Skip to content

Commit 444443a

Browse files
committed
Fix floating point precision bug handling alpha channel (gazebosim#332)
Fixes gazebosim#332 Fixes gazebosim#108 Signed-off-by: Matias N. Goldberg <[email protected]>
1 parent fe9b5b3 commit 444443a

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

ogre2/src/media/materials/programs/depth_camera_final_fs.glsl

+9-1
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,18 @@ uniform float far;
3131
uniform float min;
3232
uniform float max;
3333

34+
uniform vec4 texResolution;
35+
3436
void main()
3537
{
3638
float tolerance = 1e-6;
37-
vec4 p = texture(inputTexture, inPs.uv0);
39+
40+
// Note: We use texelFetch because p.a contains an uint32 and sampling
41+
// (even w/ point filtering) causes p.a to loss information (e.g.
42+
// values close to 0 get rounded to 0)
43+
//
44+
// See https://github.com/ignitionrobotics/ign-rendering/issues/332
45+
vec4 p = texelFetch(inputTexture, ivec2(inPs.uv0 *texResolution.xy), 0);
3846

3947
vec3 point = p.xyz;
4048

ogre2/src/media/materials/scripts/depth_camera.material

+2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ fragment_program DepthCameraFinalFS glsl
8888
default_params
8989
{
9090
param_named inputTexture int 0
91+
92+
param_named_auto texResolution texture_size 0
9193
}
9294
}
9395

test/integration/depth_camera.cc

+4
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ void DepthCameraTest::DepthCameraBoxes(
254254
unsigned int ma = *mrgba >> 0 & 0xFF;
255255
EXPECT_EQ(0u, mr);
256256
EXPECT_EQ(0u, mg);
257+
// Note: If it fails here, it may be this problem again:
258+
// https://github.com/ignitionrobotics/ign-rendering/issues/332
257259
EXPECT_GT(mb, 0u);
258260

259261
// Far left and right points should be red (background color)
@@ -453,6 +455,8 @@ void DepthCameraTest::DepthCameraBoxes(
453455
unsigned int a = *rgba >> 0 & 0xFF;
454456
EXPECT_EQ(0u, r);
455457
EXPECT_EQ(0u, g);
458+
// Note: If it fails here, it may be this problem again:
459+
// https://github.com/ignitionrobotics/ign-rendering/issues/332
456460
EXPECT_GT(b, 0u);
457461
EXPECT_EQ(255u, a);
458462
}

0 commit comments

Comments
 (0)