From 0a3561d36a9bdb0a145f6396c9eef18064e775c6 Mon Sep 17 00:00:00 2001
From: Nicolas Pope <nwpope@utu.fi>
Date: Wed, 2 Oct 2019 19:02:53 +0300
Subject: [PATCH] Display discon mask in render

---
 .../renderers/cpp/include/ftl/render/splat_params.hpp |  2 +-
 components/renderers/cpp/src/splat_render.cpp         |  7 ++++---
 components/renderers/cpp/src/splatter.cu              | 11 ++++++-----
 3 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/components/renderers/cpp/include/ftl/render/splat_params.hpp b/components/renderers/cpp/include/ftl/render/splat_params.hpp
index 4f9c8882b..5bd7d2edb 100644
--- a/components/renderers/cpp/include/ftl/render/splat_params.hpp
+++ b/components/renderers/cpp/include/ftl/render/splat_params.hpp
@@ -8,7 +8,7 @@
 namespace ftl {
 namespace render {
 
-static const uint kShowBlockBorders = 0x00000001;  // Deprecated: from voxels system
+static const uint kShowDisconMask = 0x00000001;
 static const uint kNoSplatting = 0x00000002;
 static const uint kNoUpsampling = 0x00000004;
 static const uint kNoTexturing = 0x00000008;
diff --git a/components/renderers/cpp/src/splat_render.cpp b/components/renderers/cpp/src/splat_render.cpp
index 24afd49a6..6635d1ab4 100644
--- a/components/renderers/cpp/src/splat_render.cpp
+++ b/components/renderers/cpp/src/splat_render.cpp
@@ -224,9 +224,10 @@ bool Splatter::render(ftl::rgbd::VirtualSource *src, ftl::rgbd::Frame &out, cuda
 	// Parameters object to pass to CUDA describing the camera
 	SplatParams params;
 	params.m_flags = 0;
-	if (src->value("splatting", true) == false) params.m_flags |= ftl::render::kNoSplatting;
-	if (src->value("upsampling", true) == false) params.m_flags |= ftl::render::kNoUpsampling;
-	if (src->value("texturing", true) == false) params.m_flags |= ftl::render::kNoTexturing;
+	if (src->value("show_discontinuity_mask", false)) params.m_flags |= ftl::render::kShowDisconMask;
+	//if (src->value("splatting", true) == false) params.m_flags |= ftl::render::kNoSplatting;
+	//if (src->value("upsampling", true) == false) params.m_flags |= ftl::render::kNoUpsampling;
+	//if (src->value("texturing", true) == false) params.m_flags |= ftl::render::kNoTexturing;
 	params.m_viewMatrix = MatrixConversion::toCUDA(src->getPose().cast<float>().inverse());
 	params.m_viewMatrixInverse = MatrixConversion::toCUDA(src->getPose().cast<float>());
 	params.camera = camera;
diff --git a/components/renderers/cpp/src/splatter.cu b/components/renderers/cpp/src/splatter.cu
index 41777d49d..de3902b6c 100644
--- a/components/renderers/cpp/src/splatter.cu
+++ b/components/renderers/cpp/src/splatter.cu
@@ -25,7 +25,7 @@ using ftl::render::SplatParams;
 	const int y = blockIdx.y*blockDim.y + threadIdx.y;
 
 	const float4 worldPos = points.tex2D(x, y);
-	if (worldPos.x == MINF || worldPos.w < 0.0f) return;
+	if (worldPos.x == MINF || (!(params.m_flags & ftl::render::kShowDisconMask) && worldPos.w < 0.0f)) return;
 
     // Find the virtual screen position of current point
 	const float3 camPos = params.m_viewMatrix * make_float3(worldPos);
@@ -84,12 +84,12 @@ __global__ void dibr_attribute_contrib_kernel(
 	const int x = (blockIdx.x*blockDim.x + threadIdx.x) / WARP_SIZE;
 	const int y = blockIdx.y*blockDim.y + threadIdx.y;
 
-	const float3 worldPos = make_float3(points.tex2D(x, y));
+	const float4 worldPos = points.tex2D(x, y);
 	//const float3 normal = make_float3(tex2D<float4>(camera.normal, x, y));
 	if (worldPos.x == MINF) return;
     //const float r = (camera.poseInverse * worldPos).z / camera.params.fx;
 
-	const float3 camPos = params.m_viewMatrix * worldPos;
+	const float3 camPos = params.m_viewMatrix * make_float3(worldPos);
 	if (camPos.z < params.camera.minDepth) return;
 	if (camPos.z > params.camera.maxDepth) return;
 	const uint2 screenPos = params.camera.camToScreen<uint2>(camPos);
@@ -103,8 +103,9 @@ __global__ void dibr_attribute_contrib_kernel(
     const float d = ((float)depth_in.tex2D((int)screenPos.x, (int)screenPos.y)/1000.0f);
     //if (abs(d - camPos.z) > DEPTH_THRESHOLD) return;
 
-    // TODO:(Nick) Should just one thread load these to shared mem?
-    const float4 colour = make_float4(colour_in.tex2D(x, y));
+	const float4 colour = (params.m_flags & ftl::render::kShowDisconMask && worldPos.w < 0.0f) ?
+			make_float4(0.0f,0.0f,255.0f,255.0f) :
+			make_float4(colour_in.tex2D(x, y));
     //const float4 normal = tex2D<float4>(camera.normal, x, y);
 
 	// Each thread in warp takes an upsample point and updates corresponding depth buffer.
-- 
GitLab