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

Revert to old normals

parent 1c623d96
No related branches found
No related tags found
1 merge request!123Implements #189 using density to estimate radius
Pipeline #15064 failed
...@@ -57,7 +57,7 @@ __global__ void computeNormals_kernel(ftl::cuda::TextureObject<float4> output, ...@@ -57,7 +57,7 @@ __global__ void computeNormals_kernel(ftl::cuda::TextureObject<float4> output,
const float l = length(n); const float l = length(n);
if(l > 0.0f) { if(l > 0.0f) {
output(x,y) = make_float4(pose * (n/-l), 1.0f); output(x,y) = make_float4((n/-l), 1.0f);
} }
} }
} }
...@@ -131,22 +131,22 @@ __global__ void smooth_normals_kernel(ftl::cuda::TextureObject<float4> norms, ...@@ -131,22 +131,22 @@ __global__ void smooth_normals_kernel(ftl::cuda::TextureObject<float4> norms,
//if (s > 0.0f) { //if (s > 0.0f) {
const float4 n = norms.tex2D((int)x+u,(int)y+v); const float4 n = norms.tex2D((int)x+u,(int)y+v);
//if (n.w > 0.0f) { if (n.w > 0.0f) {
nsum += make_float3(n) * s; nsum += make_float3(n) * s;
contrib += s; contrib += s;
//} }
//} //}
} }
} }
// Compute dot product of normal with camera to obtain measure of how // Compute dot product of normal with camera to obtain measure of how
// well this point faces the source camera, a measure of confidence // well this point faces the source camera, a measure of confidence
float3 ray = pose * camera.screenToCam(x, y, 1.0f); float3 ray = camera.screenToCam(x, y, 1.0f);
ray = ray / length(ray); ray = ray / length(ray);
nsum /= contrib; nsum /= contrib;
nsum /= length(nsum); nsum /= length(nsum);
output(x,y) = (contrib > 0.0f) ? make_float4(nsum, 1.0f) : make_float4(0.0f); //dot(nsum, ray) output(x,y) = (contrib > 0.0f) ? make_float4(pose*nsum, 1.0f) : make_float4(0.0f);
} }
void ftl::cuda::normals(ftl::cuda::TextureObject<float4> &output, void ftl::cuda::normals(ftl::cuda::TextureObject<float4> &output,
...@@ -163,9 +163,10 @@ void ftl::cuda::normals(ftl::cuda::TextureObject<float4> &output, ...@@ -163,9 +163,10 @@ void ftl::cuda::normals(ftl::cuda::TextureObject<float4> &output,
cudaSafeCall( cudaGetLastError() ); cudaSafeCall( cudaGetLastError() );
switch (radius) { switch (radius) {
case 7: smooth_normals_kernel<7><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose, smoothing); case 9: smooth_normals_kernel<9><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose, smoothing); break;
case 5: smooth_normals_kernel<5><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose, smoothing); case 7: smooth_normals_kernel<7><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose, smoothing); break;
case 3: smooth_normals_kernel<3><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose, smoothing); case 5: smooth_normals_kernel<5><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose, smoothing); break;
case 3: smooth_normals_kernel<3><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose, smoothing); break;
} }
cudaSafeCall( cudaGetLastError() ); cudaSafeCall( cudaGetLastError() );
...@@ -189,9 +190,9 @@ void ftl::cuda::normals(ftl::cuda::TextureObject<float4> &output, ...@@ -189,9 +190,9 @@ void ftl::cuda::normals(ftl::cuda::TextureObject<float4> &output,
cudaSafeCall( cudaGetLastError() ); cudaSafeCall( cudaGetLastError() );
switch (radius) { switch (radius) {
case 7: smooth_normals_kernel<7><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose_inv, smoothing); case 7: smooth_normals_kernel<7><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose, smoothing);
case 5: smooth_normals_kernel<5><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose_inv, smoothing); case 5: smooth_normals_kernel<5><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose, smoothing);
case 3: smooth_normals_kernel<3><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose_inv, smoothing); case 3: smooth_normals_kernel<3><<<gridSize, blockSize, 0, stream>>>(temp, output, input, camera, pose, smoothing);
} }
cudaSafeCall( cudaGetLastError() ); cudaSafeCall( cudaGetLastError() );
......
...@@ -168,7 +168,7 @@ void Splatter::renderChannel( ...@@ -168,7 +168,7 @@ void Splatter::renderChannel(
out.get<GpuMat>(Channel::Normals).setTo(cv::Scalar(0.0f,0.0f,0.0f,0.0f), cvstream); out.get<GpuMat>(Channel::Normals).setTo(cv::Scalar(0.0f,0.0f,0.0f,0.0f), cvstream);
// Create normals first // Create normals first
/*for (auto &f : scene_->frames) { for (auto &f : scene_->frames) {
ftl::cuda::dibr_attribute( ftl::cuda::dibr_attribute(
f.createTexture<float4>(Channel::Normals), f.createTexture<float4>(Channel::Normals),
...@@ -185,15 +185,15 @@ void Splatter::renderChannel( ...@@ -185,15 +185,15 @@ void Splatter::renderChannel(
out.getTexture<float4>(Channel::Normals), out.getTexture<float4>(Channel::Normals),
temp_.getTexture<float>(Channel::Contribution), temp_.getTexture<float>(Channel::Contribution),
stream stream
);*/ );
//auto &t = out.createTexture<float4>(Channel::Points, Format<float4>(params.camera.width, params.camera.height)); //auto &t = out.createTexture<float4>(Channel::Points, Format<float4>(params.camera.width, params.camera.height));
//ftl::cuda::point_cloud(t, temp_.getTexture<int>(Channel::Depth2), params.camera, params.m_viewMatrixInverse, 0, stream); //ftl::cuda::point_cloud(t, temp_.getTexture<int>(Channel::Depth2), params.camera, params.m_viewMatrixInverse, 0, stream);
ftl::cuda::normals(out.createTexture<float4>(Channel::Normals), /*ftl::cuda::normals(out.createTexture<float4>(Channel::Normals),
temp_.getTexture<float4>(Channel::Normals), temp_.getTexture<float4>(Channel::Normals),
temp_.getTexture<int>(Channel::Depth2), temp_.getTexture<int>(Channel::Depth2),
5, 0.04f, 9, 0.04f,
params.camera, params.m_viewMatrixInverse.getFloat3x3(), params.m_viewMatrix.getFloat3x3(), stream); params.camera, params.m_viewMatrixInverse.getFloat3x3(), params.m_viewMatrix.getFloat3x3(), stream);*/
//if (norm_filter_ > -0.1f) { //if (norm_filter_ > -0.1f) {
// ftl::cuda::normal_filter(f.getTexture<float4>(Channel::Normals), f.getTexture<float4>(Channel::Points), s->parameters(), pose, norm_filter_, stream); // ftl::cuda::normal_filter(f.getTexture<float4>(Channel::Normals), f.getTexture<float4>(Channel::Points), s->parameters(), pose, norm_filter_, stream);
......
...@@ -204,13 +204,14 @@ __device__ inline float make(float v) { ...@@ -204,13 +204,14 @@ __device__ inline float make(float v) {
// Assumed to be normalised // Assumed to be normalised
float4 n = normals.tex2D((int)(x+u), (int)(y+v)); float4 n = normals.tex2D((int)(x+u), (int)(y+v));
//if (length(make_float3(n)) == 0.0f) printf("BAD NORMAL\n");
// Does the ray intersect plane of splat? // Does the ray intersect plane of splat?
float t = 1000.0f; float t = 1000.0f;
if (ftl::cuda::intersectPlane(make_float3(n), worldPos, origin, ray, t)) { //} && fabs(t-camPos.z) < 0.01f) { if (ftl::cuda::intersectPlane(make_float3(n), worldPos, origin, ray, t)) { //} && fabs(t-camPos.z) < 0.01f) {
// Adjust from normalised ray back to original meters units // Adjust from normalised ray back to original meters units
t *= scale; t *= scale;
const float3 camPos3 = params.camera.screenToCam((int)(x),(int)(y),t); const float3 camPos3 = params.camera.screenToCam((int)(x),(int)(y),t);
float weight = ftl::cuda::spatialWeighting(camPos, camPos3, 2.0f*(camPos3.z/params.camera.fx)); float weight = ftl::cuda::spatialWeighting(camPos, camPos3, 2.0f*(camPos3.z/params.camera.fx));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment