当前位置:网站首页>[graphics] hair simulation in tressfx
[graphics] hair simulation in tressfx
2022-07-03 14:46:00 【ZJU_ fish1996】
reference:《GPU Pro5》Hair Simulation in TressFX
The hair of the character is about 120000 root , Due to the high cost of rendering and the lack of real-time simulation technology , Presenting human hair in real-time video games has always been a challenge . therefore , Many artists and game developers have to choose other methods , For example, use simple polygons and textures .
In this chapter , I will explain TressFX Hair simulation method in , This method has been used in recent Tomb Raider and AMD Rudy Use... In the demonstration .
At the high end GPU in , It can simulate about... In less than a millisecond 19000 Contains 22 A line of ten thousand vertices .TressFX Designed for video games (video game) The development of , therefore , Performance is the highest concern of physical accuracy .
Simulation overview
Developing TressFX When simulating , The main focus is to simulate molded hair , It's much harder than straight hair , Because he needs more powerful bending and twisting effects . No matter what kind of hairstyle , The hair of characters should be considered as non expandable . To simulate these three effects , There are usually two ways to express them , That is, rigid springs or constraints .
stay VFX in , Rigid springs are commonly used in various simulations , Such as hair or clothes . however , For real-time physical simulation , The actual effect of rigid spring is poor , Because the integration of strong spring force is easy to make the mass spring damper system unstable , Unless you use a complex integration scheme , For example, implicit backward integrator (implicit backward integrator). and , Stretching is difficult to handle in the same solver 、 Bend and twist the spring , Especially in GPU in . stay Tress in , All springs are replaced by hard constraints and soft constraints . For non scalability , We use a simple position based iterative distance constraint . For the sake of simplicity , Bending and twisting are seen as a single effect , Therefore, local and global shape constraints are used . Sometimes , We also use special constraints (ad-hoc) To handle fast-moving characters .
In addition to bending and twisting effects , Other hair simulations are similar to cloth simulations . however , If you use GPU Calculation , Better for hair , Because there are many bunches , If the collision between hair bundles is not considered , They are independent of each other . And the topological order of vertex connection is direct . By using these points ,TressFX Can achieve hair bundles / Vertex level parallelism , Without complex data structures .
Definition
Basically , Every hair is a polygonal line . When interpreting local shape constraints , Local and global terms are often used . The overall situation lies in the world framework , The part is located in the local frame , This area is attached to the starting point of the line segment .
The vertex index starts from the root of the hair bundle attached to the scalp . Is the vertex in the current time step i The location of . The first 0 Time is static , We use the right superscript to make it clear ( namely
). ad locum , When we explain the algorithm , We only focus on one set of hair bundles . therefore , Vertex Index i Always unique .
If you need to specify which coordinate system we use , You can use the left superscript to specify it ( namely It means a vertex i In local frame i-1 The position in the current time step defined in ). After defining the position in the world coordinate system , We can delete the frame index ( namely
)
In terms of transformation , We Defined as including rotation
Move peacefully
Complete transformation of . It is from
Convert to
, In order to make
Because the vertices in the hair bundle are carefully indexed , Therefore, the following equation holds :
In this chapter , We call For local transformation ,
For global transformation . At the top 0 For example , Local transformation and global transformation are the same , namely
In the figure 1.2 in , Local frames are defined on each vertex . vector and
Is the vertex under the current time step i The base vector of the local frame .
It is simply defined as
The normalized vector of . More specifically ,
.
In the figure 1.3 in , The base vector is displayed in red 、 Yellow and blue .
To describe the head transformation , We use , It turns its head from idle State transition to current state , As input of user or preset animation .
integral
In order to integrate the motion of hair dynamics , We use Verlet Integral scheme , Because it is related to explicit Euler The method is relatively simple and shows good numerical stability . In this step, an external force will be applied , Such as gravity . The damping effect can be simulated by multiplying the damping coefficient by the speed . We only integrate particles with non-zero inverse mass . If the inverse mass is zero , We think it is immovable , Please attach an object to it ( For example, head ) Then update its location , Then skip the rest of these particles . We are the apex 0 and 1 Zero inverse masses are assigned , So they can animate as the head moves .
constraint
There are three constraints .
ELC( Edge length constraint ) Is a hard constraint that simulates non stretchable hair ;
LSC( Local shape constraints ) It is a soft constraint of bending and twisting ;
GSC( Global shape constraints ) yes LSC A supplement to , And it helps to retain the initial hair shape at a very low computational cost ;
Length constraint
ELC Force the edge to keep it idle Length in state . chart 1.4 Shows how to calculate the position correction for each edge . For the sake of simplicity , We set equal mass for the first two vertices . To apply this constraint in parallel , We created two batches , Each batch is processed independently , Therefore, the vertex position can be updated safely without conflict .
In the hair , It is easy to create two batches as even edge index groups and odd edge index groups . We run the first batch , Then run the second batch . This method provides us with good parallelism . Unfortunately , The compromise scheme has poor convergence , So we iterate it many times , So that all edges reach their rest length .
stay Tomb Raider in , The protagonist can move and turn quickly . Basically , Users can generate strong acceleration , This leads to long hair elongation .
under these circumstances , Even if the iteration exceeds 20 Time ,ELC It can't converge well . By measuring the length of the first movable edge and comparing it with the rest length , Convergence can be easily checked .
To solve this problem , Let's switch to abhocyu constraint , This constraint updates only one vertex position , Pictured 1.4 Medium pi+. By updating a vertex position of each edge starting from the root of the hair clump , We can simply satisfy ELC.
however , This method will add extra energy to the system , And lead to unnatural simulation results , To eliminate this excess energy , We added high damping . therefore , We only use this method when we really need it , Interested readers can refer to Muller, In order to have a deeper understanding of this problem and different solutions .
Global constraints
GSC The main idea is simple . We take the initial hair shape as the target , And try to move the vertex to the shape , It is similar to shape matching .
The easiest way to understand is to think of the initial hair shape as a cage , and GSC Forced to trap hair .
Before the simulation starts , We save vertices P The rest of the position . take idle Position is used as the target position , To apply global shape constraints .
In the formula 1.1 in ,SG Is the rigid body coefficient of the overall shape constraint , Range from 0 To 1. If SG by 0, It doesn't work , If 1, The hair becomes completely stiff , And freeze to initial shape .
in many instances , We are in part of the hair band ( For example, close to the root ) Apply global shape constraints on . We can also gradually reduce from the root to the end of the hair SG. This is because the hair seems to be stiffer near the root . Again , It can maintain the hair style more effectively , It will not bring unnecessary additional stiffness to the whole hair simulation .
The benefits of global shape constraints are , It keeps the overall shape at the minimum cost . Combine local shape constraints , It takes almost no time to complete the simulation , And there will be no visual interference at the beginning of the simulation .
Designers can expect that the hair shape they create will be the initial shape .
The overall shape limit can also ensure that during the fast-moving game , Hair will not tangle into strange shapes .
Local constraints
Even if GSC Can effectively manage hair shape , We still need a method to simulate the bending and twisting forces of a single hair bundle . In real-time cloth simulation , The bending effect is usually expressed as a soft distance constraint connecting two vertices across the curved edge . You can also use the same method to produce a bending effect on your hair , But twisting is not easy .
For simplicity and high performance , We combine bending and twisting effects into a soft distance constraint . To define this constraint , Pictured 1.2 and 1.3 Shown , Use the local frame to calculate the target location .
The formula (1.2) Because its subscripts and superscripts may look complex , But the concept is different from ELC identical . The first equation calculates i-1di, It is the distance between the current position and its target position . Left superscript i-1 Indicates that those positions are defined in the local frame .
Last , When we calculate the position correction , We actually use world space , But the equation (1.2) Written in local space to simplify it :
Such as ELC Described in , We divide the position correction by the mass ratio , And apply it to two connected vertices (i-1Pi-1 and i-1Pi). ad locum , We have assumed that all masses are equal , So the ratio is 1/2.
Wind and collision
Wind is an important part of simulation , Because it makes the hair interact with the environment , Even in idle It can also give the game characters a sense of dynamics in the state . In order to produce more random effects and prevent caking , Convert a single wind input to four conical directions , As shown in the figure :
Modulate the size of the wind by using the sine function and the number of frames , As shown below :
The formula shows how to calculate the wind force and apply it to the location update .W1,W2,W3 and W4 It's four wind vectors , And for more randomization :
In the first equation 20 It's an arbitrary choice ,W Is one of the four wind vectors a Interpolated wind vector ,Δt It's the time step .
Wind is imposed after shape constraints , Not part of the integral , Because the shape constraint is too strong and if it is applied as an external force in the integration process , May offset its impact . The key to calculating wind is to create random directions and periods . therefore , It is more like an empirical parameter than physically correct .
assets
After creating the hair clump as a spline , Customize python The script will export it as a polyline . stay TressFX In the demonstration , Hair is divided into front , Top , Side and ponytail four groups , Each group is saved as a separate file .
GPU Realization
TressFX stay DirectX 11 Calculation shaders are used in GPU Run hair simulation in .
There are five computational shader cores . detailed list 1.1 Shows Simulate Hair_A kernel , The kernel handles integration and GSC. The kernel calculates a vertex for each thread . because GROUP_SIZE Defined as 64, therefore , If a thread group has 16 vertices , Then a thread group can calculate four hairs . Use maxPossibleVertsInStrand, You can control how many lines can be calculated in a thread group . because GROUP_SIZE by 64, So the maximum number of vertices in a harness is 64. By way of GROUP_SIZE Change to 128 or 256, We can have more vertices . however , More vertices may take longer to execute ELC and LSC. therefore , It is recommended to use 16 or 32 vertices .
detailed list 1.2 Shows SimulateHair_A kernel , It performs LSC. The kernel calculates one thread for each thread , So there is a for loop . strandType It's a variable , Display the group to which the chain belongs . such , We can assign different simulation parameters to hair groups , Such as stiffness or damping .
SimulateHair_C The kernel calculates a vertex for each thread , perform ELC And apply wind . Last ,SimulateHair_D Be responsible for collision and calculate the tangent of the segment of the rendering pipeline .
If you should ignore the hair simulation ,SkipSimulateHair The kernel implements this . This can also be done by setting 1.0 Of GSC Stiffness to complete , But this will waste a lot of unnecessary operations .SkipSimulateHair The kernel only applies the head transform to vertices , And make the hair move rigidly .
summary
TressFX Hair simulation of has been optimized for the implementation of the game in many aspects , For example, use shape constraints , And the limit on the number of vertices of each hair bundle . therefore , Need to understand the basic method , To maximize its performance and quality .
边栏推荐
- Zzuli: cumulative sum of 1050 factorials
- C language DUP function
- Happy capital new dual currency fund nearly 4billion yuan completed its first account closing
- Zzuli:1054 monkeys eat peaches
- Zzuli:1044 failure rate
- Zzuli:1059 highest score
- Tensor 省略号(三个点)切片
- The picture quality has been improved! LR enhancement details_ Lightroom turns on AI photo detail enhancement: picture clarity increases by 30%
- DDK for XP
- Luogu p5536 [xr-3] core city solution
猜你喜欢
[qingniaochangping campus of Peking University] in the Internet industry, which positions are more popular as they get older?
Pyqt interface production (login + jump page)
Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in
C language fcntl function
Sword finger offer 28 Symmetric binary tree
Adc128s022 ADC Verilog design and Implementation
QT - draw something else
tonybot 人形機器人 紅外遙控玩法 0630
X86 assembly language - Notes from real mode to protected mode
Paper sharing: generating playful palettes from images
随机推荐
Puzzle (016.4) domino effect
洛谷P4047 [JSOI2010]部落划分 题解
Frequently asked questions: PHP LDAP_ add(): Add: Undefined attribute type in
Zzuli:1049 square sum and cubic sum
Niuke bm83 string deformation (case conversion, string inversion, string replacement)
Luogu p5536 [xr-3] core city solution
Tonybot Humanoïde Robot Infrared Remote play 0630
Special research report on the market of lithium battery electrolyte industry in China (2022 Edition)
Amazon, express, lazada, shopee, eBay, wish, Wal Mart, Alibaba international, meikeduo and other cross-border e-commerce platforms evaluate how Ziyang account can seize traffic by using products in th
Zzuli:1053 sine function
tonybot 人形机器人 首次开机 0630
NPM install is stuck with various strange errors of node NPY
Accelerating strategy learning using parallel differentiable simulation
Introduction to opengl4.0 tutorial computing shaders
tonybot 人形機器人 紅外遙控玩法 0630
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
Zzuli:1055 rabbit reproduction
Address book sorting
556. 下一个更大元素 III : 简单构造模拟题
NOI OPENJUDGE 1.6(09)