Real-Time Shading with Polyhedral Lights using Silhouette Detection

In my bachelor thesis, I explored using the silhouettes of polyhedral light sources for real-time shading. Below is a summary of the thesis as well as download links for the full thesis and for my implementation of the presented techniques in the Unity Engine. The implementation is available as source code and licensed under the MIT license. I wrote the thesis at the Institut für Visualisierung und Datenanalyse of the KIT with help from my advisor Christoph Peters. It was submitted on March 23, 2021.

Motivation

Most geometry in real-time rendering is represented by polyhedral models because they approximate nearly all real and fictional objects well and because good tools and techniques have been developed to create, capture and render them. An exception to this are light sources, which are commonly represented either by single points, simple primitives, or flat polygons. While a polyhedral light source could be built from one polygonal light source for each face, that approach is relatively expensive due to the large number of either edges or triangles (depending on the shading algorithm) that need to be taken into account. Another way to replace a polyhedron by a polygon is to use its silhouette as seen from the shading point. This results in simpler geometry but yields the same shading result for untextured light sources. To actually reduce the shading time with this approach, a fast algorithm for determining the silhouette is needed.

Techniques for Shading with Polygonal Lights

Shading with area lights mainly consists of calculating an integral over the solid angle of the light source. Monte Carlo integration and Linearly Transformed Cosines (LTCs) are two commonly used methods for approximating this integral. Monte Carlo integration replaces the integral with a finite sum over random samples on the light source. The result has the correct expected value but contains some variance, visible as noise in the final image. Lower variance is achieved either by using more samples or a better sampling strategy. Various sampling strategies exist for spherical triangles. To apply them to polygonal light sources, the polygon must be triangulated. LTCs are a class of functions for which analytic integration over a spherical polygon is cheap. To use them for polygonal lights, the integrand of the shading integral is approximated by an LTC. The integral is then calculated as a sum over a relatively simple expression for each edge of the polygon.

Silhouettes of Polyhedra

The silhouette of a convex polyhedron is the same as its contour, which is the set of all edges where one adjacent face is front-facing and the other back-facing. For non-convex ones, the silhouette consists of segments of the contour edges. These segments start and end where they appear to intersect other contour edges when viewed from the shading point. To determine the silhouette, I therefore split the contour edges at these apparent intersections and then filter out the unwanted segments. A segment is not part of the silhouette if it is either occluded by a face of the polyhedron or if a face is directly behind it. I test this by tracing a ray through the midpoint of each segment.

Precalculating Silhouettes

The methods described above are expensive for real-time shading, especially the one for non-convex polyhedra. I therefore precalculate the structure of the silhouette for each shading point and store them in a binary space partitioning tree. This is possible because relevant changes to the silhouette only occur at a finite and for simple polyhedra sufficiently small set of planes. This is easy to see for convex polyhedra: whether an edge is a contour edge only depends on which side of the adjacent faces the shading point is on. Therefore, if the scene is divided into cells using these planes, each cell has the same set of silhouette edges. For non-convex polyhedra, I add additional planes that capture where contour edges start and stop intersecting. At shading time, I traverse the tree, fetch the precalculated silhouette and calculate the exact vertex positions for the shading point. The silhouette polygon can be used directly for shading with LTCs if the light source is unoccluded. Monte Carlo integration with ray tracing is needed to calculate soft shadows for partially occluded light sources.

Triangulation for Monte Carlo Integration

As mentioned before, solid angle sampling techniques commonly require triangles while the methods described so far yield a set of edges. For convex polyhedra this isn't a problem since the silhouette is convex as well and is therefore easily triangulated with a triangle fan. This is possible for non-convex polyhedra as well if they are star-shaped. A star-shaped set is one that contains a point from which the entire set is visible. In that case, I simply build the triangle fan around that central point. For non-star-shaped polyhedra, triangulation is a lot more difficult. I therefore calculate the triangulation in the preprocessing phase and store a set of triangles instead of edges for each cell. In some cases however, a triangulation is not valid for its entire cell. For lack of a better solution, I test a triangulation for a large number of samples in the cell and try a different one if the triangulation fails. The triangulation fails if a triangle is back-facing when viewed from the shading point.

Results

Using silhouettes instead of one polygon per face reduces shading times in all test cases, usually significantly. Preprocessing times and the size of the precomputed data are acceptable for simple polyhedra but increase rapidly with increasing complexity. The technique can therefore not be used efficiently for all polyhedra but it still enables the efficient use of a wide variety of polyhedral light sources in real-time applications.

Comparison to Fast Analytic Soft Shadows from Area Lights

The techniques presented here were developed concurrently with and independent of the paper Fast Analytic Soft Shadows from Area Lights by Aakash et al., which contains similar ideas. Just like I do, the authors use the silhouettes of polyhedral light sources to accelerate shading. They also developed a way of computing analytic soft shadows with LTCs, while my techniques only enable stochastic shadows with raytracing. However, my algorithm for finding silhouettes is faster because it runs on the GPU and because of its preprocessing phase. Also, it can handle non-convex light sources directly while theirs currently requires building them from multiple convex ones and performing shadowing calculations to deal with self-occlusion.

Links

Thesis (PDF)
Unity Project (ZIP)
Unity Project (GitHub)