• No results found

Evaluation of Hair Modeling, Simulation and Rendering Algorithms for a VFX Hair Modeling System

N/A
N/A
Protected

Academic year: 2021

Share "Evaluation of Hair Modeling, Simulation and Rendering Algorithms for a VFX Hair Modeling System"

Copied!
63
0
0

Loading.... (view fulltext now)

Full text

(1)LiU-ITN-TEK-A--11/002. Evaluation of Hair Modeling, Simulation and Rendering Algorithms for a VFX Hair Modeling System Vilhelm Hedberg 2011-01-26. Department of Science and Technology Linköping University SE-601 74 Norrköping , Sw eden. Institutionen för teknik och naturvetenskap Linköpings universitet 601 74 Norrköping.

(2) LiU-ITN-TEK-A--11/002. Evaluation of Hair Modeling, Simulation and Rendering Algorithms for a VFX Hair Modeling System Examensarbete utfört i medieteknik vid Tekniska högskolan vid Linköpings universitet. Vilhelm Hedberg Handledare Jonas Unger Examinator Jonas Unger Norrköping 2011-01-26.

(3) Upphovsrätt Detta dokument hålls tillgängligt på Internet – eller dess framtida ersättare – under en längre tid från publiceringsdatum under förutsättning att inga extraordinära omständigheter uppstår. Tillgång till dokumentet innebär tillstånd för var och en att läsa, ladda ner, skriva ut enstaka kopior för enskilt bruk och att använda det oförändrat för ickekommersiell forskning och för undervisning. Överföring av upphovsrätten vid en senare tidpunkt kan inte upphäva detta tillstånd. All annan användning av dokumentet kräver upphovsmannens medgivande. För att garantera äktheten, säkerheten och tillgängligheten finns det lösningar av teknisk och administrativ art. Upphovsmannens ideella rätt innefattar rätt att bli nämnd som upphovsman i den omfattning som god sed kräver vid användning av dokumentet på ovan beskrivna sätt samt skydd mot att dokumentet ändras eller presenteras i sådan form eller i sådant sammanhang som är kränkande för upphovsmannens litterära eller konstnärliga anseende eller egenart. För ytterligare information om Linköping University Electronic Press se förlagets hemsida http://www.ep.liu.se/ Copyright The publishers will keep this document online on the Internet - or its possible replacement - for a considerable time from the date of publication barring exceptional circumstances. The online availability of the document implies a permanent permission for anyone to read, to download, to print out single copies for your own use and to use it unchanged for any non-commercial research and educational purpose. Subsequent transfers of copyright cannot revoke this permission. All other uses of the document are conditional on the consent of the copyright owner. The publisher has taken technical and administrative measures to assure authenticity, security and accessibility. According to intellectual property law the author has the right to be mentioned when his/her work is accessed as described above and to be protected against infringement. For additional information about the Linköping University Electronic Press and its procedures for publication and for assurance of document integrity, please refer to its WWW home page: http://www.ep.liu.se/. © Vilhelm Hedberg.

(4) Abstract Creating realistic virtual hair consists of several major areas: creating the geometry, moving the hair strands realistically and rendering the hair. In this thesis, a background survey covering each one of these areas is given. A node-based, procedural hair system is presented, which utilizes the capabilities of modern GPUs. The hair system is implemented as a plugin for Autodesk Maya, and a user interface is developed to allow the user to control the various parameters. A number of nodes are developed to create effects such as clumping, noise and frizz. The proposed system can easily handle a variety of hairstyles, and pre-renders the result in real-time using a local shading model.. 1.

(5)

(6) Acknowledgments I would like to thank my supervisor Fredrik Lims¨ater and my mentor Mattias Lagergren for the help and support at Fido.. 3.

(7)

(8) Contents 1 Introduction 1.1 Background 1.2 Company . 1.3 Motivation 1.4 Aim . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. 1 1 1 1 2. 2 Background Survey 2.1 Styling . . . . . . . . . . . . . . . . . . . 2.2 Dynamics . . . . . . . . . . . . . . . . . 2.2.1 Single strand dynamics . . . . . 2.2.2 Global hair dynamics . . . . . . 2.2.3 Collision handling . . . . . . . . 2.3 Rendering . . . . . . . . . . . . . . . . . 2.3.1 Shadows and Transparency . . . 2.4 Graphics hardware . . . . . . . . . . . . 2.4.1 The CUDA programming model. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. . . . . . . . . .. 3 4 7 7 9 10 10 11 13 14. 3 Implementation 3.1 Styling . . . . . . . . . . . . . . . . . . 3.1.1 Interpolation . . . . . . . . . . 3.1.2 Frizz . . . . . . . . . . . . . . . 3.1.3 Length . . . . . . . . . . . . . . 3.1.4 Cut . . . . . . . . . . . . . . . 3.1.5 Noise . . . . . . . . . . . . . . 3.1.6 Clump . . . . . . . . . . . . . . 3.2 Dynamics . . . . . . . . . . . . . . . . 3.2.1 Length preservation . . . . . . 3.2.2 Angle preservation . . . . . . . 3.2.3 Collisions . . . . . . . . . . . . 3.3 Rendering . . . . . . . . . . . . . . . . 3.3.1 The Kajiya-Kay shading model 3.3.2 The Marschner shading model 3.3.3 Marschner table generation . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. . . . . . . . . . . . . . . .. 17 17 17 22 23 24 25 26 26 27 27 28 29 29 30 35. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. . . . .. 5. . . . .. . . . .. . . . .. . . . .. . . . . . . . . . . . . . . ..

(9) 6. Contents. 4 Results 4.1 Modeling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.2 Dynamics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4.3 Rendering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 37 38 39 40. 5 Conclusion 5.1 Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5.2 Future work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .. 45 45 46. A Computation of B-spline basis function without recursion using CUDA 53.

(10) Chapter 1. Introduction 1.1. Background. Realistic hair is a fundamental part of making a character look good when creating virtual humans or creatures. Creating and rendering hair has been a challenge from the dawn of computer graphics, and many different approaches has been proposed depending on different demands and conditions. The major problems in creating virtual hair lie in creating the hairstyle, simulating the movement of the hair, and rendering the final result. Each one of these areas has its own problems and solutions of which I will describe in detail in this report. As of today, hair in computer graphics is a rather immature subject in which there exists many different solutions for the same problems, each with its own advantages and disadvantages. A few commercial packages for hair modeling and animation exist, but the need for flexibility and performance has lead to several companies in the industry to use in-house developed frameworks for hair modeling and animation.. 1.2. Company. Fido Film AB is a visual effects and animation studio that works on both feature films and commercials. A major part of the work being done at Fido involves hair of some kind, either on animals or humans. Fido currently uses a commercially available hair system, but due to performance of the rendering and a demand for faster workflow, an tool developed in-house is desired.. 1.3. Motivation. A complete hair system consists of several parts, these are modeling, animation, and rendering. Currently, Fido uses the software Shave and a Haircut, which according to Chang et al. [2002] was considered the best commercial hair modeling and simulation software in the industry. Chang et al. [2002] also pointed out that Shave and a Haircut’s single strand dynamics did not look realistic and the package 1.

(11) 2. Introduction. did not account for hair-hair interactions. In addition to that, when rendering using Shave each single hair strand is saved on disk for each frame. Since a human head has around 100 000 hair strands, the disk space Shave and a Haircut uses is large. For example, a scene with a few animals can easily consist of of several millions of hair strands, and occupy several gigabytes (GB = 1 073 741 824 bytes) of hard disk space, which puts the network and harddrives under heavy load. New possibilities to get a faster workflow in modeling hair have become available as the graphics processing units of modern computers have become more powerful, and easier to use for general purpose programming tasks. This have recently been explored for real-time simulation of hair [Yuksel and Tariq 2010] and could be used to facilitate the modeling process.. 1.4. Aim. The main goal of this project is to create a hair system which is procedural and is able to generate hair strands on the fly when rendering the hair. This would reduce storage requirements and thus lessen the pressure on the hardware of the rendering system at Fido. The other aim is to create a better and faster workflow for the artists when creating the hairstyle through real-time preview rendering, and through a flexible system to control the parameters. The implementation will be based on a survey over existing techniques in modeling, animation and rendering of hair and fur. The final rendering of hair is today being done at Fido by the Renderman renderer and integrating the proposed hair system with the render pipeline is not in the scope of this thesis..

(12) Chapter 2. Background Survey Creating hair for visual effects usually consists of three parts; modeling, animating and rendering the hair. Here, an overview of the current techniques in each one of these areas will be given. Hair styling is the generation of hair strands on the scalp, and the placement and shape of the hair geometry. Animation or dynamics of the hair is the way the hair is moved to produce a motion resembling real hair. Animation also consists of handling collisions between hair and other objects as well as the hair with itself. Finally, rendering is the procedure of producing the final color and shadows of the hair strands and many of the problems when rendering the hair lies in the thin nature of each strand. When comparing different techniques, Ward et al. [2007] used the following questions for analysing the methods in the different categories: • Hair Shape : Can the method handle long, curly or wavy hair or is it limited to simpler short, straight styles? • Hair Motion : Is the method robust enough to handle large, erratic hair motion that can cause dynamic grouping and splitting of hair clusters as well as complex hair collisions? • Performance vs. Visual Fidelity : Is the primary focus of the method to model visually realistic hair, to model hair quickly and efficiently, or to offer a balance between performance speed and visual fidelity of the virtual hair? • Hardware Requirements : Does the method rely on specific GPU features or other hardware constraints or does it have cross-platform compatibility? • User Control : To what degree does the user have control over the hair? Is the control intuitive or burdensome? • Hair Properties : Can the method handle various hair properties (e.g. coarse vs. fine, wet vs. dry, stiff vs. loose) and allow for these values to vary on the fly throughout the application? 3.

(13) 4. Background Survey. As noted by Ward et al. [2007], existing methods typically have strengths in one of these areas but is weaker in others. For this thesis, it has not been an issue if the method is hardware dependent or not, and the main goal has been to develop a procedural system where the user has a high degree of control over the hair, based on intuitive building blocks for creating the desired hairstyle.. 2.1. Styling. As previously stated, hair styling is the process of creating the geometry of the hair. In real life, hair can have many different shapes and styles. Hair can be categorized into three main types: Asian hair, African hair and Caucasian hair [Ward et al. 2007]. Asian hair is regular and straight whereas African hair is irregular and curly. Caucasian hair is usually somewhere in between the two others. Some methods are more suitable than other for styling a wider range of hair categories, but they have usually required more manual work to achieve the desired hairstyle. Ward et al. [2007] categorized the styling process into three steps; attaching the hair to the scalp, generating the global hair shape, and managing finer hair properties. The first step in which hair is attached to the scalp has usually been carried out by creating a scalp space, where a 2D surface is mapped onto the 3D surface of the head. Different mappings create different distortions of the map when placed on the 3D surface. This can lead to an uneven distribution of the generated hair strands. Some proposed mappings are spherical mapping [Rosenblum et al. 1991; Yu 2001], a wrapped Catmull-Rom spline patch [Kim and Neumann 2002] and harmonic mapping [Bando et al. 2003]. Different methods use different ways of generating interpolated hair strands on the surface, as described in the survey by Ward et al. [2007]. The second step, which is to generate the global hair shape, has been done in many different ways. Several authors created the hair from either a surface or a volume created out of polygons or non-uniform rational B-spline (NURBS) curves or surfaces; Liang and Huang [2003], and Noble and Tang [2004] created a surface based on NURBS patches, Yuksel et al. [2009] created the hairstyle based on a polygonal mesh, which had topological restrictions which the authors used to determine the final hair look. A popular method introduced by Watanabe and Suenaga [Watanabe and Suenaga 1992] is to create the final hairstyle from a number wisps. The wisps are controlled on an individual level, and the final hair strands are interpolated based on the positions and geometry of the wisps. Kim and Neumann [2000] developed the so called Thin Shell Volume model that creates the hairstyle based off a nurbs patch containing the hair volume. Generalized cylinders have also been used to represent wisps that form the hair, and was introduced by Yang et al. [Yang et al. 2000]. Ward et al. [2003] has demonstrated that it is possible to move between several representations of the hair in one application. The hair in their application is represented as either hair strips, wisps or as single strands. This provides flexibility between computational requirements and visual appearance. Choe and Ko [2005] used the wisp based model together with a styling force field to create.

(14) 2.1 Styling. 5. constraints, to be able to deform the hair into several interesting hairstyles such as braids and hairpins etc. Yu [2001] also used the idea of a vector field to produce a global hair flow, combined with local procedural vector field primitives to give local control to create curls and waves in the hair. A multiresolution method where each generalized cylinder can have several smaller child cylinders was introduced by Kim and Neumann [2002]. This method defines a generalized cylinder GC with a skeleton curve and a set of contours along the curve as: GC(θ, t) = C(t) + R(θ, t). (2.1). where C(t) is the contour curve, θ is the angle around the principle axis along the curve, and R(θ, t) is the radius at each point and angle along the curve. To allow for more control they added a number of parameters to the radius function as follows: • A scalar value r to control the radius from the curve. • Sn (t) and Sb (t) to control the scale of the cylinder in the normal (N (t)) and binormal (B(t)) directions on the curve. • W (t) to represent the curliness or twist along the strand. The final representation of the cylinder then becomes: ˆ = θ + W (t) θ(t) ˆ N (t)N (t) + sin(θ)S ˆ B (t)B(t)) V (t) = C(t) + rR(θ, t)(cos(θ)S. (2.2). A graphical representation of the multiresolution method is shown in figure 2.1. Kim and Neumann [2002] then divided the hair using this formula into clusters which are defined relative to their parent, where the root clusters are defined. This method of creating a hairstyle has the advantage of letting the user edit properties of the hair at different detail levels, but also the advantage to let the user copy and paste properties from one cluster at any level to another cluster. There are also several other methods for generating the geometry of the hair [Waiming and Masayuki 1998-09-20; Grabli et al. 2002; Paris et al. 2004; Wei et al. 2005], such as using one or several images to generate hair strands, or using a sketch based interface to model the hairstyle [Mao et al. 2005]. These different ways of generating hair geometry all have their strengths and drawbacks. The main concern in the production of feature films and commercials is a high degree of users control as well as the possibility to create realistic hairstyles, whereas in games the primary goal is interactive speed, thus simplicity of the hair is often crucial. Ward et al. [2007] presented table 2.1 which compares different methods for generating hair geometry. Managing finer hair properties is a task where procedural methods are used due to the sheer amount of manual work otherwise. Yu [2001] generated random curliness using an offset function, in a similar fashion to Kim and Neumann’s [2002] curliness function. To modulate a hair strand from the root to the top, using either Kim and Neumann’s or Yu’s technique, the local coordinate frame (formed by the.

(15) 6. Background Survey. Figure 2.1. Graphical view of the multiresolution model by Kim and Neumann [2002].. normal N , tangent T , and binormal BN ) at each point along the curve must be known. Kim and Neumann [2002] used a Catmull-rom interpolation which has a defined coordinate frame along the curve, whereas Yu [2001] used the vector between the point p and the scalp centroid as an UP vector to create a coordinate frame in which to apply the offset function. To avoid hair strands looking too similar to each other, Yu [2001] created a smoothly varying Perlin noise as a parameter to the offset function to achieve a more natural appearance. Choe and Ko [2005] synthesized a subset of the total strands based of a prototype strand, by an example-based Markov chain model. Then they copied the synthesized strands styles with statistical variations into neighboring strands. Choe and Ko [2005] also took collisions and gravity into account when generating the hairstyle.. Table 2.1. Analysis of global shaping methods.. Generalized Cylinders Surfaces Physical Volymes Photos Sketches. Hair Shapes flexible limited to straight limited. details hard limited. must exists limited. details hard. User Control high high cumbersome none medium. Manual Time slow fast medium fast fast.

(16) 2.2 Dynamics. 2.2 2.2.1. 7. Dynamics Single strand dynamics. An important factor, especially for the production of feature films, is the ability to create a realistic motion of the hair of a creature or human. Simulating hair motion is also one of the most difficult parts of creating a plausible virtual character. Mainly because the sheer number of individual hair strands typically on a human head (> 100000) leads to a large complexity if all hair strands are to be simulated. Adding to that, each strand has a complex nonlinear behaviour [Bertails et al. 2006] related to its natural shape such that complex models must be used to achieve a natural motion. A hair strand can easily bend and sometimes twist, but resists shearing and streching [Ward et al. 2007]. A hair strand also tends to recover to its original shape after it has been offset. The movement of hair has a collective behavior and the interaction between hair strands is another difficult problem. Another important factor regarding the movement of hair is the influence of curls which increases the tangles between hair strands and thus the computational cost for collisions. The dynamics of rods and similar structures have been extensively studied in the field of mechanics and robotics and several mechanical models exists, but there have not been any studies regarding the movement of hair, individual strands, or the collective behavior of the hair. Research has been made regarding the structure and dynamic properties of the hair [Robbins 2002], although not for the purpose of simulating a virtual hairstyle. Thus, hair simulation has so far remained an open problem, and no standard simulation model has been widely accepted [Bertails et al. 2006]. Instead, the problem has been to find the best model for ones purpose. Rosenblum et al. [1991] and Anjyo et al. [1992] presented the first attempts to simulate individual hair strands using a mass spring model and projective dynamics on links forming the hair strand. These methods are simple which is an advantage when it comes to the possibility of simulating a large amount of hair strands, but both of them have the disadvantage of not accounting for torsion or self-collisions between hair strands. However, Anjyo et al.’s [1992] method has the advantage of the hair being able to resist bending since the dynamics are expressed in projected angles. The disadvantage of this model is that external forces only can propagate to subsequent links, something that Lee and Ko [2001] worked around by adding an extra force to previous links. A successful model for hair simulation is to simulate the hair as a serial rigid body chain which first was presented by Hadap and Magnenat-Thalmann [2001], although the technique already existed in the field of robotics [Ward et al. 2007]. Chang et al. [2002] used this model and added spring forces for hair-hair interactions. Hadap [2006] further developed this model by adding analytical constraints in an elaborate collision response model and by generalizing the formulation to an open-chain multi-body system, which is simulated with an implicit and fully recursive scheme using Differential Algebraic Equations (DAE). Since it is a fully implicit model, stability is one obvious advantage. Other useful additions made by Hadap [2006] were the introction of posable dynamics, where a moving target.

(17) 8. Background Survey. position can be strived for during the simulation, and the so called local time scale, where a time scale factor is introduced to control the amount of energy entered into the system. The latter could be very useful for feature films where characters often are animated to not have physically correct movement, which otherwise would cause the hair system to move unrealistically or to cause the simulation to become unstable. As noted by Hadap [2006], this method does have some disadvantages. It is computationally expensive and would not scale well to perform a full fur simulation. Developing and implementing constraints and collisions is not as straightforward as compared to Choe et al. [2005]. The solving of the DAE:s in Hadap [2006] was done with a free software called DASPK1 which is written in FORTRAN. If another language such as C++ is used, either an interface between the FORTRAN software and the C++ hair system solver must be created, or another software for solving the DAE:s has to be used. Writing a robust DAE solver from scratch is also an option, but for this project not feasible. A model was presented by Bertails et al. [2006] which is built upon the Kirchoff theory for elastic rods which accurately predicts the movement of hair strands with both a bending and a twisting motion. The model, called dynamic Super-Helices, represents each strand as a piecewise helical rod, which means that each section of the rod has a constant curvature and twist. The resulting rod has a limited number of degrees of freedom, depending on the number of elements in each rod. Even so, the model can more accurately describe the motion better than previous models, and by increasing the number of segments, the fidelity of the animation is improved. The Super-Helix is simulated using Lagrangian dynamics which accurately accounts for the non-linear behaviour of hair strands. A limitation of the model is that the solution computation time increases quadratically with the number of elements (O(n2 )). Bertails [2009] later presented a solution in O(n) by using a recursive scheme for the dynamics of the Super-Helices which propagates the inertias along the rod, and in a second reverse pass solves the dynamics of the rod. Another limitation of the Super-Helix model is the lack of hard constraints which can be a requirement for a production-level collision handling system [Bergbom 2007]. Bergbom [2007] argued that since the Super-Helices model had a large implementation complexity and due to the complexity of the math needed for the implementation it had not been widely used in the computer graphics community. The advantage of this model is that it can can simulate the dynamics of curls. A popular model has been the mass-spring model where the hair strand is modeled as particles connected with springs in between them. The bending rigidity of the strand is provided by angular springs at each particle. Selle et al. [2008] presented a method based implicit methods for cloth simulation with the goal of simulating every single strand on the head. They introduced a new concept of altitude-springs which makes it possible to model torsion of the hair stand, thus making it possible to simulate curly hair. The bottleneck of their method, is that each hair strand could collide with any other hair strand, and if the goal is to simulate every single strand (around 100 000) this poses obvious difficulties in terms of performance. In their paper, they used a variant of time integration based of Sifakis et al. [2007], although any standard integration scheme could be 1 http://www.cs.ucsb.edu/. ˜cse/software.html.

(18) 2.2 Dynamics. 9. fitted into their model. Selle et al. [2008] also used a stiction model, to account for the effect of nearby hair strands clumping together, which dynamically creates and removes springs between particles. Bertails et al. [2003] suggested an adaptive method that dynamically changes the resolution of the simulation based on the movement of the hair, such that the hair is represented with finer detail where discontinuous movement occur, and a lower fidelity where a large movement does not occur. They presented the so called Adaptive Wisp Tree which is a treelike control structure that represents the hair through splitting and merging of segments of the tree.. 2.2.2. Global hair dynamics. Often in hair simulation, measures are taken to preserve the volume of the hair to achieve a realistic result. Due to the very high number of interactions between hair strands, methods that interact all hair strands with each other has often been undesirable. Thus several approaches have been developed to manage the volume of the hair without explicitly interacting every single hair strand. When simulating a subset of the hair using guide strands, it is possible to interact those with each other, something Chang et al. [2002] took advantage of when creating dynamic springs between the sparse guide strands, and thus giving the look that the dense interpolated hair had a volumetric interaction. Bertails et al. [2003] represented the adaptive wisp tree with cylinders, which are collided against each other, which has the effect that each cylinder represents some volume of hair. Even though most efforts have been made to avoid colliding each hair strand against all others, Selle et al. [2008] does just that, and their method dynamically creates and breaks springs between nearby hair strands. If two hair strands are closer than a certain threshold, a spring is created that keeps them together (to mimic stiction between hair strands), but also keeps them from getting too close to each other and thus preserving volume of the hair. There are several methods that approximate the hair as a volume, which use techniques found in fluid simulations to preserve hair volume and to avoid the expensive hair-hair interactions. However, all these methods suffer from the drawback that the detail in the interactions is never better then the underlying fluid-like simulation/representation. Hadap and Magnenat-Thalmann [2001] used the SPH (smoothed particle hydrodynamics) method to model the self interactions with spring like forces. This method however, is effectively as expensive as regular spring forces between the strand particles [McAdams et al. 2009]. Petrovic et al. [2006] solved the problem of hair-hair interaction by grouping particles and their velocities into a 3D voxel grid, where each voxel grid value was the average velocity of all hair particles in that grid cell. They then created forces based on the derivatives of the density to move a level set, which was used for the rendering and shading of the hair. Forces were also added based on a desired target shape of the hair, thus enabling artist control over the dynamics simulation, which can be desirable in certain conditions. This method is limited by its grid resolution and the averaging of the velocities that is done, but its intended application was creating stylized characters where a loss of detail was acceptable. A hybrid method was later proposed by.

(19) 10. Background Survey. McAdams et al. [2009], which handles the large scale interactions and volume of the hair by an Eulerian grid FLIP solver (the interested reader is referred to Zhu and Bridson [2005] for a description), but the small scale details of hair clumping and collision with a Lagrangian approach.. 2.2.3. Collision handling. In order to create a convincing result of the hair movement, a robust collision handling scheme with other objects in the scene must be implemented. Hair to hair interactions methods are described in section 2.2.2 and only collisions with objects will be discussed in this section. Collision detection is a very large topic, with whole books dedicated to the subject [Ericson 2005]. Ericson [2005] formulates the problem of collision detection as “determining if, when and where two objects come into contact”. In general, a collision handling scheme for a hair simulation first determines the places where contacts occur. This depends on the representation of the hair strands. Then, it has to determine how to correct the positions, velocities and accelerations of the hair strands (and other objects) to prevent the objects from intersecting each other. Chang et al. [2002] solved this by intersecting each hair vertex with the human head and torso and if a collision was detected, setting the velocity to the same velocity as the surface, while the other vertices were allowed to move freely. Any acceleration towards the body was also removed. In their model, the body was modeled as a triangular mesh and any standard method for intersecting points with triangles could be used. For a thorough description of intersection tests, the reader is referred to Ericson [Ericson 2005, Ch. 5]. To avoid the tip of the hair intersecting the surface, Chang et al. [2002] used a simple iterative method, which corrects the length of the vector between the current vertex and the next, after correcting the current position. This is done by moving the next vertex to ensure that the vector has the same length as before the correction. Bertails et al. [2003] represented the character with bounding spheres, which the intersections were made against. The method of approximating the collision object using simpler primitives such as spheres has also been used in the Nalu demo [Pharr and Fernando 2005, Ch. 23], for its speed and simplicity. Selle et al. [2008] solved the problem of hair-object intersection by creating a level set signed distance field which is negative inside and positive outside the intersecting object. They used the method proposed by Bridson et al. [2005] to treat collisions and friction, which restrict the particles normal velocity relative to the surface, to avoid collision. Apart from the described methods above, a general collision method described by Schwarts and Seidel [2010], is to render the collision objects into a voxel grid, so that a comparison of the voxels can determine any collisions between two objects. This could easily be adapted to perform hair to object collisions (as will be described in section 3.2.3).. 2.3. Rendering. When rendering hair, the local reflections of a single hair strand as well as the global lighting effects has to be taken into account. The global effects include.

(20) 2.3 Rendering. 11. shadows, transparency and multiple scattering. The diffuse color from multiple scattering is often approximated using a local model. For this thesis, focus has been on the local reflection model, and only a short summary will be given on shadows and transparency. An early model, although still popular, is the so called Kajiya and Kay model [Kajiya and Kay 1989], which was developed for rendering fur with three dimensional textures. This method will be described in detail in section 3.3.1. Marschner et al. [2003] later proposed a improved method for rendering hair, which was based on observations and measurments made on hair fibers. They observed significant effects which not accounted for in the Kajiya and Kay model. The most important difference was to account for the variations when observing a fiber from different angles, in the same normal plane. Since Caucasian and African hair fibers are not cylindrical but rather have an oval cross section, the way light rays are reflected and refracted is affected [Bertails et al. 2006]. Since Marschner et al. [2003] used observations when creating their method, it better matches the scattering observed in real hair, and gives a more realistic result compared to photographs. This method will be described in detail in section 3.3.2.. 2.3.1. Shadows and Transparency. (a) Opacity Shadow Maps. (b) Deep Opacity Maps. Figure 2.2. Opacity Shadow Maps use regularly spaced planar layers where Deep Opacity Maps use fewer layers shaped after the model.. Self-shadowing is an important part of rendering hair. Each hair fiber casts shadows on other strands and other objects in the scene. The complex nature of a hairstyle, makes it hard to use traditional shadow mapping techniques. Ward et al. [2007] identified two main groups of methods that have been proposed to solve the shadowing problem; shadow maps, and ray-casting through a density grid. Kajiya and Kay [1989] used volume textures, containing texels, against which light rays were intersected, to realistically render the hair. In general, the different shadow map methods render a shadow, or opacity map, for each light, which is later used to perform a lookup if the hair strand is occluded or not..

(21) 12. Background Survey. In the method by Bertails et al. [2005], a light-oriented density voxel-grid stores the light attenuation across the hair volume. Thus a simple grid lookup can be performed to find the attenuation at each fragment. The quality of this method however depends on the grid resolution and needs filtering to remove rendering artifacts. The problem with using regular shadow maps is that they often have a limited depth resolution and they use a binary decision whether a fragment is in shadow or not, and thus causes severe artifacts unless a very high depth accuracy is used. Lokovic and Veach [2000] presented a method called Deep Shadow Maps that, instead of storing a binary depth at each pixel, stores a fractional visibility at multiple depths at each pixel. Since a depth map increases linearly in size with the number of layers in it, they use a compressing technique to approximate the fractional visibility in fewer layers. Attempts have also been made to speed up the visibility function creation by using a density map rasterized in real-time [Mertens et al. 2004]. Kim and Neumann [2001] proposed a map that instead of storing fractional visibility depth, stored the alpha values along the rays from the light source at a number of planes and interpolating from those. This in comparison to the deep shadow maps which stores the fractional visibility function as a piecewise linear function. The opacity shadow maps have been shown to be able to efficiently be rendered and created using graphics hardware [Kim and Neumann 2001]. Yuksel and Keyser [2008] have presented a method called deep opacity maps which is a variation of the opacity shadow map, but uses a per-pixel distribution of the different opacity layers. The algorithm is done in two steps. The first step consists of creating the different layers, which is done by rendering a depth map from the light source, which gives the depth value of the first layer z0 , for each pixel. The rest of the hair is divided into a number of layers, where each layer has the same distance from the starting depth value z0 . Each layer has the opacity contribution of all the layers in front of it, as this allows for a fast lookup in the rendering step. The spacing between layers does not have to be uniform. The second step is to fill the layers with the opacities. This is done by rendering the hair one time, and in the fragment shader, performing a lookup of the first map depth z0 , and adding the fragments opacity contribution to all layers at, and behind the current fragment. The rendering can then be done by performing a lookup in the deep opacity map for each fragment to be rendered. Deep opacity maps give a good visual result with significantly fewer layers than opacity shadow maps. The main advantage of the method is that the layers are shaped according to the hair and thus fewer layers are needed. A comparison between deep opacity maps and opacity shadow maps are shown in figure 2.2. Apart from the self-shadowing, another important part for creating realistic renderings of hair is the multiple scattering of light. In blonde and light colored hair, this effect contributes a large amount to the overall color of the hair [Moon and Marschner 2006]. As described in section 3.3.2, hair scatters light both forwards and backwards, depending on the number of internal reflections. Since a light ray can bounce around several times through multiple hair strands before reaching the observer, path tracing all rays can take hundreds of hours [Moon and Marschner 2006]. Moon and Marschner [2006] presented a photon mapping method, where photons are emitted from the light sources and deposited along.

(22) 2.4 Graphics hardware. 13. the paths in the hair volume. The rendering is done by computing direct lighting by evaulating the integral in equation 3.17, and the indirect lighting is evaluated by looking up the indirect radiance in the photon map. Later, Moon et al. [2008] improved the photon mapping approach by using spherical harmonics to store the directional distribution of the scattered radiance in the hair volume. First the light paths are traced and powers are contributed along the traced path to a 3d grid of spherical harmonics coefficients. Secondly, when rendering, the multiple scattering contribution can be computed by integrating the radiance from the grid with the bidirectional scattering distribution function (BSDF) by an efficient matrix multiplication method. Multiple scattering has also been approximated by a dual scattering method [Zinke et al. 2008], which simplifies the scattering model as a function of global multiple scattering and local multiple scattering. The global scattering computes the irradiance arriving around a point in the hair, and the local scattering approximates the scattering of that irradiance in the neighborhood of that point. Sagedhi and Tamsdorf [2010] explained the implementation details to effectively implement the Dual scattering model in RenderMan, which was later used as a foundation for their Artist Friendly Hair Shading System [Sadeghi et al. 2010]. Since hair fibers are very thin, a human hair strand is about 0.1 mm in diameter, rendering hair is very prone to aliasing effects, due to the size of the hair strand compared to the size of each pixel. In offline rendering, this can be solved by adding more samples per pixel, which gives a smoother look to the result. In real-time rendering, traditionally this has been solved in the same way by using multi-sampling anti-aliasing, which takes several samples per pixel to render. Different graphics chip manufacturers has presented different sampling techniques to reduce aliasing, Supersampled anti-aliasing, which renders the scene in a larger resolution and then downsamples the resulting image, multisampled antialiasing (MSAA) as mentioned, Intel has presented a method called Morphological Anti-Aliasing [Reshetov 2009] which anti-aliases the scene as a post-processing effect, and NVIDIA has presented a method called Coverage Sampling Antialiasing (CSAA) [Young 2007] which decouples the coverage of each sample from the color, depth and other buffers.. 2.4. Graphics hardware. In the last decade, tremendous progress has been made in making the graphics processing units (GPU:s) more programmable. NVIDIA’s CUDA programming model aims to make it possible to perform general purpose computing on the graphics hardware, to enable computationally intensive algorithms to be parallelized in a straightforward way. The graphics processing unit can today be seen as a many core processor with an enormous computing power. The GPU performs single instructions on multiple data (SIMD). Thus, the GPU is suitable for algorithms that perform the same computations on different data, so called dataparallel computations. Even though the GPU today has passed the CPU in terms of raw computing power, most programs still perform some sequencial operations.

(23) 14. Background Survey. which can be a problem when utilizing the GPU for computations. A naive GPU implementation can sometimes be slower, or as slow as a CPU version despite the higher computing performance. The CUDA parallel programming model has been designed to have a low learning curve for programmers familiar to the C programming language, and to overcome the challenge to program applications scalable with an increasing number of processors.. 2.4.1. The CUDA programming model. Figure 2.3. Grid of thread blocks in the CUDA programming model.. To achieve a system that is on one hand controllable, and on the other hand scalable as new processors with an increasing number of cores are developed, the CUDA programming model has three main abstractions; a hierarchy of thread groups, shared memories, and barrier synchronization. The hierarchy of thread groups allows the programmer to divide the problem at hand into smaller pieces that can be solved independently in parallel, and solved in each thread group collaboratively. During the lifetime of an application some functions may be run.

(24) 2.4 Graphics hardware. 15. on the CPU while others are run on the GPU. The threads in a thread group on the GPU are very lightweight, and more importantly, performs the same operations on different data. A thread group is called a block and contains a number of threads as illustrated in figure 2.3. There can be multiple blocks, which forms a grid, in one CUDA program. Each thread runs a specified kernel, which has access to a three dimensional index of its thread. The index is usually used to determine which data the kernel should perform its operations on. While threads in a block are run at the same time, thread blocks are scheduled independently of each other and can be executed in any order. Memory hierarchy CUDA threads can access different types of memory during its execution, each with its own properties. Each thread has its own register, which is small and fast and is used to store variables in the kernel. However, if some variables does not fit in the register, they are stored in a local memory which is slower. The register and local memory is not shared between threads. Threads can also share memory between each other in a block, using the shared memory, which only exists during the execution of the threads in a block, and which only threads in the same block can access. There is also the global memory, which is accessible (read and write) from all kernels. There are also two global read-only memories. The constant memory which is small but provides fast access, and the texture memory which is a fast cached memory which allows hardware interpolation, similar to textures in Direct3D and OpenGL. Sorting and Reduction In this thesis, several nearest neighbor searches needs to be done, for example in the clumping node (see section 3.1.6). On the CPU there are several spatial data structures one could use to speed up the naive approach (O(n2 )), such as grids, Kd-trees, octrees etc. The common approach when creating a spatial data structure in CUDA is to create a hash grid, which is then sorted. The sorted hash grid then allows for a fast nearest neighbor lookup, by performing a lookup in the grid cells neighboring the point of interest. If a lookup is performed in the 26 nearby grid cells plus the grid cell of interest, the cell size affects how far away the nearest neighbor can be found. Usually a fixed cell size is used. If the grid extent is variable, the grid size needs to vary. An infinitely large grid size can not be used, so a max size is set. If the grid size exeeds the max size, it is clamped, and the cell size is increased with the consequense that each nearest neighbor lookup needs to test extra points further away then the area of interest. How to perform a hash grid based broad phase collision detection using CUDA is described in detail in [Nguyen and NVIDIA 2008, Ch. 32]..

(25) 16. Background Survey. Collision detection When performing collision detection on the GPU, one approach could be to sort the mesh triangles into a hash grid, and to lookup nearby triangles when detecting collisions among moving points. Another method is to voxelize the triangles into a voxel-grid, and to perform collisions against the voxelized triangles instead. This has the advantage of a constant time to perform the lookup, since each grid cell only has one boolean value. However there is an increased cost for creating the grid, but using graphics hardware, improvements have been made in increasing the speed of the voxelization [Schwarz and Seidel 2010]. The general idea of the voxelization algorithm proposed by Schwarz and Seidel is to test all voxels in the axis-aligned bounding box of each triangle. Since all voxels within the bounding box needs to be tested, this parallelizes effectively. A hair simulation and rendering program performed solely on the GPU was been presented by Pharr and Fernando [2005, Ch. 23]. The program simulates a number of guide strands, which are interpolated and tessellated on the GPU. Collisions in the program are made against a number of spheres approximating the collision object for speed. Using features like programmable tessellation to interpolate hair strands, real-time speeds was achieved..

(26) Chapter 3. Implementation In this thesis, a plugin for Autodesk Maya has been created. The plugin uses CUDA to accelerate computations and to allow the users to see the full hairstyle when working with the hair. The system is procedural and allows for flexibility by using different nodes to affect the hairstyle. The hair is rendered and shaded using OpenGL and GLSL and both the Kajiya-Kay, and Marschner shading models were implemented.. 3.1. Styling. The styling is performed by connecting different nodes to each other in a directed acyclic graph. The nodes take a number of hair strands both as input and output, and thus nodes can be combined in any way desired. Nodes can also generate new hair strands by outputting more hair strands then its input. Each node in the network has a weight map, which controls the amount of modification that each node should perform. Since different nodes have different modifications being made, the weight might have a different interpretation for each node. The node graph is evaluated from the end node, which is set by the user. Each node asks for the input data from the previous node until the first node has been reached, which computes the initial data based on the guide strands. Nodes can also be ignored in which case they just pass the data from the previous node through to the next one. An example of four nodes connected to each other is shown in figure 3.1.. 3.1.1. Interpolation. The most important node in the system is the interpolation node, which generates new hair strands, based on a smaller number of input guide strands. The weight map for the interpolation node modifies the amount of hair that should be placed on the mesh based on the general hair density. The hair density is a setting that controls how many hair strands that should be placed on each area unit on the mesh. The weight map can easily be created in Autodesk Maya with a painting 17.

(27) 18. Implementation. Figure 3.1. Example of nodes connected to each other. The node selected green is the output node.. tool, where the weights are painted directly onto the model. The effect of the interpolation node is shown in figure 3.2. The first part of the interpolation node is to generate points on the mesh where the new hair strands should be grown. Ward et al. [2007] listed many methods for distributing the strand root points based on uv-coordinates, although the results can be non uniform on the mesh if the uv-mapping onto the geometry.

(28) 3.1 Styling. (a) Radius of influence: 0.6. 19. (b) Radius of influence: 1.0. Figure 3.2. Interpolating three guide strands using two different settings.. is distorted. Instead, a simple but effective method to uniformly generate hair strands at random positions is proposed in this paper. The idea is to generate random seed points for each triangle on the mesh, based on the triangle area, and to perform a lookup to get the uv-coordinates, normal and tangent for each generated point. The points on the triangle are generated using rejection sampling to ensure an even distribution. The pseudocode to generate a number of points where the hair is to be grown from is shown in algorithm 1. After the points have been created, the next step of the interpolation is to create the hair strands based on nearby guide curve shapes. In Autodesk Maya, a curve can be represented as a NURBS curve, with a number of control points. Since a NURBS curve can not be rendered in OpenGL, they have to be approximated with a number of line segments. To create a smooth hair strand curve based on the control points of the guide strands, the control points are used to evaluate the guide curves at a discrete number of positions (for this thesis, 32 hair strand points were used with a good result). A NURBS curve is defined as: Pn Ni,p (t)wi Pi C(t) = Pi=0 (3.1) n i=0 Ni,p (t)wi where Pi are the control points, wi are the weights, and Ni,p are the B-spline basis functions based on a knot vector ti provided with the curve. For this application, the weight was set to 1 at all control points since no weights were provided by the curve generated in Autodesk Maya. The B-spline basis function can be defined as a recursive function, which is defined in terms of the knot vector ti , which is a sequence of increasing numbers. The basis function is defined as:  1 if ti ≤ t < ti+1 Ni,0 (t) = 0 otherwise (3.2) t − ti ti+p+1 − t Ni,p (t) = Ni,p−1 (t) + Ni+1,p−1 (t) ti+p − ti ti+p+1 − ti+1 Equation 3.2 can result in a 00 case, which Lavoie [1999] defined to be zero. For this project, a recursive formulation could not be used, since only certain graphics cards have the ability to run recursive functions, and as much compati-.

(29) 20. Implementation. Algorithm 1 function generate points on the mesh(hair density d) for each triangle on the mesh do Compute the triangle area a. Compute the number of strands to be placed on the triangle n = d ∗ a. Intialize generated hair strands counter g = 0 while g < n do Generate two random numbers, a, b ∈ [0, 1]. if a + b < 1 then The generated point is located at au + bv, where u and v are the sides of the triangle. Compute the uv-coordinates, tangent and normal at the generated point on the triangle. Perform a lookup w ∈ [0, 1] in the weight map based on the uvcoordinates found. Generate a random number r ∈ [0, 1]. if r < w then Add the generated poing to a list of hair strands to be generated. end if Increase counter, g + +. end if end while end for. bility as possible was desired for this project. Thus an algorithm for computing the basis function using loops was created which is presented in appendix A.. Figure 3.3. Creating a hair strand based on a nearby guide strand..

(30) 3.1 Styling. 21. After a guide curve has been subdivided into 32 line segments, these are used in the curve interpolation. The positions along the guide strand are used by the to-be interpolated strand to control the shape. To be able to interpolate between nearby guide curves, the guide curve shapes are defined by offsets oi which are defined as: o0 = p0 (3.3) oi = pi − pi−1 where oi denotes the i:th offset along the hair strand, and pi the i:th position along the line. A new hair strand with the same shape at a new position q can then be created as follows: p00 = q (3.4) 0 pi = p0i−1 + oi where p0i are the new positions for the hair strand. To interpolate a hair strand that is to be grown from a seed-point (the generated point on the mesh), first a nearest neighbor search is performed to find all nearby guide strands. The user can control the influence distance of the guide strands. Based on the influence distance (di) a hash grid with a cell size of the same distance is created in CUDA, and the guide strand root positions sorted into it. For each seed-point a weighted interpolation is performed using the offsets from the nearby guide strands. For this thesis a gaussian kernel was used as a weight, although any kernel could be used as a weight. The kernel should have a value of zero at the boundaries and a value of one at the center. A smooth kernel generally gives a smooth looking interpolation between guide strands as shown in figure 3.4. A cutoff is defined as the influence distance, since the gaussian kernel otherwise has an infinite width. The gaussian kernel used in this thesis is defined as: ( (o0 −p0 )2 0 0 ko0 − p00 k < di e− 2σ2 (3.5) w(o0 , p0 ) = 0 otherwise where σ = 0.3di, which gives the function a value of less than 0.004 at the cutoff distance. The weighted interpolation is done by taking the weighted mean of the nearby guide strand offsets. This makes guide strands closer to the current hair strand have a larger influence on it. Weighted mean is defined as: Pn w i xi x ¯ = Pi=0 (3.6) n i=0 wi An interpolated hair strand based on nearby guide offsets (oi,n ) is then defined as: p00 = p0 P p0i = p0i−1 +. nearby guides j P. w(oj,0 , p0 )oj,i. (3.7). nearby guides j w(oj,0 , p0 ). An option is to instead of using the guide strand offsets directly, transform the offsets from the coordinate frame at the guide strand, to the coordinate frame at the generated hair strand. This can be useful if a mesh has a high curvature and the intention is that the hair should vary smoothly with the mesh..

(31) 22. Implementation. (a) Constant kernel.. (b) Linear kernel.. (c) Gaussian kernel.. Figure 3.4. Different weights for interpolating between guide strands.. 3.1.2. Frizz. The frizz node can create curliness on the hair by offseting the positions along the hair strand as shown in figure 3.5. An offset function very similar to the one in Kim and Neumann [2002] is created to alter the strand positions to create a frizz effect. The function is defined as: pi = pi + rN (i) cos(θ(i))Ni + rBN (i) sin(θ(i))BN i θ(i) = wiπ. (3.8). where rN is the radius in the normal direction at the point i along the strand and rBN is the radius in the binormal direction. w is a user controlled frequency parameter, which controls how curly the hair strand will be. The hair strands in this project do not have an analytical definition of the reference frame along the hair strands. This allows for arbitrary changes to a hair strand for each node (the nodes are not required to be defined using curvature and twist as in [Bertails et al. 2006]). Even though not defined analytically, the frizz node has to have a.

(32) 3.1 Styling. 23. Figure 3.5. Example of frizz node.. reference frame at each point along the hair strand to be able to offset the hair strand. For the root position of the strand, the normal (N0 ), tangent (T0 ) and binormal (BN 0 ) are always known. For each position along the hair strand, the tangent (Ti ) can be approximated using first order difference. The tangents are then used to compute a normal direction, but since a line has an infinite number of normal directions, one of the many valid normal directions have to be chosen. In the fashion of Yu [2001], the normals and binormals are computed as: Ni0 = N0 − Ti ∗ (Ti · N0 ) Ni =. Ni0 kNi0 k. (3.9). BN i = Ti × Ni This do not guarantee a continuous twist for the hair strand, but for this application, it gives a reasonable result and gives a large flexibility when designing a new node. After the hair strand has been modified in each node, the tangents are recomputed using first order difference, for the next node to be able to use the tangent in its computations.. 3.1.3. Length. Since hair strands usually have a varying length, a length node was created that can vary the length of different hair strands. The length node randomizes the length, by scaling each line segment of the hair strand. The scaling is done by: pi = pi−1 + si (pi − pi−1 ). (3.10).

(33) 24. Implementation. Figure 3.6. Example of length node.. where si is defined as a scale factor controlling the amount of scaling on the line segments. An example of the length node is shown in figure 3.6.. 3.1.4. Cut. Figure 3.7. Example of cut node.. The cut node is able to adjust the length of individual hair strands through a map. An example of two cuts are shown in figure 3.7. The map is created with a tool which allows the user to virtually cut the hair. The user drags the mouse and.

(34) 3.1 Styling. 25. creates a cut into the scene from the current viewpoint. A number of planes are created based on the mouse movement. Each plane has a width limited by two points, but extends into infinity into the scene. Using the planes, each of the hair strand line segments is tested for intersection against the planes. If an intersection is found, the cut map is set to that length at the uv-coordinates at the hair strand. When evaluating the cut map, a lookup is performed for each hair strand, and the length is limited to the length specified by the cut map. Given two points a and b that are the left and right limits of the plane, and the rays u and v into the scene at those two points, it is possible to determine if a line segment is intersected by the cut. First, the line-plane intersection between the line segment and the plane given by u and b − a is found. Then, an infinitely large triangle, with one corner in the intersection point between the two rays u and v, and the rays as the sides of the triangle, is created. The intersection point is then tested as to whether it is within the triangle or not. If the point is contained in the triangle, a cut has been made, and a comparison is made if the new strand length is shorter than before. Finally the new length is saved to the cut map.. 3.1.5. Noise. Figure 3.8. Example of noise node.. The noise node creates a random offset angle θr ∈ [0, π] for each hair strand. The amount of offset along the hair strand can be controlled by the user, but is also randomized to further emphasize the random effect. The effect of a noise node to hair strands is shown in figure 3.8. The noise offset function is defined as: pi = pi + ur i r(cos(θr )Ni + sin(θr )BN i ). (3.11). where ur i is the user defined radius and r is a random factor for each hair strand..

(35) 26. 3.1.6. Implementation. Clump. Figure 3.9. Example of clump node.. The clump node creates the impression that hair strands stick to each other by clumping them together as shown in figure 3.9. The clump node randomly selects a subset of all hair strands based on how many clumps are desired. For each hair strand that is not a clump strand, the nearest clump strand is found, and the hair strand is pulled towards it. For this node, a hash grid is used to speed up the nearest clump strand lookup. Thus, all clump strands must first be inserted into the hash grid, and then the hash grid sorted. Then each hair strand looks into its neighboring hash grid cells and finds the closest clump strand ci . When the nearest clump strand has been found, the user clump factor uc i is used to control how far towards the clump strand the hair strand should be moved. The function to clump hairs together can be defined as: pi = pi + uc i (ci − pi ). (3.12). where a clump factor uc i = 1 moves the point all the way to the clump strand, and uc i = 0 does not affect the point.. 3.2. Dynamics. Since the styling and generation of hair strands are done on the GPU, a dynamics algorithm suitable for the GPU was chosen. A mass-spring model has been successfully used by Selle et al. [2008] and by Tariq and Bavoil [2008], so a variant of their proposed method is used for this project. The dynamics in this project can be controlled through a specific dynamics node, which takes a number of hair strands as an input, and creates a velocity and position cache which holds the state.

(36) 3.2 Dynamics. 27. of all hair strands. Other nodes can still affect the hairstyle after the dynamics has been run each frame. The simulation parameters are also controlled in the dynamics node. The hair in this project is simulated as a constrained particle system, where each hair segment vertex is simulated as a particle. To move the particles, an implicit integration scheme similar to the one proposed by Selle et al. [2008] is used as follows: 1. vn+1/2 = vn +. ∆t n+1/2 , xn , vn+1/2 ) 2 a(t. 2. xn+1 = xn + ∆tvn+1/2 3. Ensure segment length by constraints, and update xn+1 and vn+1/2 accordingly. 4. Handle body collisions and update xn+1 and vn+1/2 accordingly. 5. vn+1 = v ˜n+1/2 +. 3.2.1. ∆t n+1/2 ,x ˜n+1 , v ˜n+1/2 ) 2 a(t. Length preservation. The length constraint in this system is not ensured by linear springs, but by a very straightforward strain limiting technique as proposed by Yuksel and Tariq [2010]. The idea is to ensure the correct length of the line segments by not updating all line segments at once. Instead the the odd numbered line segment are corrected, and then in another pass is the evenly numbered line segments updated. A correct length on all line segments are achieved after relatively few iterations. Another approach not tried in this thesis is to only move the point next to the line segment and to propagate the line length changes down the hair strand from the root [Selle et al. 2008]. The length constraint for one hair strands points pi is formulated in algorith 2. li is the rest length of each line segment.. 3.2.2. Angle preservation. To preserve angles, a soft constraint using angular springs between the line segments is used. Each line segment has an optimal target position which is defined using a quaternion rotation and the previous line segment. The target position is found by rotating the current line segment using a quaternion computed in an initial stage of the simulation. Using the target position, the angular force to move the next point pi+1 to the target point p0i+1 is defined as: a = p0i+1 − pi. Fi+1. b = pi+1 − pi   k (a · b)b = a− 2|a||b| kbk2. (3.13). Since the integration scheme used is implicit, all accelerations along a hair strand must be computed by inverting a matrix containing all strand points. Instead, for.

(37) 28. Implementation. Algorithm 2 Length preservation of hair strands for A number of iterations, predetermined, or error controlled do for Odd line segments si = pi pi+1 , i ∈ 1, 3, 5... do pi = pi+1 − kssii k l2i pi+1 = pi + kssii k l2i end for for Even line segments si = pi pi+1 , i ∈ 2, 4, 6... do pi = pi+1 − kssii k l2i pi+1 = pi + kssii k l2i end for end for Update positions and velocities: for All segments, i ∈ 1, 2, 3.... do xcorr = pi − xin+1 x ˜in+1 = xin+1 + xcorr n+1/2 n+1/2 corr v ˜i = vi + x∆t end for. simplicity in the adaption of the algorithm for the GPU, the angular force was linearized. If the dot product an+1 · bn+1 is replaced with the dot product an · bn , the equation to compute the force for one strand point can be computed directly. However, since the angle was linearized, the time step became restricted and the simulation produced oscillations in the hair strand.. 3.2.3. Collisions. In this project, only hair-body collisions were implemented. The fast surface voxelization technique proposed by Schwarz and Seidel [2010] is used to create a voxel surface of all collision triangles. This does not require the collision object to be closed as in the Inside-Outside Voxelization [Nguyen and NVIDIA 2008, Ch. 30]. Each cell in the voxel grid may contain several triangles, and for the collision to be resolved, the normal at each grid cell has to be known. One approach is to approximate the normal from the nearby grid cells, however, if triangles are small in comparison to the grid cell size, this might be inaccurate. Instead 4 floats are stored in the voxel grid. The first three (x, y, z) store the sum of all normals of the triangles in the grid cell. The last component (w) store the number of triangles that have intersected the cell. If the value is 0, it indicates that the cell is empty. To have four floats in each cell increases the storage requirement for the voxel grid significantly, but has the advantage of not limiting the normals to a discrete number of directions. When several triangles, or one small triangle intersects a grid cell, the normals are better preserved using this method. The average normal at a particular grid cell can easily be computed using the w component. The collision algorithm is described in algorithm 3..

(38) 3.3 Rendering. 29. Algorithm 3 Collision algorithm for Each point in the hair system do Perform a lookup g in the collision voxel grid; if gw 6= 0 then The point has collided. Compute the grid cell normal n0 = gxyz /gw , n = n0 /kn0 k. Limit the normal component of the velocity: n+1/2 vcorr = −(vi · n)n n+1/2 n+1/2 v ˜i = vi + vcorr end if end for. 3.3 3.3.1. Rendering The Kajiya-Kay shading model. Figure 3.10. Scattering geometry notation for the Kajiya-Kay shading model.. An early model, although still popular, for rendering hair, is the Kajiya-Kay model [Kajiya and Kay 1989], which was originally developed for rendering fur. For this model, there are two components, the diffuse and specular components, similar to other surface shading models. The diffuse component is similar to the Phong shading model [Phong 1975] although applied to a cylindrical surface, so instead of the surface normal, the line tangent is used. The diffuse component is derived from the Lambert shading model, and the derivation can be found.

(39) 30. Implementation. in [Kajiya and Kay 1989]. The shading notation in the Kajiya-Kay shading model is shown in figure 3.10. After some computations the diffuse component is defined as: diffuse = Kd sin(t, l) (3.14) where t is the hair strand tangent, l is the light direction, and Kd the diffuse reflection coefficient. Inspired by the Phong shading model, Kajiya and Kay [1989] also derives a specular component and the derivations are once again found in their paper. The specular component forms a highlight cone, which is only dependent on the incoming angle relative to the cylinder tangent. Their specular intensity is given by: specular = Ks (cos(θI ) cos(θO ) + sin(θI ) sin(θO ))p = = Ks ((t · l)(t · e) + sin(arccos(t · l) sin(arccos(t · e)))p. (3.15). where θI is the angle between the tangent t and the light direction l, and θO is the angle betweent t and the eye vector e. The final color of the shading model is computed as the sum of the diffuse and the specular components.. 3.3.2. The Marschner shading model. Figure 3.11. Scattering geometry notation for the Marschner shading model.. In 2003, Marschner et al. [2003] proposed a model based on observations and measurements made on real hair. Two important improvements were made to.

(40) 3.3 Rendering. 31. Kajiya and Kays model, the first one taking into account the azimuthal variations of the light reflections. The other is the separation of the reflections into three components, where the first reflection does not enter the hair cylinder, and the second, and third reflections reflects inside the hair cylinder. The notations used in the Marschner shading model are presented in figure 3.11. wi is the direction to the incoming light, wr is the reflecting direction, u is the strand tangent, and v and w forms the normal plane. The θ directions correspond to the inclinations with respect to the normal plane, and the φ directions correspond to the azimuthal angles. For the model, several other angles are defined as follows: • The difference angle θd = (θr − θi )/2 • Relative azimuth φ = φr − φi • Average angle (half angle) θh = (θr + θi )/2 • Average azimuth (half angle) φh = (φr + φi )/2. Figure 3.12. Notation for scattering from a circular cross section.. The bidirectional scattering function for a hair fiber is different from that for a surface (BRDF). Marschner et al. [2003] use curve irradiance (E) for power per unit length (as opposed to irradiance which is power per area unit), and curve.

(41) 32. Implementation. intensity (L) for intensity per unit length (as opposed to radiance which is intensity per unit area). The scattering integral is written as Z Lr (w) = D S(wi , wr )L(wi ) cos(θi ) dw (3.16) where D is the strand thickness, S the bidirectional scattering function, and the integral is integrated over the whole sphere, as opposed to a BRDF which is only integrated over the hemisphere over the surface. After measurments studying real hair fiber, Marschner et al. [2003] categorized the results in three scattering modes which are shown in figure 3.12. • R: The primary reflection, which has a shift of the highlight towards the root due to the tilt of the hair structure. • TT: The secondary reflection, which is the forward scattering component, such that when a hair is viewed from behind the light a bright highlight appears. • TRT: Third reflection, which is a highlight shifted to the tip, and from which the fiber has absorbed some color, such that it has a tint of the hair color. The general scattering function is then written as: S(φi , θi , φr , θr ) = M (θi , θr )N (η 0 (θd ), φi , φr )/ cos2 (θd ). (3.17). where M is the longitudal scattering function, N the azimuthal scattering function which also has a dependency on θd , and cos2 (θd ) accounts for the projection of the solid angle. The factor η 0 is an effective index of refraction. It can be derived as a consequence of Bravais’s law which is described in further detail by Marschner et al. [2003]. The effective index of refraction is computed by: q (3.18) η 0 (θd ) = η − sin2 (θd )/ cos(θd ) By analyzing the measurments made on the hair fibers, Marschner et al. [2003] approximate the longitudal scatterig function (M ) as a normalized gaussian curve: g(β, θh − α) = and. −(θh −α)2 1 √ e 2β2 β 2π. (3.19). MR (θh ) = g(βR , θh − αR ) MTT (θh ) = g(βT T , θh − αT T ). (3.20). MTRT (θH ) = g(βT RT , θh − αT RT ) The azimuthal scattering functions are noted NR , NTT and NTRT and will be described further shortly. By using the three scattering modes, the whole scattering function can be divided as: S(φi , θi , φr , θr ) = MR (θh )NR (η 0 (η, θd ), φ)/ cos2 (θd )+ MTT (θh )NTT (η 0 (η, θd ), φ)/ cos2 (θd )+ 0. ∗. 2. MTRT (θh )NTRT (η (η (φh ), θd ), φ)/ cos (θd ). (3.21).

(42) 3.3 Rendering. 33. The function η ∗ (φh ) lets the effective index of refraction depend on φh which allows for the approximation of elliptical cross sections. η ∗ is defined as: η1∗ = 2(η − 1)a2 − η + 2 η2∗ = 2(η − 1)a−2 − η + 2 1 η ∗ = ((η1∗ + η2∗ ) + cos(2φh )(η1∗ − η2∗ )) 2. (3.22). where a is an eccentricity factor. To derive the azimuthal scattering functions, one has to study the scattering from a dielectric circle/cylinder. When a light beam enters a unit circle at the offset h (−1 < h < 1) from the centre, there is either one, two or three reflections to account for as shown in figure 3.12. By computing the angle (γi = arcsin(h)) in which the ray enters the circle, one can compute the exit angle φ(h) as: φ(p, h) = 2pγt − 2γi + pπ. (3.23). where p is the number of internal segments (equal to the number of reflections minus one), and γt = arcsin(h/η 0 (θd )) is the angle of the refracted ray. p ∈ {0, 1, 2} for R, TT , TRT respectively, p > 2 is ignored. The h values for the different paths (R, TT , TRT ) are found by solving φ(p, h) − φ = 0, and for the first (p = 0) and second (p = 1) path, there is one root. The third path (p = 2) can have one or three roots. The function φ(p, h) can be approximated without getting a large error (less than 0.75◦ [Marschner et al. 2003]) by: φ(p, γi ) = (6pc/π − 2)γi − 8(pc/π 3 )γi3 + pπ. (3.24). where c = arcsin(1/η). From this equation, one or three roots of γi can be computed, and thus h can be found (sin(γi ) = h). Marschner et al. [2003] then defined the curve intensity distribution as:

(43)

(44)

(45)

(46) −1

(47) L(φ(h)) =

(48) 2

(49)

(50) E dh. (3.25). To account for the effect of absorption in the hair fiber, an attenuation factor A(p, h) (depending on the path taken by the ray), is added in front of the intensity such that

(51)

(52)

(53)

(54) −1

(55) L = A(p, h)

(56) 2

(57)

(58) E (3.26) dh The absorption factor A is defined as A(0, h) = F (η, γi )A(p, h) = (1 − F (η, γi ))2 F (1/η, γt )p−1 T (σa , h)p. (3.27). where F is the Fresnel factor, T is an absorption function, and σa the volume absorption per unit width, for each of the RGB color channels. The Fresnel factor.

References

Related documents

Swedenergy would like to underline the need of technology neutral methods for calculating the amount of renewable energy used for cooling and district cooling and to achieve an

The Methods for creating realistic hair for realtime will examine and compare different methods that can be used to create computer graphics with the goal to be as visually akin

In order to find out if pre-textured hair-band modeling, as well as single per-wisp curve based controls, for hairstyling, is preferred or could be beneficial within the

Olivestam uttrycker en nackdel med konfessionella undervisningen där han förklarar att risken med en konfessionell undervisning är att elever som växer upp utan mångfaldig

In so doing, while acknowledging her having exploited a series of structured tasks to reach this point, an ambition that accords with RME principles (Dolk et al. 2002), her

Eftersom sjukdomen fortsätter att drabba de som började arbeta efter asbestförbudet samt kvinnor som sällan arbetar i asbestexponerade yrken (Socialstyrelsen, 2015), är det

Om detta är rätt sätt finns det nog inget svar på, men vi anser att sådana små saker som SS berättar om gör det lättare både för lärare samt eleverna, det blir på så sätt

Forskningsresultatet visar att de didaktiska strategier som var avgörande för elevernas användning av läsförståelsestrategier var att; modellera för användandet