Skip to content

Latest commit

 

History

11 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A CGA Approach to Raytracing

Abstract

The five dimensional framework of Conformal Geometric Algebra (CGA), described by [1], lends itself as particularly convenient to work with three dimensional euclidean geometry. The geometric primitives, amongst them, lines, planes, and spheres that arise in the conformal representation are of particular interest in computer graphics, where these may be used in the modeling of more complex objects and whole scenes. A key step towards this is the introduction of parameterized objects, made up of CGA primitives. We will show how such descriptions of surfaces can be ray-traced, by analyzing their intersections with lines, representing light rays. The resulting equations are of polynomial type, making their roots easy to compute. Since this form of modeling objects also allows differentiation, we have direct access to the surface normals and tangents at every point. This enables the use of a Blinn-Phong lighting model, in order to shade scenes in natural lighting. In the end, these techniques are demonstrated by implementing them in the rendering of a final image.

Final render Final rendering of a scene, using the Blinn-Phong model described before, illustrating the lighting of a sphere by a light source behind the camera. The brighter part of the sphere shows diffuse reflection of light, producing the uniform gray glow. This is also seen in the in Fig. 1 (top image). Additionally, there is a sharp, specular reflection of the light source visible (Fig. 1, center) . After hitting the sphere, the light rays were traced further until they intersect with the floor, creating the intricate reflection of the chequerboard pattern. Depth attenuation is visible as a black fog, making the background disappear. Lastly, the shadow attenuation produces the sphere's shadow on the ground surface.

Parameterized Surfaces via CGA Primitives

We first introduce parameterized surfaces that are generated by CGA primitives. Naively, this may be accomplished by linearly interpolating between two circles $C_1$ and $C_2$ for example, using the parameter $\alpha \in [0,1]$. Both circles are normalized, so $C_1^2 = C_2^2 = 1$.

$$ C_\alpha' = \alpha C_1 + (1-\alpha) C_2 $$

Unfortunately, given $\alpha$, the interpolated object $C_\alpha'$ is generally not a blade, therefore it does not immediately have an interpretation as a geometric primitive in Euclidean space. This means, that the inbetween objects $C_\alpha'$ are not valid circles.

Fortunately, we are still able to recover a blade $C_\alpha$ by use of a projector $\mathcal S$ \cite[pp. 2]{hadint}, such that

$$ C_\alpha = \mathcal{S} C_\alpha'. $$

In $\mathrm{Cl}(4,1)$ such an element contains only scalar and 4-vector parts, therefore $\mathcal{S}$ and $\mathcal{S}^-$ can be defined by taking

$$ \mathcal{S} = \langle \mathcal{S} \rangle_0 + \langle \mathcal{S} \rangle_4 $$

$$ \mathcal{S}^- = \langle \mathcal{S} \rangle_0 - \langle \mathcal{S} \rangle_4 $$

such that

$$ \mathcal{S}^- \mathcal{S} = \frac{1}{k}, $$

where $k$ is a scalar quantity. Therefore $k \mathcal{S}^-$ can be seen as the inverse of the projector and we have

$$ C_\alpha' = k \mathcal{S}^- C_\alpha, $$

which means that we may take

$$ C_\alpha'\tilde{C}_\alpha' = (k\mathcal{S}^- C_\alpha)\widetilde{(k\mathcal{S}^- C_\alpha)} = -k^2(\mathcal{S}^-)^2. $$

In order to extract the projector, we need an expression for the principal square root of a scalar + 4-vector quantity $\Sigma = \Sigma_0 + \Sigma_4$, the indices indicating the grades.

We define

$$ \left[ \left[ \Sigma \right] \right] = \sqrt{\Sigma_0^2 - \Sigma_4^2}, $$

this is possible since both grades square to give a scalar. Next, taking the square of $\Sigma$ itself we get

$$ \Sigma^2 = 2 \Sigma_0 \Sigma_4 + (\Sigma_0^2 + \Sigma_4^2) $$

$$ = 2 (\Sigma_0^2 + \Sigma_0 \Sigma_4) - (\Sigma_0^2 - \Sigma_4^2) $$

$$ = 2 \Sigma_0 \Sigma - \left[ \left[ \Sigma \right] \right]^2. $$

The square of $\Sigma$ is a linear combination of $1$ and $\Sigma$. So, we also have that $\Sigma$ is a linear combination of $\sqrt{\Sigma}$ and $1$. By inverting this result, $\sqrt{\Sigma}$ is a linear combination of $\Sigma$ and $1$ \cite[pp. 83]{hild}. Therefore, write

$$ \sqrt{\Sigma} = \mu + \nu \Sigma, $$

where $\mu$ and $\nu$ are two scalars, we have

$$ \Sigma = \mu^2 + 2 \mu \nu \Sigma + \nu^2 \Sigma^2. $$

Rewrite using the previous expression to eliminate the $\Sigma^2$ part, this yields

$$ 0 = (\mu^2 - \nu^2 \left[ \left[ \Sigma \right] \right]^2)

  • (2 \Sigma_0 \nu^2 + 2 \mu \nu - 1)\Sigma. $$

Since both expressions in parenthesis are equal to zero we can solve for $\mu$ and $\nu$:

$$ \mu = \pm \nu \left[ \left[ \Sigma \right]\right] $$

$$ \nu = \frac{1}{\sqrt{2} \sqrt{\Sigma_0 \pm \left[ \left[ \Sigma \right] \right]}} $$

In the end, for a scalar + 4-vector $\Sigma$, we have constructed its principal square root by plugging in for $\mu$ and $\nu$ \cite[p. 86]{hild}

$$ \sqrt{ \Sigma } = \frac{\Sigma \pm \left[\left[ \Sigma \right] \right]} {\sqrt{2} \sqrt{ \Sigma_0 \pm \left[\left[ \Sigma \right]\right] }}. $$

Parameterized surface generated by evolving circles with different types of interpolation. (From left) linear, quadratic, cubic, which refers to the degree in $\alpha$ of the interpolation $C_\alpha'$. \cite[Fig. 8]{had}

Parameterized surface generated by evolving circles with different types of interpolation. (From left) linear, quadratic, cubic, which refers to the degree in $\alpha$ of the interpolation $C_\alpha'$. [2]

Its existence depends on the existence of a real solution to $\sqrt{ \Sigma_0 \pm \left[\left[ \Sigma \right]\right] }$. It turns out, that the $+$ solution is always defined and it will be chosen in the subsequent sections about ray-tracing.

Using the principal square root, we then get \cite[p. 4]{hadint} \cite[p. 10]{had}

$$ k\mathcal{S}^- = \sqrt{-C_\alpha'\tilde{C}_\alpha'} $$

$$ \mathcal{S} = \frac{1}{\sqrt{-C_\alpha'\tilde{C}_\alpha'}}. $$

Thus, the inbetween blades can be constructed as

$$ C_\alpha = \mathcal{S} (\alpha C_1 + (1-\alpha) C_2). $$

Note, that this is formally not a linear interpolation, since $\mathcal{S}$ depends on $\alpha$. In the figure above the resulting objects are shown, higher order interpolations yielding subsequently smoother surfaces. The projector $\mathcal{S}$ can be reused for these higher order interpolations as well.

References

[1] J. Lasenby, A. Lasenby, and R. Wareham, “A covariant approach to geometry using geometric algebra,” Tech. Rep. CUED/F-INFENG/TR-483, 2004.

[2] H. Hadfield and J. Lasenby, “Direct linear interpolation of geometric objects in conformal geometric algebra,” Advances in Applied Clifford Algebras, vol. 29, Aug. 2019. doi: 10.1007/s00006-019-1003-y.

[3] D. Hildenbrand, Foundations of Geometric Algebra Computing. Berlin Heidelberg: Springer Science & Business Media, 2012, isbn: 978-3-642-31794-1.

[4] H. Hadfield, S. Achawal, J. Lasenby, A. Lasenby, and B. Young, “Exploring novel surface representations via an experimental ray-tracer in cga,” Advances in Applied Clifford Algebras, vol. 31, Apr. 2021. doi: 10.1007/s00006-021-01117-8.

About

Recreating some ray-traced scenes using CGA methods from Hadfield et al.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages