From d98f87f25255d92b56c29135060cf1f4735ac066 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Fri, 6 Nov 2020 11:28:38 +0200 Subject: [PATCH] Change normal viz --- .../fusion/smoothing/mls_multi_weighted.cu | 2 +- components/renderers/cpp/src/CUDARender.cpp | 2 + components/renderers/cpp/src/normals.cu | 38 ++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/components/operators/src/fusion/smoothing/mls_multi_weighted.cu b/components/operators/src/fusion/smoothing/mls_multi_weighted.cu index fa73444dc..b9fbec08e 100644 --- a/components/operators/src/fusion/smoothing/mls_multi_weighted.cu +++ b/components/operators/src/fusion/smoothing/mls_multi_weighted.cu @@ -146,7 +146,7 @@ __device__ inline float biasedLength(const float3 &Xi, const float3 &X) { // TODO: Angle from cam (dot of normal and ray) //const float w_lateral = ftl::cuda::weighting(sqrt(Xi.x*X.x + Xi.y*X.y), float(SEARCH_RADIUS)*camera_origin.fx/Xi.z); const float w = (length(Ni) > 0.0f) - ?w_space * w_high_int * w_mean_int // min(w_space, min(w_high_int, w_mean_int)) + ? min(w_space, min(w_high_int, w_mean_int)) //w_space * w_high_int * w_mean_int // : 0.0f; // Mark as a symmetry contribution diff --git a/components/renderers/cpp/src/CUDARender.cpp b/components/renderers/cpp/src/CUDARender.cpp index 0f888dec2..52472c0b9 100644 --- a/components/renderers/cpp/src/CUDARender.cpp +++ b/components/renderers/cpp/src/CUDARender.cpp @@ -417,6 +417,8 @@ void CUDARender::_mesh(ftl::rgbd::Frame &out, const Eigen::Matrix4d &t, cudaStre );*/ } + //out.createTexture<half4>(_getNormalsChannel()); + ftl::cuda::transform_normals( out.createTexture<half4>(_getNormalsChannel()), poseInverse_.getFloat3x3(), diff --git a/components/renderers/cpp/src/normals.cu b/components/renderers/cpp/src/normals.cu index ddeb6294e..3afe06c70 100644 --- a/components/renderers/cpp/src/normals.cu +++ b/components/renderers/cpp/src/normals.cu @@ -409,7 +409,7 @@ void ftl::cuda::normals_dot(ftl::cuda::TextureObject<float> &output, //============================================================================== -__global__ void vis_normals_kernel(ftl::cuda::TextureObject<half4> norm, +/*__global__ void vis_normals_kernel(ftl::cuda::TextureObject<half4> norm, ftl::cuda::TextureObject<uchar4> output, float3 direction, uchar4 diffuse, uchar4 ambient) { const unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; @@ -433,6 +433,42 @@ __global__ void vis_normals_kernel(ftl::cuda::TextureObject<half4> norm, min(255.0f, diffuse.z*d + ambient.z), ambient.w); } } +}*/ + +__global__ void vis_normals_kernel(ftl::cuda::TextureObject<half4> norm, + ftl::cuda::TextureObject<uchar4> output, + float3 direction, uchar4 diffuse, uchar4 ambient +) { + const unsigned int x = blockIdx.x*blockDim.x + threadIdx.x; + const unsigned int y = blockIdx.y*blockDim.y + threadIdx.y; + + if(x < norm.width() && y < norm.height()) { + output(x,y) = make_uchar4(ambient.x,ambient.y,ambient.z,0); + + //float3 ray = direction; + //ray = ray / length(ray); + float3 n = make_float3(norm.tex2D((int)x,(int)y)); + float l = length(n); + + if (l != 0) { + n /= l; + + const float b = (n.z + 1.0f) * 0.5f * 255.0f; + const float g = (n.y + 1.0f) * 0.5f * 255.0f; + const float r = (n.x + 1.0f) * 0.5f * 255.0f; + + //const float d = max(dot(ray, n), 0.0f); + /*output(x,y) = make_uchar4( + min(255.0f, diffuse.x*d + ambient.x), + min(255.0f, diffuse.y*d + ambient.y), + min(255.0f, diffuse.z*d + ambient.z), ambient.w);*/ + + output(x,y) = make_uchar4( + min(255.0f, b + ambient.x), + min(255.0f, g + ambient.y), + min(255.0f, r + ambient.z), ambient.w); + } + } } void ftl::cuda::normal_visualise(ftl::cuda::TextureObject<half4> &norm, -- GitLab