Skip to content

Commit

Permalink
finalize the code
Browse files Browse the repository at this point in the history
  • Loading branch information
hbb1 committed May 6, 2024
1 parent 02d6f89 commit 661d224
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 21 deletions.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@ This is the rasterization engine for the paper "2D Gaussian Splatting for Geome
<section class="section" id="BibTeX">
<div class="container is-max-desktop content">
<h2 class="title">BibTeX</h2>
<pre><code>@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}
<pre><code>@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}
}</code></pre>
</div>
</section>


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.

<section class="section" id="BibTeX">
<div class="container is-max-desktop content">
<h2 class="title">BibTeX</h2>
Expand Down
2 changes: 1 addition & 1 deletion cuda_rasterizer/auxiliary.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 13 additions & 5 deletions cuda_rasterizer/backward.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
20 changes: 13 additions & 7 deletions cuda_rasterizer/forward.cu
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 661d224

Please sign in to comment.