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

Allow config of back point cull

parent 3e39c8e3
No related branches found
No related tags found
1 merge request!117Implements #181 back facing cull
Pipeline #14782 passed
...@@ -44,6 +44,7 @@ class Splatter : public ftl::render::Renderer { ...@@ -44,6 +44,7 @@ class Splatter : public ftl::render::Renderer {
ftl::cuda::ClipSpace clip_; ftl::cuda::ClipSpace clip_;
bool clipping_; bool clipping_;
float norm_filter_; float norm_filter_;
bool backcull_;
}; };
} }
......
...@@ -54,6 +54,11 @@ Splatter::Splatter(nlohmann::json &config, ftl::rgbd::FrameSet *fs) : ftl::rende ...@@ -54,6 +54,11 @@ Splatter::Splatter(nlohmann::json &config, ftl::rgbd::FrameSet *fs) : ftl::rende
on("normal_filter", [this](const ftl::config::Event &e) { on("normal_filter", [this](const ftl::config::Event &e) {
norm_filter_ = value("normal_filter", -1.0f); norm_filter_ = value("normal_filter", -1.0f);
}); });
backcull_ = value("back_cull", true);
on("back_cull", [this](const ftl::config::Event &e) {
backcull_ = value("back_cull", true);
});
} }
Splatter::~Splatter() { Splatter::~Splatter() {
...@@ -90,7 +95,7 @@ void Splatter::renderChannel( ...@@ -90,7 +95,7 @@ void Splatter::renderChannel(
f.createTexture<float4>(Channel::Points), f.createTexture<float4>(Channel::Points),
f.createTexture<float4>(Channel::Normals), f.createTexture<float4>(Channel::Normals),
temp_.getTexture<int>(Channel::Depth), temp_.getTexture<int>(Channel::Depth),
params, stream params, backcull_, stream
); );
//LOG(INFO) << "DIBR DONE"; //LOG(INFO) << "DIBR DONE";
......
...@@ -20,6 +20,7 @@ using ftl::render::SplatParams; ...@@ -20,6 +20,7 @@ using ftl::render::SplatParams;
* Pass 1: Directly render each camera into virtual view but with no upsampling * Pass 1: Directly render each camera into virtual view but with no upsampling
* for sparse points. * for sparse points.
*/ */
template <bool CULLING>
__global__ void dibr_merge_kernel(TextureObject<float4> points, __global__ void dibr_merge_kernel(TextureObject<float4> points,
TextureObject<float4> normals, TextureObject<float4> normals,
TextureObject<int> depth, SplatParams params) { TextureObject<int> depth, SplatParams params) {
...@@ -29,6 +30,8 @@ using ftl::render::SplatParams; ...@@ -29,6 +30,8 @@ using ftl::render::SplatParams;
const float4 worldPos = points.tex2D(x, y); const float4 worldPos = points.tex2D(x, y);
if (worldPos.x == MINF || (!(params.m_flags & ftl::render::kShowDisconMask) && worldPos.w < 0.0f)) return; if (worldPos.x == MINF || (!(params.m_flags & ftl::render::kShowDisconMask) && worldPos.w < 0.0f)) return;
// Compile time enable/disable of culling back facing points
if (CULLING) {
float3 ray = params.m_viewMatrixInverse.getFloat3x3() * params.camera.screenToCam(x,y,1.0f); float3 ray = params.m_viewMatrixInverse.getFloat3x3() * params.camera.screenToCam(x,y,1.0f);
ray = ray / length(ray); ray = ray / length(ray);
float3 n = make_float3(normals.tex2D((int)x,(int)y)); float3 n = make_float3(normals.tex2D((int)x,(int)y));
...@@ -40,6 +43,7 @@ using ftl::render::SplatParams; ...@@ -40,6 +43,7 @@ using ftl::render::SplatParams;
const float facing = dot(ray, n); const float facing = dot(ray, n);
if (facing <= 0.0f) return; if (facing <= 0.0f) return;
}
// Find the virtual screen position of current point // Find the virtual screen position of current point
const float3 camPos = params.m_viewMatrix * make_float3(worldPos); const float3 camPos = params.m_viewMatrix * make_float3(worldPos);
...@@ -57,11 +61,12 @@ using ftl::render::SplatParams; ...@@ -57,11 +61,12 @@ using ftl::render::SplatParams;
} }
} }
void ftl::cuda::dibr_merge(TextureObject<float4> &points, TextureObject<float4> &normals, TextureObject<int> &depth, SplatParams params, cudaStream_t stream) { void ftl::cuda::dibr_merge(TextureObject<float4> &points, TextureObject<float4> &normals, TextureObject<int> &depth, SplatParams params, bool culling, cudaStream_t stream) {
const dim3 gridSize((depth.width() + T_PER_BLOCK - 1)/T_PER_BLOCK, (depth.height() + T_PER_BLOCK - 1)/T_PER_BLOCK); const dim3 gridSize((depth.width() + T_PER_BLOCK - 1)/T_PER_BLOCK, (depth.height() + T_PER_BLOCK - 1)/T_PER_BLOCK);
const dim3 blockSize(T_PER_BLOCK, T_PER_BLOCK); const dim3 blockSize(T_PER_BLOCK, T_PER_BLOCK);
dibr_merge_kernel<<<gridSize, blockSize, 0, stream>>>(points, normals, depth, params); if (culling) dibr_merge_kernel<true><<<gridSize, blockSize, 0, stream>>>(points, normals, depth, params);
else dibr_merge_kernel<false><<<gridSize, blockSize, 0, stream>>>(points, normals, depth, params);
cudaSafeCall( cudaGetLastError() ); cudaSafeCall( cudaGetLastError() );
} }
......
...@@ -11,6 +11,7 @@ namespace cuda { ...@@ -11,6 +11,7 @@ namespace cuda {
ftl::cuda::TextureObject<float4> &normals, ftl::cuda::TextureObject<float4> &normals,
ftl::cuda::TextureObject<int> &depth, ftl::cuda::TextureObject<int> &depth,
ftl::render::SplatParams params, ftl::render::SplatParams params,
bool culling,
cudaStream_t stream); cudaStream_t stream);
void dibr_attribute( void dibr_attribute(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment