DiffCSG: Differentiable CSG via Rasterization

Haocheng Yuan, Adrien Bousseau, Hao Pan, Quancheng Zhang, Niloy J. Mitra, Changjian Li

TL;DR

This paper introduces DiffCSG, a novel method for optimizing Constructive Solid Geometry (CSG) models by leveraging differentiable rasterization. By cleverly handling the discontinuities introduced by boolean operations, DiffCSG enables efficient, image-guided editing and inverse design of complex parametric shapes, overcoming limitations of previous approaches.

What Problem Does This Paper Address?

Constructive Solid Geometry (CSG) is a powerful way to represent 3D shapes using boolean operations (union, intersection, difference) on simpler primitives. While CSG models are highly editable and parametric, optimizing their continuous parameters (like position, scale, orientation) to match a target shape, especially from images, has been a significant challenge. Existing differentiable rendering techniques primarily work with meshes, and applying boolean operations to meshes is computationally expensive and difficult to differentiate. Alternatively, Signed Distance Fields (SDFs) can be used for differentiable CSG, but defining analytical SDFs for complex primitives and the computational cost of sphere tracing are major hurdles. This paper aims to bridge this gap by enabling differentiable optimization of CSG models directly, without explicit mesh boolean operations or complex SDF computations.

Methods

The core of DiffCSG lies in adapting a differentiable rasterization pipeline to handle CSG models. Instead of explicitly computing the resulting mesh from boolean operations, DiffCSG uses a technique called "CSG rasterization" (specifically, the Goldfeather algorithm) which determines visibility based on depth and parity tests. The key innovation is to make this process differentiable.

Here's how it works:

  • CSG Rasterization: The Goldfeather algorithm renders CSG shapes by checking which primitive faces are visible based on the boolean operations, without ever constructing a final mesh.
  • Differentiable Rasterization: The paper builds upon existing differentiable rasterizers (like Nvdiffrast) that can backpropagate image gradients to mesh vertices.
  • Handling Discontinuities: The main challenge is that CSG boolean operations create sharp discontinuities (edges) where primitives intersect. Standard differentiable rasterizers only antialias along the silhouette edges of the input mesh, missing these crucial CSG intersection edges.
  • Intersection Edge Detection: DiffCSG explicitly detects these intersection edges between primitive triangles.
  • Antialiasing Intersection Edges: These detected intersection edges are then fed into the antialiasing module of the differentiable rasterizer. This ensures that gradients can flow smoothly across these critical areas, all the way back to the primitive parameters.
  • Backpropagation to Parameters: Finally, gradients are backpropagated from mesh vertices to the continuous parameters of the CSG primitives (e.g., radius, translation, scale).

Datasets

The paper evaluates its method on a benchmark of 50 CSG models. They also use synthesized images (rendered colors, per-primitive colors, and interpolated vertex normals) as targets for optimization. No new datasets were introduced, but the benchmark is described as being composed of shapes with varying complexity and parameter dependencies.

Key Insights and Ideas

  • Intersection edges are critical for CSG gradients: The paper strongly emphasizes that the discontinuities formed by CSG boolean operations are precisely where the most informative gradients for optimization lie. Without properly handling these, optimization fails.
  • CSG rasterization is a viable differentiable primitive: By adapting the Goldfeather algorithm, the authors show that CSG rendering can be made differentiable without the overhead of mesh booleans or SDFs.
  • Parameterization matters: The way CSG parameters are abstracted (e.g., co-parameterizing related elements) significantly impacts the ease and success of optimization. A well-chosen parameterization can make optimization tractable where an independent one might fail.
  • Interior signals enrich optimization: While silhouette and intersection edges are crucial, using interpolated vertex normals as an interior signal can provide richer information, especially for smooth primitives, aiding convergence even when intersection edge gradients are imperfect.

Key Results

  • Efficiency: The majority (62%) of shapes in their benchmark were optimized within 10 seconds, with 29% taking under 100 seconds. This is significantly faster than SDF-based methods, which are orders of magnitude slower.
  • Effectiveness: DiffCSG successfully optimizes CSG models to match target images, demonstrating its ability to refine parameters and achieve accurate shape reconstruction.
  • Applications: The method is shown to be effective for both direct 3D editing (editing a mesh and finding corresponding CSG parameters) and image-based editing (using edited renderings as targets).
  • Comparison: DiffCSG outperforms SDF-based optimization (UCSG-Net) in terms of speed and convergence, and is more robust than derivative-free methods for complex shapes with unknown parameter scales.

Limitations and Future Work

  • Structure Optimization: DiffCSG currently only optimizes continuous parameters. Future work could explore changing the CSG program's structure (primitive types, boolean operations), potentially using reinforcement learning.
  • Initialization: Like many optimization methods, DiffCSG can get stuck in local minima. Using hypernetworks for better initializations is suggested.
  • Regularization: The paper notes the lack of explicit regularization. Future work could incorporate shape priors or latent space representations of CAD programs to guide optimization and prevent issues like vanishing primitives.
  • Failure Cases: The paper acknowledges two failure modes: primitives vanishing (due to parameters becoming zero) and target shapes being too distant from the source, requiring step-by-step optimization.

Summary updated

BibTeX
@inproceedings{yuan2024diffcsg,
  author = {Haocheng Yuan and Adrien Bousseau and Hao Pan and Quancheng Zhang and Niloy J. Mitra and Changjian Li},
  title = {{DiffCSG: Differentiable CSG via Rasterization}},
  booktitle = {SIGGRAPH Asia},
  year = {2024},
  url = {https://openreview.net/forum?id=VSoEjjJH4i},
}
Figure