diff --git a/components/renderers/cpp/src/splat_render.cpp b/components/renderers/cpp/src/splat_render.cpp index f766fa1e385c9e74be3bded23e2377d4c1ddcede..813cbda8392ce36d8b9f70d1239087e55cbfd8f7 100644 --- a/components/renderers/cpp/src/splat_render.cpp +++ b/components/renderers/cpp/src/splat_render.cpp @@ -259,6 +259,7 @@ void Splatter::_renderChannel( if (is_4chan) { ftl::cuda::splat( accum_.getTexture<float4>(Channel::Normals), + accum_.getTexture<float>(Channel::Density), accum_.getTexture<float4>(channel_out), temp_.getTexture<int>(Channel::Depth2), out.createTexture<float>(Channel::Depth), @@ -268,6 +269,7 @@ void Splatter::_renderChannel( } else if (is_float) { ftl::cuda::splat( accum_.getTexture<float4>(Channel::Normals), + accum_.getTexture<float>(Channel::Density), accum_.getTexture<float>(channel_out), temp_.getTexture<int>(Channel::Depth2), out.createTexture<float>(Channel::Depth), @@ -277,6 +279,7 @@ void Splatter::_renderChannel( } else { ftl::cuda::splat( accum_.getTexture<float4>(Channel::Normals), + accum_.getTexture<float>(Channel::Density), accum_.getTexture<uchar4>(channel_out), temp_.getTexture<int>(Channel::Depth2), out.createTexture<float>(Channel::Depth), diff --git a/components/renderers/cpp/src/splatter.cu b/components/renderers/cpp/src/splatter.cu index a26cd502d2de31a8591f7c0ca75dc964f0c2429b..70be6c7baae1b56e565c96decf79dad7b978503f 100644 --- a/components/renderers/cpp/src/splatter.cu +++ b/components/renderers/cpp/src/splatter.cu @@ -150,6 +150,7 @@ __device__ inline float make(float v) { __global__ void splat_kernel( //TextureObject<float4> points, // Original 3D points TextureObject<float4> normals, + TextureObject<float> density, TextureObject<T> in, TextureObject<int> depth_in, // Virtual depth map TextureObject<float> depth_out, // Accumulated output @@ -205,7 +206,7 @@ __device__ inline float make(float v) { // Assumed to be normalised - float4 n = normals.tex2D((int)(x+u), (int)(y+v)); + float4 n = normals.tex2D((int)(x)+u, (int)(y)+v); n /= length(n); //if (length(make_float3(n)) == 0.0f) printf("BAD NORMAL\n"); @@ -214,8 +215,9 @@ __device__ inline float make(float v) { const float r = ftl::cuda::intersectDistance(make_float3(n), worldPos, origin, ray, t); if (r != PINF) { //} && fabs(t-camPos.z) < 0.01f) { // Adjust from normalised ray back to original meters units - t *= scale; - float weight = ftl::cuda::weighting(r, 2.0f/params.camera.fx); // (1.0f/params.camera.fx) / (t/params.camera.fx) + t *= scale; + const float dens = density.tex2D((int)(x)+u, (int)(y)+v); + float weight = ftl::cuda::weighting(r, dens/params.camera.fx); // (1.0f/params.camera.fx) / (t/params.camera.fx) /* Buehler C. et al. 2001. Unstructured Lumigraph Rendering. */ /* Orts-Escolano S. et al. 2016. Holoportation: Virtual 3D teleportation in real-time. */ @@ -269,6 +271,7 @@ __device__ inline float make(float v) { template <typename T> void ftl::cuda::splat( TextureObject<float4> &normals, + TextureObject<float> &density, TextureObject<T> &colour_in, TextureObject<int> &depth_in, // Virtual depth map TextureObject<float> &depth_out, @@ -279,6 +282,7 @@ void ftl::cuda::splat( splat_kernel<8,T><<<gridSize, blockSize, 0, stream>>>( normals, + density, colour_in, depth_in, depth_out, @@ -290,6 +294,7 @@ void ftl::cuda::splat( template void ftl::cuda::splat<uchar4>( TextureObject<float4> &normals, + TextureObject<float> &density, TextureObject<uchar4> &colour_in, TextureObject<int> &depth_in, // Virtual depth map TextureObject<float> &depth_out, @@ -297,7 +302,8 @@ template void ftl::cuda::splat<uchar4>( const SplatParams ¶ms, cudaStream_t stream); template void ftl::cuda::splat<float4>( - TextureObject<float4> &normals, + TextureObject<float4> &normals, + TextureObject<float> &density, TextureObject<float4> &colour_in, TextureObject<int> &depth_in, // Virtual depth map TextureObject<float> &depth_out, @@ -305,7 +311,8 @@ template void ftl::cuda::splat<float4>( const SplatParams ¶ms, cudaStream_t stream); template void ftl::cuda::splat<float>( - TextureObject<float4> &normals, + TextureObject<float4> &normals, + TextureObject<float> &density, TextureObject<float> &colour_in, TextureObject<int> &depth_in, // Virtual depth map TextureObject<float> &depth_out, diff --git a/components/renderers/cpp/src/splatter_cuda.hpp b/components/renderers/cpp/src/splatter_cuda.hpp index 463beefb18b54879a401580083cf21ca58b5d38f..684b0de5597f79ab8df78188d6552c08b5734c9a 100644 --- a/components/renderers/cpp/src/splatter_cuda.hpp +++ b/components/renderers/cpp/src/splatter_cuda.hpp @@ -17,6 +17,7 @@ namespace cuda { template <typename T> void splat( ftl::cuda::TextureObject<float4> &normals, + ftl::cuda::TextureObject<float> &density, ftl::cuda::TextureObject<T> &colour_in, ftl::cuda::TextureObject<int> &depth_in, // Virtual depth map ftl::cuda::TextureObject<float> &depth_out,