@@ -16,8 +16,8 @@ namespace fvdb::detail::ops {
1616
1717template <typename ScalarType>
1818inline __device__ ScalarType
19- logistic (ScalarType x, ScalarType k = 100 , ScalarType x0 = 0.995 ) {
20- return 1 / (1 + exp (-k * (x - x0) ));
19+ sigmoid (ScalarType x) {
20+ return ScalarType ( 1 ) / (ScalarType ( 1 ) + :: cuda::std:: exp (-x ));
2121}
2222
2323template <typename ScalarType>
@@ -27,23 +27,30 @@ gaussianMCMCAddNoiseKernel(fvdb::TorchRAcc64<ScalarType, 2> outMeans,
2727 fvdb::TorchRAcc64<ScalarType, 1 > logitOpacities,
2828 fvdb::TorchRAcc64<ScalarType, 2 > quats,
2929 fvdb::TorchRAcc64<ScalarType, 2 > baseNoise,
30- ScalarType noiseScale) {
30+ const ScalarType noiseScale,
31+ const ScalarType t,
32+ const ScalarType k) {
3133 const auto N = outMeans.size (0 );
3234 for (uint32_t idx = blockIdx .x * blockDim .x + threadIdx .x ; idx < N;
3335 idx += blockDim .x * gridDim .x ) {
34- auto opacity = ScalarType ( 1.0 ) / ( 1 + exp (- logitOpacities[idx]) );
36+ const auto opacity = sigmoid ( logitOpacities[idx]);
3537
3638 const auto quatAcc = quats[idx];
3739 const auto logScaleAcc = logScales[idx];
38- auto covar = quaternionAndScaleToCovariance<ScalarType>(
40+ const auto covar = quaternionAndScaleToCovariance<ScalarType>(
3941 nanovdb::math::Vec4<ScalarType>(quatAcc[0 ], quatAcc[1 ], quatAcc[2 ], quatAcc[3 ]),
4042 nanovdb::math::Vec3<ScalarType>(::cuda::std::exp (logScaleAcc[0 ]),
4143 ::cuda::std::exp (logScaleAcc[1 ]),
4244 ::cuda::std::exp(logScaleAcc[2 ])));
4345
4446 nanovdb::math::Vec3<ScalarType> noise = {
4547 baseNoise[idx][0 ], baseNoise[idx][1 ], baseNoise[idx][2 ]};
46- noise *= logistic (1 - opacity) * noiseScale;
48+
49+ // The noise term is scaled down based on the opacity of the Gaussian.
50+ // More opaque Gaussians get less noise added to them.
51+ // The parameters t and k control the transition point and sharpness
52+ // of the scaling function.
53+ noise *= sigmoid (-k * (opacity - t)) * noiseScale;
4754 noise = covar * noise;
4855 outMeans[idx][0 ] += noise[0 ];
4956 outMeans[idx][1 ] += noise[1 ];
@@ -57,7 +64,9 @@ launchGaussianMCMCAddNoise(torch::Tensor &means, // [N, 3]
5764 const torch::Tensor &logScales, // [N, 3]
5865 const torch::Tensor &logitOpacities, // [N]
5966 const torch::Tensor &quats, // [N, 4]
60- ScalarType noiseScale) {
67+ const ScalarType noiseScale,
68+ const ScalarType t,
69+ const ScalarType k) {
6170 const auto N = means.size (0 );
6271
6372 const int blockDim = DEFAULT_BLOCK_DIM;
@@ -72,7 +81,9 @@ launchGaussianMCMCAddNoise(torch::Tensor &means, // [N, 3]
7281 logitOpacities.packed_accessor64 <ScalarType, 1 , torch::RestrictPtrTraits>(),
7382 quats.packed_accessor64 <ScalarType, 2 , torch::RestrictPtrTraits>(),
7483 baseNoise.packed_accessor64 <ScalarType, 2 , torch::RestrictPtrTraits>(),
75- noiseScale);
84+ noiseScale,
85+ t,
86+ k);
7687
7788 C10_CUDA_KERNEL_LAUNCH_CHECK ();
7889}
@@ -83,13 +94,15 @@ dispatchGaussianMCMCAddNoise<torch::kCUDA>(torch::Tensor &means,
8394 const torch::Tensor &logScales, // [N]
8495 const torch::Tensor &logitOpacities, // [N]
8596 const torch::Tensor &quats, // [N, 4]
86- float noiseScale) { // [N]
97+ const float noiseScale,
98+ const float t,
99+ const float k) {
87100 FVDB_FUNC_RANGE ();
88101 const at::cuda::OptionalCUDAGuard device_guard (device_of (means));
89102
90103 const auto N = means.size (0 );
91104
92- launchGaussianMCMCAddNoise<float >(means, logScales, logitOpacities, quats, noiseScale);
105+ launchGaussianMCMCAddNoise<float >(means, logScales, logitOpacities, quats, noiseScale, t, k );
93106}
94107
95108template <>
@@ -98,7 +111,9 @@ dispatchGaussianMCMCAddNoise<torch::kPrivateUse1>(torch::Tensor &means, // [N, 3
98111 const torch::Tensor &logScales, // [N, 3]
99112 const torch::Tensor &logitOpacities, // [N]
100113 const torch::Tensor &quats, // [N, 4]
101- float noiseScale) { // [N]
114+ const float noiseScale,
115+ const float t,
116+ const float k) {
102117 TORCH_CHECK_NOT_IMPLEMENTED (false , " GaussianMCMCAddNoise is not implemented for PrivateUse1" );
103118}
104119
@@ -108,7 +123,9 @@ dispatchGaussianMCMCAddNoise<torch::kCPU>(torch::Tensor &means, // [N,
108123 const torch::Tensor &logScales, // [N, 3]
109124 const torch::Tensor &logitOpacities, // [N]
110125 const torch::Tensor &quats, // [N, 4]
111- float noiseScale) { // [N]
126+ const float noiseScale,
127+ const float t,
128+ const float k) {
112129 TORCH_CHECK_NOT_IMPLEMENTED (false , " GaussianMCMCAddNoise is not implemented for CPU" );
113130}
114131
0 commit comments