Skip to content
Snippets Groups Projects
Commit 30012bab authored by Nicolas Pope's avatar Nicolas Pope
Browse files

Fix problem with normals

parent 2842b09f
No related branches found
No related tags found
1 merge request!354Add full 3D MLS and carving
Pipeline #33563 passed
...@@ -47,7 +47,7 @@ using ftl::cuda::TextureObject; ...@@ -47,7 +47,7 @@ using ftl::cuda::TextureObject;
const float3 Ni = make_float3(normals_in.tex2D((int)(x)+u, (int)(y)+v)); const float3 Ni = make_float3(normals_in.tex2D((int)(x)+u, (int)(y)+v));
// Gauss approx weighting function using point distance // Gauss approx weighting function using point distance
const float w = ftl::cuda::spatialWeighting(X,Xi,smoothing); const float w = (Ni.x+Ni.y+Ni.z == 0.0f) ? 0.0f : ftl::cuda::spatialWeighting(X,Xi,smoothing);
aX += Xi*w; aX += Xi*w;
nX += Ni*w; nX += Ni*w;
...@@ -55,6 +55,7 @@ using ftl::cuda::TextureObject; ...@@ -55,6 +55,7 @@ using ftl::cuda::TextureObject;
} }
} }
if (contrib > 0.0f) {
nX /= contrib; // Weighted average normal nX /= contrib; // Weighted average normal
aX /= contrib; // Weighted average point (centroid) aX /= contrib; // Weighted average point (centroid)
...@@ -72,6 +73,7 @@ using ftl::cuda::TextureObject; ...@@ -72,6 +73,7 @@ using ftl::cuda::TextureObject;
depth_out(x,y) = X.z; depth_out(x,y) = X.z;
normals_out(x,y) = make_half4(nX / length(nX), 0.0f); normals_out(x,y) = make_half4(nX / length(nX), 0.0f);
} }
}
void ftl::cuda::mls_smooth( void ftl::cuda::mls_smooth(
ftl::cuda::TextureObject<half4> &normals_in, ftl::cuda::TextureObject<half4> &normals_in,
...@@ -137,7 +139,7 @@ void ftl::cuda::mls_smooth( ...@@ -137,7 +139,7 @@ void ftl::cuda::mls_smooth(
const float3 Ni = make_float3(normals_in.tex2D((int)(x)+u, (int)(y)+v)); const float3 Ni = make_float3(normals_in.tex2D((int)(x)+u, (int)(y)+v));
// Gauss approx weighting function using point distance // Gauss approx weighting function using point distance
const float w = ftl::cuda::spatialWeighting(X,Xi,smoothing); const float w = (Ni.x+Ni.y+Ni.z == 0.0f) ? 0.0f : ftl::cuda::spatialWeighting(X,Xi,smoothing);
aX += Xi*w; aX += Xi*w;
nX += Ni*w; nX += Ni*w;
...@@ -145,6 +147,7 @@ void ftl::cuda::mls_smooth( ...@@ -145,6 +147,7 @@ void ftl::cuda::mls_smooth(
} }
} }
if (contrib > 0.0f) {
nX /= contrib; // Weighted average normal nX /= contrib; // Weighted average normal
aX /= contrib; // Weighted average point (centroid) aX /= contrib; // Weighted average point (centroid)
...@@ -162,6 +165,7 @@ void ftl::cuda::mls_smooth( ...@@ -162,6 +165,7 @@ void ftl::cuda::mls_smooth(
//depth_out(x,y) = X.z; //depth_out(x,y) = X.z;
normals_out(x,y) = make_half4(nX / length(nX), 0.0f); normals_out(x,y) = make_half4(nX / length(nX), 0.0f);
} }
}
void ftl::cuda::mls_smooth( void ftl::cuda::mls_smooth(
ftl::cuda::TextureObject<half4> &normals_in, ftl::cuda::TextureObject<half4> &normals_in,
......
...@@ -508,6 +508,28 @@ void CUDARender::_mesh(ftl::rgbd::Frame &out, const Eigen::Matrix4d &t, cudaStre ...@@ -508,6 +508,28 @@ void CUDARender::_mesh(ftl::rgbd::Frame &out, const Eigen::Matrix4d &t, cudaStre
params_.camera, params_.camera,
stream_ stream_
); );
ftl::cuda::mls_smooth(
out.createTexture<half4>(_getNormalsChannel()),
temp_.createTexture<half4>(Channel::Normals),
out.getTexture<float>(_getDepthChannel()),
//out.getTexture<float>(_getDepthChannel()),
value("mls_smooth", 0.01f),
value("mls_radius", 2),
params_.camera,
stream_
);
ftl::cuda::mls_smooth(
temp_.createTexture<half4>(Channel::Normals),
out.createTexture<half4>(_getNormalsChannel()),
out.getTexture<float>(_getDepthChannel()),
//out.getTexture<float>(_getDepthChannel()),
value("mls_smooth", 0.01f),
value("mls_radius", 2),
params_.camera,
stream_
);
} }
} }
......
...@@ -221,13 +221,13 @@ void ftl::cuda::depth_carve( ...@@ -221,13 +221,13 @@ void ftl::cuda::depth_carve(
// Point and normal of neighbour // Point and normal of neighbour
const float3 Xi = in_2_o * camera_in.screenToCam(s.x+u, s.y+v, d); const float3 Xi = in_2_o * camera_in.screenToCam(s.x+u, s.y+v, d);
const float3 Ni = in_2_o33 * make_float3(normals_in[s.x+u+(s.y+v)*npitch_in]); const float3 Ni = make_float3(normals_in[s.x+u+(s.y+v)*npitch_in]);
// Gauss approx weighting function using point distance // Gauss approx weighting function using point distance
const float w = (Ni.x+Ni.y+Ni.z > 0.0f) ? ftl::cuda::spatialWeighting(X,Xi,smoothing) : 0.0f; const float w = (length(Ni) > 0.0f) ? ftl::cuda::spatialWeighting(X,Xi,smoothing) : 0.0f;
aX += Xi*w; aX += Xi*w;
nX += Ni*w; nX += (in_2_o33 * Ni)*w;
contrib += w; contrib += w;
} }
} }
...@@ -265,7 +265,8 @@ __global__ void mls_reduce_kernel( ...@@ -265,7 +265,8 @@ __global__ void mls_reduce_kernel(
normals_out[x+y*npitch] = make_half4(0.0f, 0.0f, 0.0f, 0.0f); normals_out[x+y*npitch] = make_half4(0.0f, 0.0f, 0.0f, 0.0f);
float d0 = depth[x+y*dpitch]; float d0 = depth[x+y*dpitch];
if (d0 < camera.minDepth || d0 > camera.maxDepth || contrib == 0.0f) return; //depth[x+y*dpitch] = 0.0f;
if (d0 <= camera.minDepth || d0 >= camera.maxDepth || contrib == 0.0f) return;
float3 X = camera.screenToCam((int)(x),(int)(y),d0); float3 X = camera.screenToCam((int)(x),(int)(y),d0);
nX /= contrib; // Weighted average normal nX /= contrib; // Weighted average normal
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment