Cube-To-Sphere Projections For Procedural Texturing and Beyond
Cube-To-Sphere Projections For Procedural Texturing and Beyond
org
(a) (b)
(c) (d)
Figure 1. Real-time shader illustrating stratified sampling of the sphere. (a) jittered uniform
grid on cube; (b) nonlinear warp of each face; (c) projection to sphere via normalization;
(d) resulting Voronoi diagram, generated in constant time per fragment.
Abstract
Motivated by efficient GPU procedural texturing of the sphere, we describe several approxi-
mately equal-area cube-to-sphere projections. The projections not only provide low-distortion
UV mapping, but also enable efficient generation of jittered point sets with O(1) nearest-
neighbor lookup. We provide GLSL implementations of the projections with several real-time
procedural texturing examples. Our numerical results summarize the various methods’ abil-
ity to preserve projected areas as well as their performance on both integrated and discrete
GPUs. More broadly, the overall cube-to-sphere approach provides an underexplored avenue
for adopting existing 2D grid-based methods to the sphere. As an example, we showcase fast
Poisson disk sampling.
1 ISSN 2331-7418
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
1. Introduction
Spheres are ubiquitous primitives in computer graphics, used to render everything
from molecules to planets. Sampling and tessellating the sphere is fundamental to
texturing and modeling these common objects. Most users of modern graphics APIs
are familiar with cube mapping [Greene 1986], a technique that is commonly used to
map between 3D direction vectors and 2D textures tiling the surface of a cube. In this
paper, we present a family of invertible mappings that can be considered as a general-
ization of cube mapping. When constructed to preserve relative area, these mappings
are useful for sampling the sphere and have applications to procedural texturing and
modeling.
2
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
parameters for previously published projections that had been chosen ad hoc and to
increase the visibility of the overall cube-to-sphere approach. We also introduce a
new method: the 1D odd-polynomial projection.
(ii) Jittered point sets – the implementation must be able to generate visually non-
uniform samples, with neither dense clumps nor large empty regions. This
can be accomplished via stratified sampling (a.k.a. jittered grids) in which the
domain is partitioned into regular subdomains of equal area which are then
sampled uniformly.
3
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
(iii) Efficient nearest sample search – the implementation must be able to quickly
determine the closest k sample points to any arbitrary point in the domain, irre-
spective of the total number of sample points.
Of these, value noise requires (i) and (iii), and the other primitives require (ii) and (iii).
Figure 2. Real-time fragment shader generating value noise on both a uniform (left) and
jittered (right) grid with m = 16 points per cube face edge.
Figure 3. Real-time fragment shader comparing two types of Voronoi cells. Left side: Points
taken from a jittered 3D grid. Note apparent curvature of cell borders as well as high variation
in region sizes on the sphere. Right side: Points from jittered 2D grid on the sphered cube.
3D grid based on MIT-licensed code © Íñigo Quı́lez [2013].
4
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
(a) (b)
(c) (d)
Figure 4. Voronoi diagrams of randomized point sets, colored by originating cube face.
From top left: (a)–(c) Varying m = 8, 16, and 32 points per cube edge, mapped through
tangent warp (Section 3.2); (d) Same as (c), but using the identity warp (Section 3.1). Using
this non-equal-area projection, Voronoi regions shrink near cube edges and grow near face
centers.
Our sphered-cube approach uses the same grid-traversal code (Listing 3) everywhere
and the resulting value noise appears visually homogeneous, as shown in Figure 2.
In further contrast to spherical Fibonacci mapping, we can straightforwardly create
jittered grids, allowing us to implement cellular texturing and Voronoise as well.
One popular approach for texturing the surface of an arbitrary solid object with
cellular noise is to generate a jittered grid on a 3D lattice and compute distances from
each point on the surface to the k-nearest 3D sample points. However, as shown in
Figure 3, this approach has two main drawbacks, especially when used to texture
spheres. Although the Voronoi boundaries of a 3D jittered grid are piecewise planar,
their intersections with the sphere do not follow geodesics along its surface, inducing
undesirable extraneous curvature with respect to the local tangent frame. Further-
more, the intersections of the 3D Voronoi cells with the sphere exhibit substantial
size variation as the corresponding sample points vary in distance to the sphere’s sur-
face. Using the sphered cube mitigates both of these effects, and the underlying cube
structure is invisible as long as the cube-to-sphere projection is approximately area-
preserving (see Figure 4 for an example of the converse).
5
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
Figure 5. Example scenes. Left: Planetoid with height-mapped cellular noise among a jit-
tered grid of stars on a skydome. Right: Simulating brittle fracture along Voronoi boundaries.
In summary, spherical Fibonacci mapping satisfies requirements (i) and (iii) but
not (ii). The popular 3D-to-2D approach for cellular texturing satisfies (ii) to some
extent, but suffers visually. In contrast, the sphered-cube approach we describe in
the following sections satisfies all three requirements. Furthermore, the underlying
techniques provide a low-distortion UV mapping which is also useful for traditional
(i.e., non-procedural) texture mapping.
We conclude this section with two demonstrations of the utility of the sphered-
cube approach in procedural texturing and modeling. The left-hand scene in Figure 5
is rendered using real-time ray marching (a.k.a. sphere tracing), and the right-hand
scene is rendered using real-time ray tracing. Both scenes are rendered at interactive
rates by pure fragment shaders drawing a single full-screen quad. The GLSL source
for both shaders can be found in the supplemental materials.
6
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
Figure 6. Illustration of the approaches described in Sections 3.1 to 3.6. The top row shows
the warped grid for each method; the bottom shows projected area error (E A in Equation (8)).
Areas shaded in red are enlarged by projection onto the sphere, blue areas are reduced. *As-
terisks above indicate that the maximum area error exceeds the color-map limits.
coordinates within the cube face as a vector (a, b) ∈ [−1, 1] × [−1, 1] such that
a
~p = P b .
(1)
1
Given an original pair of cube-face coordinates (a, b), each approach we describe
below computes a new set of coordinates (u, v) with u = fu (a, b) and v = fv (a, b).
The warp functions fu , fv : R2 7→ R distort 2D grid points on a cube face prior to
normalization onto the sphere, as shown in the top row of Figure 6. Although each
cube face undergoes distortion, no point ever moves to a new cube face. Hence, we
can reuse P to represent the warped location ~q of point ~p:
u fu (a, b)
~q = P v = P fv (a, b) .
(2)
1 1
Finally, regardless of which pair of warp functions is used, the unit vector ω̂ on the
sphere is obtained by simply normalizing ~q:
~q
ω̂ = . (3)
k ~q k
The projections all have some properties in common. Each method exhibits hor-
izontal and vertical symmetry with fu (−a, b) = − fu (a, b) and fv (a, −b) = − fv (a, b);
7
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
therefore, fu (0, b) = fv (a, 0) = 0 and so the center of the cube face is not displaced.
Furthermore, the edges of the cube face are not displaced, so fu (1, b) = fv (a, 1) = 1.
However, the approaches differ in several key qualitative aspects. Each one may be:
• diagonally symmetric with fu (a, b) = fv (b, a); i.e., the warp treats the parame-
ters a and b interchangeably. All univariate warps are diagonally symmetric;
Aside from these key categorical distinctions, the most important quantitative differ-
ence between the approaches described here is the degree to which they are area-
preserving; that is, a region covering a given percentage of the unit cube covers the
same percentage of the unit sphere after transformation.
Here we follow Arvo’s [2001] recipe for deriving the area element of the transfor-
mation defined by the composition of Equations (1) to (3). According to the method
he provides, the area element is given by
s
!2
∂ω̂ ∂ω̂ ∂ω̂ ∂ω̂ ∂ω̂ ∂ω̂
! !
dA(a, b) = · · − · , (4)
∂a ∂a ∂b ∂b ∂a ∂b
where ∂∂aω̂ and ∂∂bω̂ are the partial derivatives of the unit vector ω̂ with respect to the
input cube face coordinates a and b. They are defined as
−uv ∂ fv + v2 ∂ fu + ∂ fu
∂a ∂a ∂a
∂ω̂ 1
2 ∂ fv ∂ fu ∂ fv
= 3 u ∂a − uv ∂a + ∂a , (5)
∂a u2 + v2 + 1 2
−u ∂∂afu − v ∂∂afv
8
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
Figure 7. Motivation for tangent-based warp. Left: Equal-length subdivisions of the square
result in unequal subdivisions of the circumscribed circle; Right: warping square coordinates
through the tangent function guarantees uniform subdivisions of the circle.
9
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
the tangent mapping, our implementation introduces and optimizes a free parameter
to better preserve area.
The free parameter is implicitly fixed at π4 by both of the works we just cited,
and this value is indeed optimal for equalizing angles in the 2D motivating example.
However, in 3D it is possible to preserve area more effectively by using the warp
tan(a θ)
u = f (a) = (9)
tan(θ)
for some angle θ > 0. The inverse of the tangent warp is given by
1
a = f −1 (u) = tan−1 u tan(θ) .
(10)
θ
The inspiration for our design of this method is that trigonometric functions, par-
ticularly inverse functions, can be expensive to evaluate and are hence frequently
replaced by polynomial approximations. In this case, instead of optimizing polyno-
mial coefficients to approximate tan(x) as closely as possible, we directly optimize
the coefficients to minimize Equation (8). Indeed, the polynomials obtained through
optimization visually resemble the tangent function. However, unlike the tangent and
Everitt approaches, they are not analytically invertible for n > 2.
10
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
By construction, Equation (16) satisfies the requirements that fu (−a, b) = − fu (a, b),
and fu (1, b) = 1. Owing to diagonal symmetry, the second cube coordinate is defined
by fv (a, b) = fu (b, a). Their model is often called the COBE quadrilateralized spher-
ical cube model, as it was developed in support of the NASA Cosmic Background
Explorer (COBE) project.
Figure 8. Using Arvo’s method to map the entire cube to a sphere results in discontinuities
along cube edges, as evidenced by the T -vertices shown here.
11
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
and setting u = x/z and v = y/z (i.e., dividing by the value of the maximal coordinate).
What remains is to invert the mapping function: given u = fu (a, b) and v = fv (a, b),
solve for a and b. The inverses of the tangent warp and Everitt’s warp are given in
Sections 3.2 and 3.3. However, the odd 1D polynomial method (Section 3.4) and the
COBE method (Section 3.5) must be inverted numerically.
over a linearly spaced set of samples ai ∈ [0, 1]. For the bivariate polynomial, we
choose the coefficients of f˜−1 : R2 7→ R to minimize
12
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
Although the initial inverse estimate may exhibit significant approximation error,
numerical root-finding techniques can virtually eliminate the approximation error in
just a few iterations. We use the secant method and its multidimensional general-
ization, Broyden’s method [Press et al. 1992], to refine the univariate and bivariate
inverses, respectively. Their GLSL implementations may be found in Listing 1 and
Listing 2. See Table 1 for a summary of the accuracy of these numerical inverses.
Listing 1. Vectorized secant method for inverting univariate mapping, implemented in GLSL.
13
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
1. Unproject ω̂ to get the permutation matrix P, and use the inverse mapping to
get the unwarped face coordinates (a, b).
3. When ranking sample points, use distance on the sphere to ω̂ (as opposed to
distance on the flat cube faces). It is sufficient to choose the sample point that
has the maximum dot product with the 3D vector ω̂.
The single closest sample point always lies within a 2×2 neighborhood centered on
the cell corner closest to ω̂. However, to correctly identify the second-closest sample,
it is necessary to search a 4×4 neighborhood instead. In general, a larger k implies
larger neighborhoods. Since it does not depend on the grid size m, but only on the
neighborhood size s, the algorithm outlined above runs in constant time with respect
to the total number of sample points.
Aside from using the correct metric to rank points—distance on the sphere, as
opposed to the cube—when adopting grid-based methods using the cube-to-sphere
approach, it is vital to respect edge-wrapping effects while iterating over neighbor-
hoods. For example, a 3×3 neighborhood is the set of grid cells on the cube that can
be accessed by moving up one step in the horizontal and vertical directions from the
center cell. Although in the 2D planar domain this always results in a neighborhood
size of nine cells, there may be fewer on the cube, as shown in Figure 9.
We address this issue with an algorithm (Listing 3) that handles edge wrapping
and rejects steps (e.g., offsets to neighboring cells) that would cross more than one
cube edge. With respect to the central point at (0.75, 0.75, 1) in Figure 9, the algo-
rithm permits a step of (+0.5, 0, 0), causing a wrap across to the positive-x face of the
cube, or a step of (0, +0.5, 0) that wraps across to the positive-y face. However, the
z −0.25
−0.75
0.25
0.75
0.75
0.25
y
−0.25
−0.75
−0.75
−0.25
0.25
x 0.75
Figure 9. On the cube, considering all cells within ±1 horizontal or vertical steps of a central
cell may result in fewer neighbors than would be found on a 2D planar grid.
14
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
algorithm rejects a step of (+0.5, +0.5, 0), as it would cross more than one cube edge.
The total number of permitted steps therefore corresponds to the actual neighborhood
size on the cube.
15
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
Table 1. Summary of numerical results for projected area error and inverse approximations.
Area RMSE is the optimization objective (Equation (8)) and area max error is the worst-case
observed value for E A in that equation. Inverse errors refer to the worst-case observed value
for the initial inverse guess and subsequent refinement by an iterative solver. Dashes indicate
the method has an analytic inverse.
Figure 10. Timing data from Table 2 normalized to show trends across two different GPUs.
Error bars indicate ±1 standard deviation.
16
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
Table 3. Optimal free parameters for the mappings defined in Sections 3.2 to 3.5 along with
their approximate inverses (Section 4.1). Dashes indicate the method has an analytic inverse.
17
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
Figure 11. Comparing radially averaged power spectrum and anisotropy for ∼300 points
using brute force dart throwing, Wei’s [2008] multiresolution algorithm adapted to the sphere
with our 5th-order polynomial cube-to-sphere mapping, and 2D dart throwing lifted to the
sphere by Lambert cylindrical equal-area mapping.
Instead, we propose to use the structure of the sphered cube to aid with direct
Poisson disk sampling on the sphere. As an example, we adapt Wei’s [2008] mul-
tiresolution algorithm to the sphere using the 5th-order polynomial mapping. Wei
uses a grid structure on the unit square to make Poisson disk sampling GPU-friendly,
and demonstrates that the resulting point sets still exhibit excellent blue noise quali-
ties. By changing the underlying spatial structure from a 2D grid to a sphered cube
and using the methods of Section 4 for conflict checking, we are able to achieve high
quality Poisson disk sampling on the sphere that is parallelizable on the GPU.
We examine the quality of various Poisson disk point sets on the sphere by com-
puting the relative radius, radial mean power spectrum, and anisotropy [Lagae and
Dutré 2007]. Figure 11 compares Wei’s algorithm combined with cube-to-sphere
mapping with brute force dart throwing directly on the sphere and brute force dart
throwing on the unit torus (i.e., unit square with periodic boundaries) lifted to the
sphere by Lambert cylindrical equal-area mapping. Due to singularities at the poles,
the latter point set exhibits poor blue noise characteristics and high anisotropy at low
frequencies. The relative radius is around 0.2 to 0.4, well below the range [0.65, 0.85]
suggested by Lagae and Dutré. In contrast, our adaptation of Wei’s algorithm gener-
ates point sets with very similar spectral properties to brute force dart throwing. The
relative radius is consistently around 0.75, within the suggested range of [0.65, 0.85].
Far less distortion is introduced because sampling and conflict checking are performed
18
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
Closest pair
Rel. sizes
Largest empty cap
Figure 12. Comparing one example spherical point set per sampling method. Each is rotated
to highlight both the closest point pair as well as the largest empty spherical cap.
directly on the sphere, yielding nearly identical quality to Wei’s original results on the
plane. Figure 12 shows example point sets from all three methods, illustrating that
the cylindrical equal-area mapping yields far less regular distributions than the other
two methods.
7. Conclusion
We have shown how cube-to-sphere mappings can aid in GPU procedural modeling
and texturing of the sphere. In particular, we have detailed several pre-existing pro-
jections and one novel one. We have also shown how to efficiently implement fast
nearest-neighbor query for jittered grids on the sphere using this approach. Finally,
we demonstrated how to use these mappings to adapt general 2D grid-based methods
to the sphere, showcasing Poisson disk sampling as an example. This is a promising
application area for the sphered-cube approach based on the popularity of 2D grid-
based methods, and because algorithms for sampling the plane are typically much
simpler and faster than algorithms for sampling arbitrary meshes or manifolds.
References
Arvo, J. 1995. Stratified sampling of spherical triangles. In Proceedings of the 22nd
Annual Conference on Computer Graphics and Interactive Techniques, ACM, New
19
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
20
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
Keinert, B., Innmann, M., Sänger, M., and Stamminger, M. 2015. Spherical Fibonacci
mapping. ACM Transactions on Graphics (TOG) 34, 6, 193:1–193:7. URL: https://dl.
acm.org/citation.cfm?id=2818131. 2, 4
Lagae, A., and Dutré, P. 2007. A comparison of methods for generating Poisson disk dis-
tributions. Computer Graphics Forum 27, 1, 114–129. URL: https://onlinelibrary.
wiley.com/doi/full/10.1111/j.1467-8659.2007.01100.x. 18
Lambers, M. 2016. Mappings between sphere, disc, and square. Journal of Computer Graph-
ics Techniques Vol 5, 2, 1–21. URL: http://jcgt.org/published/0005/02/01/. 2
Marques, R., Bouville, C., Ribardière, M., Santos, L. P., and Bouatouch, K. 2013. Spherical
Fibonacci point sets for illumination integrals. Computer Graphics Forum 32, 8, 134–143.
URL: https://onlinelibrary.wiley.com/doi/pdf/10.1111/cgf.12190. 17
Meyer, Q., Smuth, J., Suner, G., Stamminger, M., and Greiner, G. 2010. On floating-
point normal vectors. Computer Graphics Forum 29, 4, 1405–1409. URL: https://
onlinelibrary.wiley.com/doi/full/10.1111/j.1467-8659.2010.01737.x. 2
Press, W. H., Teukolsky, S. A., Vetterling, W. T., and Flannery, B. P. 1992. Numerical
recipes in C. Cambridge University Press. URL: http://apps.nrbook.com/c/index.
html. 13
Quı́lez, Í., 2013. Shadertoy: Voronoi - 3D. URL: https://www.shadertoy.com/view/
ldl3Dl. 4
Quı́lez, Í., 2015. Voronoise. URL: http://www.iquilezles.org/www/articles/
voronoise/voronoise.htm. 3
Shao, M.-Z., and Badler, N. 1996. Spherical sampling by Archimedes’ theorem. Tech.
Rep. MS-CIS-96-02, University of Pennsylvania Department of Computer and Information
Science. URL: https://repository.upenn.edu/cgi/viewcontent.cgi?article=
1188&context=cis_reports. 2
Singh, G. 2015. Sampling and variance analysis for Monte Carlo integration in spherical
domain. PhD thesis, Université Claude Bernard-Lyon I. URL: https://hal.archives-
ouvertes.fr/tel-01217082/document. 2
Wei, L.-Y. 2008. Parallel Poisson disk sampling. ACM Transactions on Graphics (TOG) 27,
3, 20:1–20:9. URL: https://dl.acm.org/citation.cfm?id=1360619. 17, 18
Wong, T.-T., Luk, W.-S., and Heng, P.-A. 1997. Sampling with Hammersley and Halton
points. Journal of Graphics Tools 2, 2, 9–24. URL: http://www.tandfonline.com/
doi/abs/10.1080/10867651.1997.10487471. 2
Worley, S. 1996. A cellular texture basis function. In Proceedings of the 23rd annual confer-
ence on computer graphics and interactive techniques, ACM, New York, SIGGRAPH ’96,
ACM SIGGRAPH, 291–294. URL: https://dl.acm.org/citation.cfm?id=237267.
3
21
Journal of Computer Graphics Techniques Vol. 7, No. 2, 2018
Cube-to-sphere Projections for Procedural Texturing and Beyond http://jcgt.org
M. Zucker and Y. Higashi, Cube-to-sphere Projections for Procedural Texturing and Beyond,
Journal of Computer Graphics Techniques (JCGT), vol. 7, no. 2, 1–22, 2018
http://jcgt.org/published/0007/02/01/
Received: 2018-04-04
Recommended: 2018-05-15 Corresponding Editor: Stephen Hill
Published: 2018-06-26 Editor-in-Chief: Marc Olano
22