scieee AI-readable full text Open interactive document viewer

A framework for real-time physically-based hair rendering

Gonzalez Jimenez, Santi

Abstract

Hair rendering has been a major challenge in computer graphics for several years due to the complex light interactions involved. Complexity mainly stems from two aspects: the number of hair strands, and the resulting complexity of their interaction with light. In general, theoretical approaches towards a realistic hair visualization aim to develop a proper scattering model on a per-strand level, which can be extended in practice to the whole hair volume with ray tracing even though it is usually expensive in computational terms. Aiming at achieving real-time hair rendering, I analyze each component contributing to it from both theoretical and practical points of view in this work. Most approaches, both real- and non-real-time build on top of the Marschner scattering model, such as recent efficient state-of-the-art techniques introduced in Unreal Engine and Frostbite, among others. Interactive applications cannot afford the complexity of ray tracing, and they target efficiency by explicitly dealing with each component involved in both single-strand and inter-strand light interactions, applying the necessary simplifications to match the time budget. I have further implemented a framework, separating the different components, which combines aspects of these approaches towards the best possible quality and performance. The implementation achieves real-time good-looking hair, and its flexibility has allowed to perform experiments on performance, scalability, and contribution to quality of the different components.

Full text

A Framework for Real-Time Physically-Based Hair Rendering UPC By Santi Gonzalez Jimenez Supervisors: Ricardo Jorge Rodrigues Sep´ ulveda Marques Jos´ e-Angel Blat Gimeno A thesis submitted for the degree of Master in Innovation and Research in Informatics Specialization in Computer Graphics and Virtual Reality Facultat d’Inform` atica de Barcelona Universitat Polit` ecnica de Catalunya Barcelona, June 2022 Acknowledgements I would like to thank the Grup de Tecnologies Interactives (GTI)1depart- ment from Universitat Pompeu Fabra (UPF) and each of its members for allowing me to develop this project as a collaboration with them, motivated by the European projects Present2and SignON3being carried on by the group. Specifically, I would like to thank my supervisors Dr. Ricardo Marques4and Prof. Josep Blat5for guiding me through this work and providing very useful feedback regularly. Also, I want to thank my colleagues from the Huawei IRC 3DE team for the support provided. Specifically, Thomas Poulet6for having the patience and expertise to solve many of the technical doubts I’ve had related to hair rendering, as well as providing helpful feedback during the project development, and Tobias Alexander Franke7for introducing me useful insights, initial ideas, and references around the topic. Finally, I want to thank everyone else involved in my academic and professional career, UPC lecturers, and class colleagues, as well as my family and friends. In this group falls, of course, my cat Lofi, who has provided emotional support like no human deserves. This must have been the most exciting year in my life so far, so again: thank you, everyone, for making it possible. 1https://www.upf.edu/web/gti 2https://cordis.europa.eu/project/id/856879 3https://cordis.europa.eu/project/id/101017255 4https://ricjm.github.io/ 5https://www.upf.edu/web/jblat 6https://blog.thomaspoulet.fr/ 7https://www.tobias-franke.eu/ Abstract Hair rendering has been a major challenge in computer graphics for several years due to the complex light interactions involved. Complexity mainly stems from two aspects: the number of hair strands, and the resulting complexity of their interaction with light. In general, theoretical approaches towards a realistic hair visualization aim to develop a proper scattering model on a per-strand level, which can be extended in practice to the whole hair volume with ray tracing even though it is usually expensive in computational terms. Aiming at achieving realtime hair rendering, I analyze each component contributing to it from both theoretical and practical points of view in this work. Most approaches, both real- and non-real-time build on top of the Marschner scattering model, such as recent efficient state-of-the-art techniques introduced in Unreal Engine8and Frostbite9, among others. Interactive applications cannot afford the complexity of ray tracing, and they target efficiency by explicitly dealing with each component involved in both single-strand and inter-strand light interactions, applying the necessary simplifications to match the time budget. I have further implemented a framework, separating the different components, which combines aspects of these approaches towards the best possible quality and performance. The implementation achieves real-time good-looking hair, and its flexibility has allowed to perform experiments on performance, scalability, and contribution to quality of the different components. 8https://www.unrealengine.com/ 9https://www.ea.com/frostbite Contents 1 Introduction 1 2 Theoretical Background 4 2.1 HairAnatomy................................ 4 2.2 SurfaceReflection.............................. 5 2.2.1 BRDF................................. 5 2.2.2 BSSRDF ............................... 7 2.3 Hair Geometry Representation: Cards . . . . . . . . . . . . . . . . . . 8 2.4 HairShading................................. 10 2.4.1 Near-field and Far-field Scattering . . . . . . . . . . . . . . . . 10 2.4.2 Marschner scattering model . . . . . . . . . . . . . . . . . . . . 11 2.4.2.1 Notation ......................... 11 2.4.2.2 Bidirectional Curve Scattering Distribution Function 11 2.4.2.3 Components of reflected light for a hair fiber . . . . 14 2.4.2.4 Longitudinal and Azimuthal scattering decomposition ........................... 14 2.4.2.5 Longitudinal Scattering Function . . . . . . . . . . . 17 2.4.2.6 Azimuthal Scattering . . . . . . . . . . . . . . . . . . 17 2.4.2.7 Attenuation by absorption and reflection . . . . . . . 18 3 State of the Art 21 3.1 Offline Scattering Models . . . . . . . . . . . . . . . . . . . . . . . . . 21 3.2 Shadowing.................................. 22 3.3 GlobalScattering .............................. 22 3.4 Real-timepipelines ............................. 22 3.4.1 EpicGames ............................. 23 3.4.2 Frostbite............................... 23 i CONTENTS ii 4 Implementation and Results 24 4.1 Framework set-up and overview . . . . . . . . . . . . . . . . . . . . . 24 4.1.1 Rasterization Pipeline . . . . . . . . . . . . . . . . . . . . . . . 24 4.1.2 Material, Shaders and Geometry . . . . . . . . . . . . . . . . . 25 4.1.3 BaseScenario ............................ 26 4.2 Blending ................................... 27 4.2.1 Alphablending........................... 27 4.2.2 Order Independent Transparency . . . . . . . . . . . . . . . . 28 4.2.3 Alphatesting ............................ 28 4.3 Scatteringmodel .............................. 29 4.3.1 Recall of Marschner’s model and Notation . . . . . . . . . . . 31 4.3.2 RPath ................................ 35 4.3.3 TTPath................................ 36 4.3.4 TRTPath............................... 40 4.3.5 Roughness.............................. 42 4.4 Environmental Lighting . . . . . . . . . . . . . . . . . . . . . . . . . . 44 4.5 Shadowing.................................. 46 4.6 GlobalScattering .............................. 49 5 Experiments 52 5.1 OverallStrategy............................... 52 5.2 Comparison with Basic and Enhanced PBR . . . . . . . . . . . . . . . 53 5.3 Scalability and Performance . . . . . . . . . . . . . . . . . . . . . . . . 55 5.3.1 Resolution.............................. 57 5.3.2 Lightinstances ........................... 58 5.3.3 Hairinstances............................ 58 6 Conclusions 60 A O3DE Background 62 A.1 O3DEBasics................................. 62 A.2 O3DECon 2021: Atom Deep Dive - Talk summary . . . . . . . . . . . 68 A.2.1 Introduction............................. 68 A.2.2 RPI.................................. 68 A.2.3 PassSystem............................. 68 A.2.4 RHI.................................. 69 CONTENTS iii Bibliography 71 List of Figures 2.1 Cross-section schematic of human hair fibers [Wei06].......... 5 2.2 Visualization of the BRDF reflectance abstraction [PJH16]. ...... 6 2.3 Visualization of the BSSRDF reflectance abstraction [PJH16]. ..... 8 2.4 Hair cards model. Top: shaded hair. Bottom: raw cards geometry. From [Tok18]. ................................ 9 2.5 Left: (blue) and far (orange) field scattering are represented. Middle: near-field close-up. Right: far-field close-up. [YJR17].......... 11 2.6 Cylinder scattering notation [MJC+03]................... 13 2.7 Cylinder scattering notation from a circular cross-section [MJC+03]. . 13 2.8 Marschner model scheme. The dashed lines indicate the scattering angles for a cylinder without tilted surface scales [MJC+03]. ..... 15 2.9 Rays reflecting off a smooth cylinder are restricted to a single specular cone [DFH+11]. ............................ 15 2.10 Snell’s law in a cylinder. (left) high longitudinal inclination (θi> 60◦) (right) no longitudinal inclination (θi= 0◦). (top) longitudinal view (bottom) azimuthal view. . . . . . . . . . . . . . . . . . . . . . . 16 4.1 Left: framework interface showing the relevant properties exposed for tuning the hair shading model. Right: more properties that are not shown in the left image. . . . . . . . . . . . . . . . . . . . . . . . . 26 4.2 Base sample using the proposed scattering model with shadows enabled...................................... 27 4.3 Outcome of applying different blending modes and parameters. . . . 30 4.4 Cylinder scattering notation [MJC+03]................... 31 4.5 Marschner model scheme. The dashed lines indicate the scattering angles for a cylinder without tilted surface scales [MJC+03]. ..... 31 4.6 Cylinder scattering notation from a circular cross-section [MJC+03]. . 31 4.7 Contribution of the R path (p= 0)..................... 37 iv LIST OF FIGURES v 4.8 Comparison between the exact hand the approximated one used in the TT azimuthal path, for different values of a= 1/η′. ........ 38 4.9 Contribution of the TT path (p= 1).................... 40 4.10 TT path contribution placing a point light behind the head. . . . . . . 41 4.11 Contribution of the TRT path (p= 2)................... 43 4.12 Output visualization using different longitudinal roughness βM. . . . 44 4.13 Output visualization using different azimuthal roughness βN. .... 45 4.14 IBL influence (outdoor environment). . . . . . . . . . . . . . . . . . . 47 4.15 IBL influence (indoor environment). . . . . . . . . . . . . . . . . . . . 48 4.16 Shadowing comparison using a point light between the head and the camera. (left) shadows disabled, (right) shadows with exponentialfalloff. .................................. 49 4.17 Shadowing comparison using a directional light oriented towards the camera. (left) shadows disabled, (right) shadows with exponentialfalloff. .................................. 49 4.18 Contribution of the global scattering approximated by a constant ambientterm. ................................ 51 5.1 Comparison between the hair material implementation and O3DE’s PBR implementation tuned to achieve efficiency and similarity. Left: O3DE’s PBR. Right: proposed hair material. . . . . . . . . . . . . . . 53 5.2 Comparison between the hair material implementation and O3DE’s enhanced PBR implementation tuned to achieve maximal quality. (left) O3DE’s enhanced PBR, (right) Implemented hair material. . . . 54 5.3 Comparison between Karis’ hair material against the material implemented in this work. (left) Karis hair [Bri16], (right) this work´s hairmaterial. ................................ 55 5.4 Frame times of each shading model introduced in the comparison for different scene setups. . . . . . . . . . . . . . . . . . . . . . . . . . 56 5.5 Output visualization of experiment with 4 discrete light sources. . . . 58 5.6 Output visualization of experiment with 8 hair instances occupying most part of the viewport and 2 discrete light sources. . . . . . . . . . 59 A.1 Passfilestructure .............................. 69 List of Tables 2.1 Notation description for geometry scattering and hair-specific parameters.................................... 12 2.2 Scales tilt and roughness values used in every path from the Marschner practical model [MJC+03].......................... 17 4.1 Notation description for geometry scattering and hair-specific parameters.................................... 32 vi 2.2. SURFACE REFLECTION 7 • Reciprocity: fr(p, ωo, ωi) = fr(p, ωi, ωo),∀ωo, ωi∈Ω(2.5) • Energy conservation: The total radiant exitance cannot be greater than the total energy of incident light. ZΩ fr(p, ωo, ωi) cos θidωi≤1,∀ωo∈Ω(2.6) A trivial variant of the BRDF is the bidirectional transmittance distribution function (BTDF) for absorbed light. The form is the same but with ωiand ωobelonging to opposite hemispheres. The result of joining the BRDF and the BTDF (which expands to using the whole set of sphere directions as integration domain instead of only the hemispherical ones) is commonly referred to as bidirectional scattering distribution function (BSDF). Most hair rendering approaches are based on a specification of the BSDF in the domain of curves, named Bidirectional Curve Scattering Distribution Function (BCSDF). A significant limitation of the BRDF abstraction is that incident light is assumed to be absorbed or reflected at the same point of incidence, while in real-world materials the incident light is scattered at a subsurface level before leaving the surface at a different point (this is partially modelled by a diffuse reflection component of the BRDF) or being absorbed. In most materials, however, the subsurface light transport is negligible, thus the BRDF abstraction is accurate enough. But for translucent materials, this is not the case. 2.2.2 BSSRDF The bidirectional scattering surface reflectance distribution function (BSSRDF) is a generalization of the BRDF that considers scattering from materials that exhibit a significant amount of subsurface light transport. Similar to the BRDF, the BSSRDF is a distribution function S(po, ωo, pi, ωi)describing the ratio between outgoing and incident radiance in specific directions. The key difference is that the BSSRDF allows measuring the outgoing radiance at any point pothat is not necessarily the same point piwhere the incident light arrives, accounting this way for the subsurface scattering contribution. Figure 2.3 2.3. HAIR GEOMETRY REPRESENTATION: CARDS 8 Figure 2.3: Visualization of the BSSRDF reflectance abstraction [PJH16]. describes this abstraction visually. Note that if po=pithe BSSRDF becomes the BRDF introduced above, hence the BSSRDF generalizes the BRDF. Using the same procedure as in the BRDF, and renaming pthe outgoing point as earlier, the BSSRDF can be formalized as: S(p, ωo, pi, ωi) = dLo(p, ωo) dE(pi, ωi)=dLo(p, ωo) Li(pi, ωi) cos θidωi (2.7) Then, the outgoing radiance can be isolated: Lo(p, ωo) = ZAZΩ S(p, ωo, pi, ωi)Li(pi, ωi) cos θidωidA (2.8) Note that the inner integral is the same as in Eq. (2.4) describing the BRDF-based radiance. Since now we have another dimension pi, we need to add another integral to measure the contribution of the incident light at all positions piin the surface area A. The rationale behind this is that every point in the surface might contribute with subsurface scattered light to any other point in the surface. In practice, however, the BSSRDF will assign a negligible contribution when piand pare far away, since the incident light at piis likely to be either absorbed or reflected at other surface points before reaching p. 2.3 Hair Geometry Representation: Cards Since the pipeline used is based on rasterization, a traditional way to represent hair would be with an explicit geometry. Many explicit representations have been used 2.3. HAIR GEOMETRY REPRESENTATION: CARDS 9 Figure 2.4: Hair cards model. Top: shaded hair. Bottom: raw cards geometry. From [Tok18]. in the literature and in interactive applications. Sometimes a single-shell mesh representing the whole hair shape can be used. In other cases, especially for fur, a shell by extruding the mesh with strand data has been proposed as a useful representation. The most sophisticated approach uses individual strand data as actual geometry. However, representing hair with hair cards is the most common option in current games and interactive applications in general, and thus we focus on it. In terms of explicit geometry, cards usually refer to planes (curved and elongated) representing a set of strands. The single-strand detail is baked into a texture so that it can be recovered when shading the plane geometry. An instance of hair cards model is shown in Figure 2.4. There are some significant advantages when using this representation: • The reduced amount of vertices improves the geometry throughput. • Reduced amount of overdraw due to the baking strategy (leading to fewer sub-objects per pixel compared to a strand-based representation). However, despite its advantages, it also exhibits relevant limitations: • Per-strand detail depends on the texture resolution. For high-quality hair, a high texture resolution is usually needed (2k or 4k). 2.4. HAIR SHADING 10 • Usually multiple textures are required to recreate a proper shading, increasing the memory footprint. • Hard to blend properly. • Repeating patterns can be spotted if observed carefully. Most of these cannot be solved directly but can be alleviated, as done in some parts of this work. Still, cards achieve a very good quality-performance ratio, especially for real-time applications. 2.4 Hair Shading 2.4.1 Near-field and Far-field Scattering Single fiber scattering can be approximated with two different approaches: • Far-field scattering models assume that hair fibers are very thin, usually thinner than a pixel. Therefore, these models give more importance to the integral over the hair fiber cross-section rather than the accurate incident position. This implies that incident light across the width of the hair fiber is assumed to be collimated (parallel). Thus, when a strand covers more than one fiber it will look flat. • Near-field approaches, on the other hand, take into account the accurate incident positions in the cross-section, giving hair a cylindrical appearance from a close-up view. Figure 2.5 shows a diagram of the scattering in both cases. The full intuition behind it is going to be clearer after going through Section 2.4.2, but a simpler description is presented here. Far-field estimates the angle of incidence of light in the hair cross-section (related to the hparameter in the figure). This estimation is done from the exiting azimuth ϕwe are interested in with respect to the incident light direction. Near-field, on the other hand, considers the actual angle of incidence of the light in the hair cross-section, and computes its contribution to the exiting azimuth ϕ. The figure also shows the different visual appearances resulting from each approach. 2.4. HAIR SHADING 11 Figure 2.5: Left: (blue) and far (orange) field scattering are represented. Middle: near-field close-up. Right: far-field close-up. [YJR17] 2.4.2 Marschner scattering model Marschner et al. [MJC+03] introduced one of the first physically-based far-field Bidirectional Curve Scattering Distribution Function (BCSDF, more details in Section 2.4.2.2) models in the hair rendering literature. Most posterior models build upon it. Given its prominence, the model is described in detail in this subsection. From the hair anatomy described in Section 2.1, Marschner models a hair fiber as an elliptical cylinder with the cuticle being the surrounding layer, and simplifies the cortex and medulla into a single component. Considering an elliptical crosssection introduces a significant complexity both mathematical and computational. Since this work targets real-time, and the elliptical component is not essential for a proper visualization (even though it is not negligible in non-caucasian hairs), a circular cross-section is assumed in this section and over the whole work unless noted otherwise. 2.4.2.1 Notation Figures 2.6,2.7 and Table 2.1 show the scattering notation used in their work. The interpretation of these figures is introduced progressively through this section. The stated notation is also inherited in later work, therefore it is used throughout this work too. As can be observed in Figure 2.6, the scattering and absorption in the interior of the fiber are considered to be uniform, that is, the cortex and medulla components introduced in Section 2.1 have been merged into a single one. 2.4.2.2 Bidirectional Curve Scattering Distribution Function Marschner defines a Bidirectional Curve Scattering Distribution Function (BCSDF) S(ωi, ωo), which conceptually maps to a BSDF applied to curves. The difference 2.4. HAIR SHADING 12 Term Description Formula uTangent direction to the hair fiber (pointing towards the strand tip) vMajor axis of the elliptical cross section (forming an orthonormal basis with uand w) wMinor axis of the elliptical cross section (forming an orthonormal basis with uand v) ωiIncident light direction ωrDirection in which scattered light is being measured ωx⊥Projection of ωxonto u(perpendicular to the normal plane v-w) u(ωx·u) ωx∥Projection of ωxonto the normal plane v-w(parallel to it) ωx−ωx⊥ θiLongitudinal inclinationaof ωiarccos (ωi·ωi∥) θrLongitudinal inclination of ωrarccos (ωr·ωr∥) ϕiAzimuthal inclinationbof ωiarccos (ωi∥·v) ϕrAzimuthal inclination of ωrarccos (ωr∥·v) θdDifference longitudinal angle (θr−θi)/2 ϕRelative azimuth ϕr−ϕi θhAverage longitudinal inclination (half angle) (θi+θr)/2 ϕhAverage azimuthal inclination (half angle) (ϕi+ϕr)/2 αCuticle scales tilt −10◦to −5◦ ηIndex of refraction of hair 1.55 η′Cortex’s virtual refractive index in the azimuthal projection √η2−sin2θd cos θd hOffset from a ray to the center of a unit circle γiAngle of incidence with respect to the cross section circle normal arcsin (h) γtAngle of the refracted ray with respect to the cross section circle normal arcsin (h/η′) aInclination with respect to the normal plane. bInclination around the hair fiber axis, with respect to v. Table 2.1: Notation description for geometry scattering and hair-specific parameters. 2.4. HAIR SHADING 13 Figure 2.6: Cylinder scattering notation [MJC+03]. Figure 2.7: Cylinder scattering notation from a circular cross-section [MJC+03]. is that it is measured in terms of curve irradiance ¯ E(power per unit length) and curve intensity ¯ L(intensity per unit length), which are analogous to irradiance and radiance, respectively. Using the notation stated in 2.4.2.1, we can write: S(ωo, ωi) = d¯ Lo(ωo) d¯ E(ωi)=d¯ Lo(ωo) D¯ Li(ωi) cos θidωi ,(2.9) 2.4. HAIR SHADING 14 where D is the diameter of the fiber. Then, the scattering integral is: ¯ Lo(ωo) = DZS(ωo, ωi)¯ Li(ωi) cos θidωi(2.10) Qualitatively, the arrangement of D in this expression indicates that a thick fiber gets more light, and therefore appears brighter from a distance than a thin fiber. 2.4.2.3 Components of reflected light for a hair fiber From their experiments, Marschner et al. [MJC+03] conclude that three scattering paths can be identified as the most relevant ones for translucent hair: R, TT, and TRT, where T and R symbolize transmission and reflection across the fiber interface, respectively. These three paths can be described as: • R: Reflection from the fiber surface resulting in a component spread uniformly around a cone. Visually, it is a shift of the primary (imperfect) specular peak toward the root of the strand. According to Marschner, this deviation is hypothesized to be due to the tilt in the scales which exist on the hair fiber. • TT: Transmission through the hair fiber producing a very bright component that is usually more prominent when looking at it from the opposite side of the hair. • TRT: Light that reflects on from the inside of the actual hair fiber producing a back-scattering component. Visually, it is a colored secondary peak shifted towards the tip of the strand with respect to the primary specular peak. Sometimes it appears more as a colored fringe on the primary highlight than a separate feature. Figure 2.8 shows a scheme of these paths and the effect of the cuticle scales according to the Marschner model. In Figure 2.7 the respective light cones are represented. 2.4.2.4 Longitudinal and Azimuthal scattering decomposition Assuming a symmetric cylinder, the 4D scattering function for a fiber can be factored into a product of two 2D terms: longitudinal scattering M(dependent on the longitudinal inclinations θ) and azimuthal scattering N(dependent on the azimuthal inclinations ϕ). This is based on two observations: 2.4. HAIR SHADING 15 Figure 2.8: Marschner model scheme. The dashed lines indicate the scattering angles for a cylinder without tilted surface scales [MJC+03]. 1. In an ideal smooth cylindrical fiber, light arriving at an incoming inclination θiis reflected in a restricted specular cone θr=−θi(see Figure 2.9). This also applies to the refracted rays inside the hair, therefore, every path (R, TT, and TRT) involves cone-restricted reflection directions in the longitudinal axis. Figure 2.9: Rays reflecting off a smooth cylinder are restricted to a single specular cone [DFH+11]. 2. The contribution of the azimuthal scattered distribution can be measured by examining only the projection into a plane perpendicular to the hair fiber. For the Rpath, one can simply project it into the perpendicular plane and apply a traditional reflection using the normal at the incident point, as can be observed in Figure 2.7. For the refracted paths, Marschner exploits the Bravais properties of smooth 2.4. HAIR SHADING 16 cylinders, which state that if the incident and transmitted vectors at a dielectric interface are projected onto a plane containing the surface normal, the projected vectors still obey Snell’s law, but with the index of refraction ηreplaced by η′(η, θ)> η [MJC+03]. The new index of refraction η′depends on the longitudinal inclination θ. Specifically, η′=√η2−sin2θd cos θd. The intuition behind this is shown in Figure 2.10. As can be observed, rays with a high incident longitudinal inclination θiwill appear more refracted from the cross-section projection than rays with no longitudinal inclination θi= 0. Figure 2.10: Snell’s law in a cylinder. (left) high longitudinal inclination (θi> 60◦) (right) no longitudinal inclination (θi= 0◦). (top) longitudinal view (bottom) azimuthal view. On the basis of these two observations, the BCSDF can be decomposed into a longitudinal scattering component M(θi, θr), accounting for the specular cone distribution, and an azimuthal scattering component N(η′(θi); ϕi, ϕr)performing the general scattering analysis but with a reduced dimensionality: S(ϕi, θi;ϕr, θr) = M(θr+θi)N(η′(θi); ϕi, ϕr)/cos2θd(2.11) The cosine term in this expression accounts for the projected solid angle of the specular cone. 3.4. REAL-TIME PIPELINES 23 3.4.1 Epic Games Karis [Bri16] presents the way hair rendering is handled in the 3D engine Unreal Engine1. Several simplifications of the Marschner [MJC+03] and d’Eon [DFH+11] scattering models are performed. No shadowing technique from the hair literature is used. Instead, they use an exponential falloff, which achieves good enough results. As for the environmental lighting, the precomputed environment irradiance map is sampled towards a bent normal direction, and the sample obtained is input into the scattering model with some modifications. For global scattering, a fake normal and an exponential falloff towards the shadow map is used again, but this time applying absorption over the light path. 3.4.2 Frostbite Tafuri [Taf19] explains how their 3D engine Frostbite2manages hair rendering. An important difference with respect to Karis [Bri16] is that strand-based hair models are used. He presents how Frostbite manages sampling the hair strands efficiently and without artifacts by using a visibility buffer. Also, the scattering model from Karis is extended to depend on azimuthal roughness as well, and some specific components are slightly modified. As for shadowing and global scattering, they use deep opacity maps [YK08]. 1https://www.unrealengine.com/ 2https://www.ea.com/frostbite Chapter 4 Implementation and Results 4.1 Framework set-up and overview As indicated in the introduction, this work implements a model for shading hair defined by a set of components: hair blending, scattering model, environmental lighting, shadowing, and global scattering, which are discussed in detail in the different sections of this chapter. The implementation introduced in this thesis is a framework integrating these different components, which can be enabled, disabled, or parameterized through a graphical user interface. In this section, I provide an overview of the framework. 4.1.1 Rasterization Pipeline The framework developed uses a rasterization pipeline, which is a common option in most interactive 3D applications. This is relevant because optimizations of the shading models can differ according to the pipeline used. The most intuitive pipeline for realistic rendering, in general, would be a traditional ray-tracing pipeline since it allows easily replicating the physical behavior of light; the light reaching the camera can be computed by spawning rays from it and evaluating the BCSDF for every hair strand intersected, but in order to account for the incident light from every direction, more rays need to be spawned from the intersection points, repeating this process recursively. If an infinite level of recursion was allowed, the behavior of light would be accurately represented. Therefore, a ray-tracing pipeline implicitly accounts for hair self-shadowing, translucency, and 24 4.1. FRAMEWORK SET-UP AND OVERVIEW 25 global scattering through the volume. A rasterization pipeline, on the other hand, involves projecting 3D models into the camera view space, and then shading each pixel according to the attributes and contextual information of these models. Therefore, each point being shaded does not have accurate information regarding the light reaching it. This forces us to deal explicitly with the global phenomena mentioned above (self-shadowing, strand blending, and light scattering through the volume). In a rasterization pipeline the light rays cannot be easily simulated, so this usually involves not matching the accuracy of a ray-traced result. Despite this, because of the way GPUs are built and the computational complexity of each approach, a rasterization pipeline is much more efficient and feasible for real-time applications. 4.1.2 Material, Shaders and Geometry I have been using a new custom material for hair using O3DE1as 3D engine. O3DE is an emerging open-source project which offers high modularity. O3DE material Briefly speaking, an O3DE material is defined as a JSON file that contains a set of properties (such as albedo, roughness, etc), their expected input data type, and how they map to the actual shaders attached to the material. For more information about O3DE and its renderer Atom, see Appendix A. Custom shaders In this project, I have implemented three custom shaders: two of these are attached to the depth and shadow pass, which, as the following sections will show, are both necessary to perform proper blending and shadowing. The other one defines the main behavior for the forward pass (O3DE uses a forward+ pipeline), gathering results from the information produced in the previous passes and evaluating the proposed scattering model from this information and the input parameters defined. 1https://o3de.org/ 4.1. FRAMEWORK SET-UP AND OVERVIEW 26 Framework interface The properties defined in the material file are shown in the O3DE’s material editor as an interface to the actual values used by the shaders. This provides higher flexibility and a more intuitive tuning of the model parameters. Most properties map directly to the forward pass shader, but some others require some kind of processing before being usable, which is performed in Lua/C++ functors (referenced in the material file as well). Besides the parameters strictly required by the shading model, I have added supplementary properties allowing for each component to be enabled/disabled, or in some cases, to be weighted by a user-defined factor. Figure 4.1 shows the framework interface with the available properties in the Material Property tab. Figure 4.1: Left: framework interface showing the relevant properties exposed for tuning the hair shading model. Right: more properties that are not shown in the left image. Hair geometry The most popular representations of hair geometry in the context of interactive applications are cards-based models and strand-based models. In general, cards models are less expensive to shade (see Sections 2.3), so these are the ones used in this work. 4.1.3 Base Scenario In the following sections, each component involved in the shading model is described in detail. Moreover, the contribution of each one is illustrated with images coming directly from this work’s results. The base scenario is the one shown in 4.2. BLENDING 27 4.2, using as default roughness values βM= 0.2(longitudinal roughness, see Section 2.4.2.5) and βN= 0.8(azimuthal roughness introduced first by d’Eon et al [DFH+11], see Section 3.1). The scene setup has been kept as simple as possible in order to minimize noise from other sources, therefore it consists of a single point light that illuminates the hair object. Figure 4.2: Base sample using the proposed scattering model with shadows enabled. 4.2 Blending This work uses hair cards models to represent the hair geometry. With proper models of this kind, a plausible visualization can be achieved, but we need to perform blending carefully, where blending refers to the process of combining the contribution from multiple objects (strands, in this case) into the same projected area (pixel) due to their translucent nature. One of the biggest challenges when using hair cards is that blending the cards properly can be cumbersome due to the very thin hair strand width and its translucent nature, as detailed in the next subsections. 4.2.1 Alpha blending Assuming we are provided with an opacity map, we still cannot perform alpha blending properly because in the case of self-occluding objects like hair cards, 4.2. BLENDING 28 hardware blending does not guarantee any depth order, so we would end up with a corrupted blending as we see next: • With enabled depth writes: when a card is drawn, its depth is written into the depth buffer. For cards drawn afterwards, all fragments falling behind the closest depth registered in these pixels will be discarded, even if the fragment that defined the closest depth (occluder) was transparent. • With disabled depth writes: the cards visible depend on the order they are drawn, so cards that should be occluded can appear completely visible. 4.2.2 Order Independent Transparency A potential solution for card blending is to use Order-Independent Transparency (OIT) techniques, which consist of sorting the depth of the geometry per pixel in order to blend from furthest to nearest, solving this way the shortcomings of both alpha blending options introduced in the previous section. However, OIT usually involves storing all fragments in an intermediate step before the sorting and blending stages. As can be expected, these aspects imply a very complex implementation process and a significant overhead in computational cost. Hence, given the real-time target of this work, OIT has been discarded as a blending solution for it. 4.2.3 Alpha testing The most efficient solution in these scenarios is to perform alpha testing. Alpha test writes into the depth buffer, but only for fragments whose opacity is above a certain threshold. Naturally, it has some side effects: • Only the closest fragment (the fragment with lowest depth value) will be shown; there is no blending with fragments behind. • Sharp aliased edges are usually introduced due to the differences in opacity values of neighbor texels, unless a very high resolution texture is used. Even with post-processing using anti-aliasing techniques, jagged artifacts will still appear when the object is close enough. 4.3. SCATTERING MODEL 29 • It is hard to determine the proper threshold because the thickness of the strands can be affected. A higher threshold will allow more texels to be displayed and therefore increase the apparent strand width. Despite this, for the sake of reducing render times, I use this as blending solution. As an important side note, hair cards should be seen from both front and back directions, so face culling needs to be disabled. Figure 4.3 shows some rendering results with different blending modes and threshold values. We can observe in Fig. 4.3(a) that treating the cards as opaque objects does not achieve the desired effect. As stated in this Section 4.2, alpha blending does not ensure a proper blending, as we can see in Figure 4.3(b), specifically in the base hair cap. Still, some arbitrary parts of the ponytail seem to be blended properly. Then, the outcome of using alpha testing with three different threshold values is shown in Figs. 4.3(c) to (e). With a low threshold (Fig. 4.3(c)), some discontinuities become too obvious, apart from the jagged artifacts. With a high threshold (4.3(d)), the strands appear too thick. Figure 4.3(e) shows the threshold value used for the final result, which achieves a good trade-off between both options. There exist a couple extensions to alpha test that would improve the results at the cost of a slight increase in computational complexity, but have not been implemented due to time constraints: •Alpha to coverage [Gol17]: the goal of this technique is to obtain anti-aliased alpha test. It works by performing multi-sampling and evaluating alpha test for all the coverage samples of the pixel. If a fragment is opaque, then its depth will be written and the color information belonging to that fragment updated. This way, an average of the strands contributing to that pixel will be achieved instead of a unique comparison leading to aliased edges. •Hashed alpha testing [WM17]: this technique makes use of well-distributed noise with spatial and temporal stability to define the alpha test threshold. This kind of noise is obtained with hash functions ensuring a set of spatiotemporal properties (see reference for further information). Hashed alpha testing is usually combined with temporal anti-aliasing. 4.3 Scattering model The light scattering model is the rendering component that most contributes to a realistic hair visualization. Therefore, a significant part of the efforts involved in 4.3. SCATTERING MODEL 30 (a) Opaque (b) Alpha blend (no depth writes) (c) Alpha test (thr = 0.25) (d) Alpha test (thr = 1) (e) Alpha test (thr = 0.8) Figure 4.3: Outcome of applying different blending modes and parameters. this project has been devoted to implementing a proper BSDF model, by integrating different state-of-the-art approaches, which we reference in what follows. The main idea is to model single strand light scattering with three lobes, as introduced by the Marschner BSDF [MJC+03] (see Section 2.4.2), but reducing the computation complexity of each one through mathematical approximations and/or computational optimizations integrating different contributions. First, we recall the basics and notation of Marschner’s model and specify the issues dealt with, then discuss more precisely the approximation taken for the different paths (R, TT, TRT) and conclude with a specific subsection on roughness, an important tunable parameter in PBR. 4.3. SCATTERING MODEL 31 4.3.1 Recall of Marschner’s model and Notation For the reader convenience, Table 4.1, Figure 4.4, Figure 4.5, and Figure 4.6, are inserted again in this section. Figure 4.4: Cylinder scattering notation [MJC+03]. Figure 4.5: Marschner model scheme. The dashed lines indicate the scattering angles for a cylinder without tilted surface scales [MJC+03]. Figure 4.6: Cylinder scattering notation from a circular cross-section [MJC+03]. Marschner et al. [MJC+03] model a hair strand as a translucent cylinder. It measures its BCSDF Sas the product of two separate components: longitudinal scattering Mand azimuthal scattering N, yielding: S(ϕi, θi;ϕr, θr) = M(θi, θr)N(η′(η, θd); ϕi, ϕr)/cos2θd(4.1) 4.3. SCATTERING MODEL 32 Term Description Formula uTangent direction to the hair fiber (pointing towards the strand tip) vMajor axis of the elliptical cross section (forming an orthonormal basis with uand w) wMinor axis of the elliptical cross section (forming an orthonormal basis with uand v) ωiIncident light direction ωrDirection in which scattered light is being measured ωx⊥Projection of ωxonto u(perpendicular to the normal plane v-w) u(ωx·u) ωx∥Projection of ωxonto the normal plane v-w(parallel to it) ωx−ωx⊥ θiLongitudinal inclinationaof ωiarccos (ωi·ωi∥) θrLongitudinal inclination of ωrarccos (ωr·ωr∥) ϕiAzimuthal inclinationbof ωiarccos (ωi∥·v) ϕrAzimuthal inclination of ωrarccos (ωr∥·v) θdDifference longitudinal angle (θr−θi)/2 ϕRelative azimuth ϕr−ϕi θhAverage longitudinal inclination (half angle) (θi+θr)/2 ϕhAverage azimuthal inclination (half angle) (ϕi+ϕr)/2 αCuticle scales tilt −10◦to −5◦ ηIndex of refraction of hair 1.55 η′Cortex’s virtual refractive index in the azimuthal projection √η2−sin2θd cos θd hOffset from a ray to the center of a unit circle γiAngle of incidence with respect to the cross section circle normal arcsin (h) γtAngle of the refracted ray with respect to the cross section circle normal arcsin (h/η′) aInclination with respect to the normal plane. bInclination around the hair fiber axis, with respect to v. Table 4.1: Notation description for geometry scattering and hair-specific parameters. 4.3. SCATTERING MODEL 39 sorption values. For the TT and TRT paths, both d’Eon and Marschner define the attenuation as a set of chained Fresnel reflections weighted by an absorption term. In this work I use Schlick’s approximation [Sch94] for measuring the Fresnel F, which is responsible to account for the proportion of light reflected/refracted in every path. As for the absorption, it accounts for the amount of light absorbed across the hair fiber in terms of the distance it has travelled (for more context, see Section 2.4.2.7). In the R path there is no absorption because the reflection is considered as a rough shifted mirror, but for TT and TRT, the light goes through the fiber, and therefore will get absorbed differently along its spectrum. The absorption term has been described in many different ways in the literature, but for this work, I am using the approach by Pekelis et al [PHVL15]. This approach uses a color variable that maps implicitly to the absorption coefficients instead of using the absorption coefficients as raw input, which allows for a more intuitive tuning of the model: T(θ, ϕ) = e−pζ(C)   cos γt cos θd   (4.17) Then, substituting with γt= arcsin h η′and developing for the TT path (p= 1): TT T (θ, ϕ) = C √1−h2a2 2 cos θd,(4.18) where Cis the base color of the hair. Note that in the case of Tafuri’s approach, approximating AT T at h= 0, most of the parameters involved in the attenuation can be made constant: TT T (θ, ϕ) = C 1 2 cos θd(4.19) Also, from Eq. (4.7), fcan be simplified: f=F(η, cos θd)(4.20) This might slightly reduce the computational complexity of measuring this path, but not significantly, since at the end of the day we are only avoiding a few multiplications of already known parameters, not any complex operation. Same as with the analytical hvalue, the analytical azimuthal distribution term for the TT path becomes much more complex compared to the one seen in the R path. Following the same line, Karis uses a cheaper approximation to that function. 4.3. SCATTERING MODEL 40 Specifically, it uses a Gaussian with the appropriate parameters that produce a similar function to the analytical one. In this work, it has proved to be valid, so it is the one that is going to be used: DT T (ϕ)≈e−3.65 cos ϕ−3.98 (4.21) Then, the final expression for the azimuthal TT contribution is: NT T = (1 −F(η, cos θd))2C 1 2 cos θde−3.65 cos ϕ−3.98 (4.22) In the same scene setup as in Figure 4.2, the TT path has almost no contribution in this (see Figure 4.9). This path becomes extremely significant when the hair strands are between the light source and the camera, as can be observed in Figure 4.10, which uses a point light behind the hair object (note that the intensity of this light is low), and even more prominently in Figure 4.17, which uses a directional light source facing the camera. Note that this path introduces slight information of the hair color due to the absorption inside the strand. Figure 4.9: Contribution of the TT path (p= 1) 4.3.4 TRT Path Similar to the previous paths, the goal is to find the right value(s) for hgiven ϕ, which will allow us to compute the attenuation and distribution terms. For the TRT path, as noted in Eq. (4.4) from Section 2.4.2.6, a given difference angle ϕcan 4.3. SCATTERING MODEL 41 (a) TT (p= 1) (b) All components Figure 4.10: TT path contribution placing a point light behind the head. lead to either one or three solutions of h; the analytical solutions are the roots of the following function (extracted from [DFH+11]): sin ϕ 2=−h+ 2a2h3+ 2ah√1−h2√1−a2h2(4.23) These solutions are complex and inconvenient to implement, which makes them unfeasible for real-time. Moreover, there is no cheap approximation for this solution even in the state-of-the-art of interactive hair rendering. Thus, I use the alternative introduced by Karis [Bri16], which is similar to the way Tafuri approximated hin the TT path [Taf19]. Basically, it consists in finding the hvalue that most contributes to the global attenuation function; Karis approximates it at h=√3 2. Consequently, the attenuation expression introduced by Pekelis [PHVL15] (see Eq. (4.17)) can be developed again, now with h=√3 2and p= 2 (TRT), resulting in the following expression: TT RT (θ, ϕ) = C 0.8 cos θd(4.24) also, for the proposed constant value h=√3 2,γibecomes γi=π3, so we can define: f=F(η, cos θd 2)(4.25) In the same line, Karis approximates the distribution term with another Gaussian [Bri16]: DT RT =e17 cos ϕ−16.78 (4.26) 4.3. SCATTERING MODEL 42 So far, azimuthal roughness has not been taken into account for any of the paths. Note that the original Marschner approach does not take it into account, but recently Chiang et al. [CBTB16] demonstrate the relevance of this component for the resulting appearance. For the R path, there is no need to consider it, since the light does not traverse the strand. For the TT path, Tafuri proposes to apply reconstructed Gaussians by fetching their parameters from a baked structure into a texture [Taf19]; this has not been implemented in this work in order to reduce the number of texture lookups as much as possible, since these are usually expensive. Nevertheless, for the TRT path, Tafuri improves significantly the distribution approximation by using a scale factor srthat depends on the azimuthal roughness βN[Taf19]: DT RT =sresr(17 cos ϕ−16.78) sr=clamp(1.5(1 −βN)) (4.27) It is important to note that the scale factor sris not based on any physical measure; it is manually tuned to visually approximate the effect. As can be observed in Eq. (4.27), adding the contribution of the azimuthal roughness βNinvolves an almost negligible overhead in computational complexity with respect to the original form (only a small number of basic operations). Moreover, the TRT path is the one with the most significant azimuthal roughness contribution, since it is the path in which light performs more bounces inside the fiber. Because of these two reasons, I have chosen to use this improved approach in my implementation. The resulting expression for the TRT path is: NT RT =1−Fη, cos θd 22 Fη, cos θd 2C 0.8 cos θdsresr(17 cos ϕ−16.78) (4.28) Analyzing visually the results, as can be observed in Figure 4.11, the TRT path is the one reflecting most part of the pure hair color, and its contribution is mainly diffuse. 4.3.5 Roughness The roughness property introduced in the proposed hair models does not only influence the distribution of the light reflected, but it can also have an effect on the 4.3. SCATTERING MODEL 43 Figure 4.11: Contribution of the TRT path (p= 2) actual color of hair. As noted by Chiang et al. [CBTB16], longitudinal roughness βMprimarily controls the width of the highlight, thus changing the perceived shininess of the fiber assembly, while azimuthal roughness βNcontrols the overall softness. Figure 4.12 shows the same setup with different longitudinal roughness βMvalues. As can be observed, the influence of the longitudinal roughness on the output visualization can be mapped to the traditional roughness in a BRDF, in the sense that higher roughness values widen the distribution of reflected rays. Visually, this decreases the saturation of the hair color (assuming a non-colored light), since the pure color lobes are affected now by the R ad TT paths which add light-specific color information. Figure 4.13 shows the influence of various azimuthal roughness values βN. In this case, we can see how it has a more direct impact on the actual hair color. Note that it does not affect the R path, since the azimuthal roughness contributes to the interactions of light inside the hair strand. The visible difference, in this case, is due the TRT path contribution. The azimuthal roughness is still modeling the microfacet geometry and therefore has an impact on the reflection distribution. With this in mind, we know that having a higher 4.4. ENVIRONMENTAL LIGHTING 44 (a) βM= 0.15 (b) βM= 0.3(c) βM= 0.4 Figure 4.12: Output visualization using different longitudinal roughness βM. roughness implies a wider distribution, so the outcoming light (which has been absorbed in a frequency-dependent way determining the hair color) gets scattered across many directions. Hence, the intensity scattered towards the camera will be lower than it would be if the azimuthal roughness was low, since it would then reflect/refract more directionally, transmitting more energy in the direction towards the camera. It is important to mention that this last scenario would happen only if the light and the camera are placed in such a way that the TRT path contribution is maximized. Otherwise, the outgoing radiance towards the camera will be lower than it would be with a higher roughness value (because most of the light will get scattered very directionally in another direction). In practice, this implies that moving either the camera or the light will change the color of the hair significantly, which is not what one would usually expect. Because of this, higher azimuthal roughness values are usually more appropriate for hair and fur. 4.4 Environmental Lighting Applying environmental lighting via Image Based Lighting (IBL) in a BCSDF is not as straightforward as with traditional BRDF models. The main issue is that the BCSDF introduced cannot be approximated with an irradiance map as performed in IBL for traditional diffuse BRDF components. The reason why this happens is that most terms in the BCSDF need to remain inside the rendering equation integral since they depend on the differential variables. Thus, in principle, we cannot benefit from any precomputation. Evaluating the integral with the proposed 4.4. ENVIRONMENTAL LIGHTING 45 (a) βN= 0.3(b) βN= 0.7(c) βN= 0.95 Figure 4.13: Output visualization using different azimuthal roughness βN. BCSDF numerically is far beyond feasibility in real-time applications, so we need to simplify. There are some methods proposed in the literature that approximate the environment by a set of Spherical Radial Basis Functions (SRBF) [RZL+10], but again, their precision scales with numerical complexity. To cope with this problem, Karis [Bri16] proposes to simply take a sample from the environment irradiance map in the direction we (heuristically) guess that will have the largest contribution to the hair appearance, and factor it properly to ensure the same amount of energy is taken into account. Karis [Bri16] uses a bent normal of the hair card to sample from the environment irradiance map. This work uses the actual surface normal instead, but the approach is the same: sampling from a precomputed irradiance map, and then factoring the sample by π, in order to compensate for the fact that we are not sampling from any other direction on the positive hemisphere, but is implicitly embedded in the irradiance map sample. This way, we get a sample that can be input into the shading model, ensuring that contiguous values will have a low variance in the IBL contribution. Furthermore, Karis’ approach [Bri16] introduces other observation-based modifications: • The R path contribution is multiplied by min(ωi·ωr+ 1,1). This translates to attenuating the reflections coming from the opposite direction to the camera (given this work’s sampling strategy, this becomes min(n·v+ 1,1)). The reason why this is done is because we cannot apply the shadowing techniques introduced in Section 4.5 to the IBL samples, since these are not actual 4.5. SHADOWING 46 light sources, so we need to compensate for it by removing the intensity that would likely be blocked by the volume of hair. • Because of the same reason, the whole TT path is removed, since it mainly contributes when the light behind the hair volume faces the camera. • Increase the longitudinal roughness, approximating this way a larger area light source, which is appropriate when accounting for the diffuse environment lighting. I have slightly modified this approach by assuming we are only dealing with hair cards. When fetching the normal direction used to sample the environment map, we allow for this normal to be inverted so that n·v > 0, under the assumption that we are using double-sided polygons, and the face that the camera is seeing has more R and TRT contribution in its positive normal direction, which is not necessarily the case if we do not perform the conditional inversion proposed. Note that this will implicitly solve the first point proposed by Karis, so with the new approach used there is no need to multiply the R path by any external factor. Figures 4.14 and 4.15 show the contribution of IBL in an outdoor and indoor environment, respectively. 4.5 Shadowing Shadowing in the context of hair rendering is important, and mandatory if we want to support dynamic scenes. As explained in Section 4.1, the proposed implementation uses hair cards, which usually are placed in multiple layers through the hair volume. The scattering model is useful to highlight these differences in depth, so that the whole volume does not look flat and uniform. Despite this, in order to achieve a realistic sense of depth, we need to introduce shadows. Because of the nature of hair cards, and the way we are blending them, traditional shadow maps cannot be used; if our shadow map consists in a basic depth map with the raw geometry projected into the light source view, once we test the depth of our point (being shaded from the main view) in light space against the shadow map, we might end up rejecting it as a false negative. This would happen if the shadow map point occluding our main view point was part of the cards 4.5. SHADOWING 47 No IBL IBL Ambient Point Light Figure 4.14: IBL influence (outdoor environment). geometry but did not pass the alpha test (its corresponding alpha value from the opacity map is below the alpha threshold defined). Generalizing, our shadows would have the cards geometry shape instead of the strands shape. A widely used solution for shadowing applied to blended objects is to evaluate the alpha test in the shadow map too. This implies having to use a custom pixel shader for performing this operation, which is the worst case from the hardware perspective to perform depth test; it cannot benefit from either Early-Z or Z-Culling (raster-time depth test) because it writes to the depth target directly from the pixel shader. For better quality, I also use percentage close filtering (PCF) [RSC87] with 4 taps (3x3 window) to smooth the shadows. Figure 4.16 shows the contribution of shadows in the base scenario. As can be observed, shadows help to give hair a feel of volume with multiple layers. De- 4.5. SHADOWING 48 No IBL IBL Ambient Point Light Figure 4.15: IBL influence (indoor environment). spite the improvements, this is not enough for a proper representation of hair selfshadowing. As mentioned in previous sections, hair is translucent. This means that light entering a hair strand can still reach strands behind it, until it is absorbed completely. This is not modelled by the scattering model (since it only measures single-strand scattering), so we need to explicitly reproduce this effect. For this work, I use the simple solution proposed by Karis [Bri16] which is efficient and feasible for real-time applications. It consists in modifying the current shadow map application by using an exponential falloff instead of a hard depth test, so that hair points behind the first lit strand can receive a positive amount of radiance from that light source, with this amount being inversely proportional to the distance (in light space) between the first lit strand and the hair point being shaded; the more distant, the lower the contribution from the light it will receive, which properly represents the absorption through the hair volume. Moreover, this 5.3. SCALABILITY AND PERFORMANCE 55 the part at the bottom of the hair, which is alleviated in the proposed implementation with the exponential falloff. Even though the reference cannot be recreated, Figure 5.3 shows a side-to-side comparison between Karis’ hair shading model and this work’s model under a similar scene and lighting conditions. Figure 5.3: Comparison between Karis’ hair material against the material implemented in this work. (left) Karis hair [Bri16], (right) this work´s hair material. The first thing we might notice is the difference in the quality of the hair model. Karis’ seems to have higher resolution and to be better authored, so the individual strands baked can be better perceived. Also, the strand ID map of the model I use is composed of a single channel, which limits the variability of strand color to be used and is probably not the case in Karis’ model. The opacity is better solved in Karis’ model, most likely because the maps used have a better resolution, the blending techniques are more elaborated, and on top of that, it has been antialiased properly. Aside from that, the actual shading looks similar. Since the hair color is dark, the lack of azimuthal roughness on the Karis’ model is not very visible in this comparison. 5.3 Scalability and Performance In order to evaluate the feasibility of the proposed model for real-time applications, we need to evaluate its performance. Figure 5.4 plots the frame time of the three models presented in this chapter (basic PBR, enhanced PBR, and my hair-specific model) against different setups, for each one building on top of the previous one: 5.3. SCALABILITY AND PERFORMANCE 56 •Raw hair: The shading model with blending only. •Shadows: Raw hair with shadows enabled. •IBL: Raw hair with shadows and IBL enabled. The timing measurements have been captured with NVidia Nsight on a RTX3080 GPU, Intel i7-11850H CPU, and 32GB of RAM. The captures have been done in the O3DE Editor with a scene viewport resolution of 1494x835. This is a higher resolution than HQ (720p) and lower than FHD (1080p). Raw hair + Shadows + IBL + Close-up 4 lights 8 instances 0 5 10 15 20 25 30 35 40 45 60 FPS 30 FPS Frame time (ms) New hair material Basic PBR Enhanced PBR Figure 5.4: Frame times of each shading model introduced in the comparison for different scene setups. In general, we can see how the hair material introduced is slower than the basic PBR but outperforms the enhanced PBR in all cases. This is already a positive 5.3. SCALABILITY AND PERFORMANCE 57 result demonstrating that the new hair material can achieve better results with better performance than a PBR replica of it would. The complexity and quality of the basic PBR are much lower, so we could expect it to be more efficient. Apart from this per-component analysis, it is relevant to acknowledge the limits of the proposed material and how well it scales. Because of this, I have added three setups that could be considered stress tests for our model and are described in the following sections. In general, we can see that in non-stress tests our method is able to shade at 60 FPS, and around 30 FPS in the worst stress tests, making it feasible for most realtime uses. In all the experiments, the scene set-up (lights, environment, etc) described in Section 4.1 has been used equally unless noted otherwise. The implemented model is evaluated with disabled IBL unless noted otherwise. 5.3.1 Resolution To see how the hair material scales with resolution, I use a close-up view of the hair model, since in this case most part of the screen is going to be occupied by hair that needs to be shaded with the given model on a per-pixel basis. This experiment is done with IBL enabled. As we could expect, Figure 5.4 (Close-up) shows that the current implementation scales significantly with resolution. Every screen pixel needs to evaluate the complex shading model, which involves computing the contribution of each scattering path with its pertinent cost. This could be optimized by improving the shader implementation, targeting a better thread scheduling and synchronization strategy on the GPU side. The way to optimize it would be to look for potentially divergent branches that may affect threads from the same warp (usually neighbor pixels), and replace them with GPU-friendly alternatives. Also, profiling meticulously would help to identify these caveats, and reduce the vector registers (VGPR) pressure on the GPU. This experiment increases the cost of the basic and enhanced PBR too, but by a lower factor. 5.3. SCALABILITY AND PERFORMANCE 58 5.3.2 Light instances To see how our model scales with the number of light sources, I have used four light sources in the same scene, as Figure 5.5 shows. We can observe in Figure 5.4 (4 lights) how our model scales with lighting worse than the basic PBR. The reason behind this is that each scattering path contribution needs to be evaluated for each light source, plus perform the proper shadow map with pixel shader for every light as well. A solution to this could be to cluster light sources so that the model is only evaluated with a reduced amount of lights, at the cost of losing precision. Figure 5.5: Output visualization of experiment with 4 discrete light sources. 5.3.3 Hair instances This experiment measures how the proposed implementation scales with the number of hair instances. The screen occupancy is similar to the one in the close-up test, and two light sources have been used. The scene used is shown in Figure 5.6. Just putting together the increased screen occupancy and the increased number of light sources is going to increase the frame rendering time significantly. On top of that, note that there is a significant amount of occlusion among instances. Since this work uses alpha testing and does not ensure the order in which the instances are being rendered, there is going to be a significant amount of overdraw. The performance decrease due to this can be seen in Figure 5.4 (8 instances). A solution to 5.3. SCALABILITY AND PERFORMANCE 59 this could be to sort the instances in a front-to-back order and draw separately (instead of GPU instanced) every instance with the goal of benefiting from the depth buffer that the previous rendered instance will have written into, so that occluded fragments can be discarded instantly. In this case, the overdraw happens as well in the basic and enhanced PBR, but since there is an increase in screen occupancy and number of lights as well, the performance scaling factor with respect to the baseline measure is lower than in the proposed model. The next step to improve the scaling in the proposed framework would be to implement a proper LODding mechanism, not in the hair geometry, since the vertex throughput is not the bottleneck in this case, but in the shading model instead, so that if an instance is far enough, a simplified model (or even the basic PBR introduced in this section) could be used. Figure 5.6: Output visualization of experiment with 8 hair instances occupying most part of the viewport and 2 discrete light sources. Chapter 6 Conclusions In this work, a new framework for real-time hair rendering has been proposed as a combination of solutions for the different challenges discussed in the introduction. I briefly recall them here, with the solutions proposed. Light scattering in single hair strands is solved with an approximation of previous physically-based models introduced in the film industry. This approximation is decomposed into several components accounting for the contribution of each light path at a strand level, where each piece has been defined based on the current real-time physically-based hair rendering state-of-the-art. The contribution of this work is to put together the best option for each component from the set of real-time references, where best is considered in terms of quality-performance ratio. Hair self-shadowing is performed efficiently with an extension of current shadow mapping techniques, and similarly for blending. Traditional techniques cannot be used because we need to account for a continuous and soft attenuation inside the hair volume. Finally, global scattering inside the hair volume is accounted as a constant ambient contribution, which has been observed to be a reasonable simplification qualitatively. The proposed solution is able to render multiple hair instances in real-time, with similar quality to the state-of-the-art on interactive hair visualization. Despite this, there exist multiple areas of improvement; A proper LODding system on the shading complexity (not the geometry) would allow to display a higher number of hair instances on screen with similar perceived quality. Furthermore, self-shadowing and global scattering in hair could be solved with volumetric approaches. Experiments with such techniques would be needed, but these could 60 Conclusions 61 potentially lead to a better performance at the cost of a higher GPU memory footprint (assuming a full GPU implementation). Also, blending could be improved with alpha to coverage or a proper order-independent transparency implementation. Apart from combining previous existing methods for hair rendering, this work introduces a framework for easier inspecting and interacting with the outcome. It contains a proper user interface so that the parameters input into the model can be modified interactively. Furthermore, it is modular, allowing for quickly enabling, disabling, or weighting each component involved in the model. This has permitted to perform proper comparisons and visualize efficiently the contribution of each component. It is important to mention that the development of this framework has involved a significant amount of time, reducing the time available for the actual hair model implementation. Despite this, the fact of having a framework allows to work on the actual models faster, in a more scalable way, and easier to extend. It also increases intelligibility and replicability. The framework has been developed in O3DE, an emergent promising opensource 3D engine, but it is worth to mention that currently it is not as stable and performant as other options available, therefore a small plus of performance could be expected (as of today) from porting the framework to other engines. Appendix A O3DE Background O3DE is an emerging open-source 3D engine. In this appendix, a set of slides are attached presenting the basic workflow of the engine and its rendering pipeline in a visual way. Afterwards, a document summarizing the components of O3DE’s renderer Atom is presented, including how the pipeline and hardware interface work internally and an overview of the pass system, based on the talk Atom Deep- Dive from O3DECon 2021. A.1 O3DE Basics 62 O3DE basics O3DE Features - Open source - Modularity → Gems: modules that contain libraries, interfaces, assets… - Entity Component System (ECS) - PBR (Atom) - Logic → Script Canvas (visual scripting tool) or Lua. - Physics simulations - Networking - Data-driven asset workflows and asset handling - Supports Windows, Linux, MacOS and can target Android and iOS too A.1. O3DE BASICS 63 Editor overview Structure of project runtimes in O3DE [source] A.1. O3DE BASICS 64 Bibliography [Bri16] Brian Karis. Physically Based Hair Shading in Unreal. Siggraph, 2016. [CBTB16] Matt Jen Yuan Chiang, Benedikt Bitterli, Chuck Tappan, and Brent Burley. A Practical and Controllable Hair and Fur Model for Production Path Tracing. Computer Graphics Forum, 35(2):275–283, May 2016. Publisher: John Wiley & Sons, Ltd. [DFH+11] Eugene D’eon, Guillaume Francois, Martin Hill, Joe Letteri, and Jean- Marie Aubry. An Energy-Conserving Hair Reflectance Model. Eurographics Symposium on Rendering, 30(4), 2011. [Gol17] Ben Golus. Anti-aliased Alpha Test: The Esoteric Alpha To Coverage, 2017. [KN01] Tae-Yong Kim and Ulrich Neumann. Opacity Shadow Maps. In Steven J. Gortler and Karol Myszkowski, editors, Rendering Techniques 2001, pages 177–182. Springer Vienna, Vienna, 2001. Series Title: Eurographics. [MJC+03] Stephen R Marschner, Henrik Wann Jensen, Mike Cammarano, Steve Worley, Worley Laboratories, and Pat Hanrahan. Light Scattering from Human Hair Fibers. 2003. [PHVL15] Leonid Pekelis, Christophe Hery, Ryusuke Villemin, and Junyi Ling. A Data-Driven Light Scattering Model for Hair. 2015. [PJH16] Matt Pharr, Wenzel Jakob, and Greg Humphreys. Physically Based Rendering: From Theory to Implementation. Morgan Kaufmann, September 2016. Google-Books-ID: iNMVBQAAQBAJ. [RSC87] William T. Reeves, David H. Salesin, and Robert L. Cook. Rendering antialiased shadows with depth maps. In Proceedings of the 14th annual 71 BIBLIOGRAPHY 72 conference on Computer graphics and interactive techniques, SIGGRAPH ’87, pages 283–291, New York, NY, USA, August 1987. Association for Computing Machinery. [RZL+10] Zhong Ren, Kun Zhou, Tengfei Li, Wei Hua, and Baining Guo. Interactive Hair Rendering Under Environment Lighting. page 8, 2010. [Sch94] Christophe Schlick. An Inexpensive BRDF Model for Physically-based Rendering. Computer Graphics Forum, 13:233–246, 1994. [Taf19] Sebastian Tafuri. Strand-based Hair Rendering in Frostbite. 2019. [Tok18] Kirill Tokarev. Creating Hair for Real-Time Game Characters, January 2018. [Wei06] Xue Wei. What is human hair? a light and scanning electron microscopy study, 2006. [WM17] Chris Wyman and Morgan McGuire. Hashed alpha testing. In Proceedings of the 21st ACM SIGGRAPH Symposium on Interactive 3D Graphics and Games, pages 1–9, San Francisco California, February 2017. ACM. [YJR17] Ling Qi Yan, Henrik Wann Jensen, and Ravi Ramamoorthi. An efficient and practical near and far field fur reflectance model. ACM Transactions on Graphics (TOG), 36(4), July 2017. Publisher: ACM PUB27 New York, NY, USA. [YK08] Cem Yuksel and John Keyser. Deep Opacity Maps. Computer Graphics Forum, 27(2):675–680, April 2008. [YSJR17] Ling Qi Yan, Weilun Sun, Henrik Wann Jensen, and Ravi Ramamoorthi. A BSSRDF model for efficient rendering of fur with global illumination. ACM Transactions on Graphics, 36(6), November 2017. Publisher: Association for Computing Machinery. [YTJR15] Ling-Qi Yan, Chi-Wei Tseng, Henrik Wann Jensen, and Ravi Ramamoorthi. Physically-accurate fur reflectance: modeling, measurement and rendering. ACM Transactions on Graphics, 34(6):1–13, November 2015. BIBLIOGRAPHY 73 [ZYWK08] Arno Zinke, Cem Yuksel, Andreas Weber, and John Keyser. Dual scattering approximation for fast multiple scattering in hair. In ACM SIGGRAPH 2008 papers on - SIGGRAPH ’08, page 1, Los Angeles, California, 2008. ACM Press.