From 661d22484ac4fe15495d34410eab4c635b3ceb74 Mon Sep 17 00:00:00 2001 From: hbb1 Date: Mon, 6 May 2024 14:43:43 +0800 Subject: [PATCH] finalize the code --- README.md | 15 +++++++-------- cuda_rasterizer/auxiliary.h | 2 +- cuda_rasterizer/backward.cu | 18 +++++++++++++----- cuda_rasterizer/forward.cu | 20 +++++++++++++------- 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 796c16f..8c51805 100644 --- a/README.md +++ b/README.md @@ -5,18 +5,17 @@ This is the rasterization engine for the paper "2D Gaussian Splatting for Geome

BibTeX

-
@article{huang2dgs,
-  title={2D Gaussian Splatting for Geometrically Accurate Radiance Fields},
-  author={Huang, Binbin and Yu, Zehao and Chen, Anpei and Geiger, Andreas and Gao, Shenghua},
-  journal={arXiv preprint arXiv:2403.17888},
-  year={2024}
+    
@inproceedings{Huang2DGS2024,
+    title={2D Gaussian Splatting for Geometrically Accurate Radiance Fields},
+    author={Huang, Binbin and Yu, Zehao and Chen, Anpei and Geiger, Andreas and Gao, Shenghua},
+    publisher = {Association for Computing Machinery},
+    booktitle = {SIGGRAPH 2024 Conference Papers},
+    year      = {2024},
+    doi       = {10.1145/3641519.3657428}
 }
- -Our rasterization is based on the diff-gaussian-rasterization engine from the paper "3D Gaussian Splatting for Real-Time Rendering of Radiance Fields". If you can make use of it in your own research, please also be so kind as to cite them. -

BibTeX

diff --git a/cuda_rasterizer/auxiliary.h b/cuda_rasterizer/auxiliary.h index e291dd4..49c7f98 100644 --- a/cuda_rasterizer/auxiliary.h +++ b/cuda_rasterizer/auxiliary.h @@ -34,7 +34,7 @@ #define DUAL_VISIABLE 1 #define NEAR_PLANE 0.2 #define FAR_PLANE 100.0 -#define DETACH_WEIGHT 1 +#define DETACH_WEIGHT 0 // Spherical harmonics coefficients __device__ const float SH_C0 = 0.28209479177387814f; diff --git a/cuda_rasterizer/backward.cu b/cuda_rasterizer/backward.cu index be1521c..4076755 100644 --- a/cuda_rasterizer/backward.cu +++ b/cuda_rasterizer/backward.cu @@ -286,21 +286,27 @@ renderCUDA( // compute two planes intersection as the ray intersection float3 k = {-Tu.x + pixf.x * Tw.x, -Tu.y + pixf.x * Tw.y, -Tu.z + pixf.x * Tw.z}; float3 l = {-Tv.x + pixf.y * Tw.x, -Tv.y + pixf.y * Tw.y, -Tv.z + pixf.y * Tw.z}; - + // cross product of two planes is a line (i.e., homogeneous point), See Eq. (10) float3 p = crossProduct(k, l); #if BACKFACE_CULL + // May hanle this by replacing a low pass filter, + // but this case is extremely rare. if (p.z == 0.0) continue; // there is not intersection #endif - float2 s = {p.x / p.z, p.y / p.z}; + + float2 s = {p.x / p.z, p.y / p.z}; + // Compute Mahalanobis distance in the canonical splat' space float rho3d = (s.x * s.x + s.y * s.y); // splat distance - // add low pass filter according to Botsch et al. [2005]. + // Add low pass filter according to Botsch et al. [2005], + // see Eq. (11) from 2DGS paper. float2 xy = collected_xy[j]; + // 2d screen distance float2 d = {xy.x - pixf.x, xy.y - pixf.y}; float rho2d = FilterInvSquare * (d.x * d.x + d.y * d.y); // screen distance float rho = min(rho3d, rho2d); - // compute accurate depth when necessary + // Compute accurate depth when necessary float c_d = (rho3d <= rho2d) ? (s.x * Tw.x + s.y * Tw.y) + Tw.z : Tw.z; if (c_d < NEAR_PLANE) continue; @@ -348,7 +354,9 @@ renderCUDA( dL_dz += dL_dmedian_depth; dL_dweight += dL_dmax_dweight; } -#if DETACH_WEIGHT +#if DETACH_WEIGHT + // if not detached weight, sometimes + // it will bia toward creating extragated 2D Gaussians near front dL_dweight += 0; #else dL_dweight += (final_D2 + m_d * m_d * final_A - 2 * m_d * final_D) * dL_dreg; diff --git a/cuda_rasterizer/forward.cu b/cuda_rasterizer/forward.cu index 331f2c3..81cebb2 100644 --- a/cuda_rasterizer/forward.cu +++ b/cuda_rasterizer/forward.cu @@ -102,8 +102,8 @@ __device__ bool computeTransMat(const glm::vec3 &p_world, const glm::vec4 &quat, #endif #if RENDER_AXUTILITY and DUAL_VISIABLE -// This means a 2D Gaussian is dual visiable. -// Experimentally, turning off the dual visiable works eqully. + // This means a 2D Gaussian is dual visiable. + // Experimentally, turning off the dual visiable works eqully. float multiplier = cos > 0 ? 1 : -1; tn *= multiplier; #endif @@ -208,7 +208,7 @@ __global__ void preprocessCUDA(int P, int D, int M, float4 intrins = {focal_x, focal_y, float(W)/2.0, float(H)/2.0}; glm::vec2 scale = scales[idx]; glm::vec4 quat = rotations[idx]; - // view frustum cullling TODO + const float* transMat; bool ok; float3 normal; @@ -361,18 +361,24 @@ renderCUDA( float3 Tw = collected_Tw[j]; float3 k = {-Tu.x + pixf.x * Tw.x, -Tu.y + pixf.x * Tw.y, -Tu.z + pixf.x * Tw.z}; float3 l = {-Tv.x + pixf.y * Tw.x, -Tv.y + pixf.y * Tw.y, -Tv.z + pixf.y * Tw.z}; - // Then, cross product and norm to get the intersection, See Eq. (10) + // cross product of two planes is a line (i.e., homogeneous point), See Eq. (10) float3 p = crossProduct(k, l); #if BACKFACE_CULL + // May hanle this by replacing a low pass filter, + // but this case is extremely rare. if (p.z == 0.0) continue; // there is not intersection #endif + // 3d homogeneous point to 2d point on the splat float2 s = {p.x / p.z, p.y / p.z}; - float rho3d = (s.x * s.x + s.y * s.y); // splat distance + // 3d distance. Compute Mahalanobis distance in the canonical splat' space + float rho3d = (s.x * s.x + s.y * s.y); - // add low pass filter according to Botsch et al. [2005], Eq. (11). + // Add low pass filter according to Botsch et al. [2005], + // see Eq. (11) from 2DGS paper. float2 xy = collected_xy[j]; float2 d = {xy.x - pixf.x, xy.y - pixf.y}; - float rho2d = FilterInvSquare * (d.x * d.x + d.y * d.y); // screen distance + // 2d screen distance + float rho2d = FilterInvSquare * (d.x * d.x + d.y * d.y); float rho = min(rho3d, rho2d); float depth = (rho3d <= rho2d) ? (s.x * Tw.x + s.y * Tw.y) + Tw.z : Tw.z; // splat depth