“strong manageable hair without all the fuss” jason lacroix & dominic filion software...

19
Strong manageable hair Strong manageable hair without all the fuss” without all the fuss” Jason Lacroix & Dominic Filion Jason Lacroix & Dominic Filion Software Developers Software Developers Artificial Mind & Movement, Inc. Artificial Mind & Movement, Inc. [email protected] [email protected] [email protected] [email protected] Implementing real-time Implementing real-time dynamic hair for today’s dynamic hair for today’s consoles consoles

Upload: augusta-byrd

Post on 17-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

““Strong manageable hair Strong manageable hair without all the fuss”without all the fuss”

Jason Lacroix & Dominic FilionJason Lacroix & Dominic FilionSoftware DevelopersSoftware Developers

Artificial Mind & Movement, Inc.Artificial Mind & Movement, [email protected]@[email protected]@a2m.com

Implementing real-time Implementing real-time dynamic hair for today’s dynamic hair for today’s

consolesconsoles

Page 2: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Hair physicsHair physics

• Hair physical realism is multi-Hair physical realism is multi-facetedfaceted– RigidityRigidity– AerodynamicsAerodynamics– CollisionCollision– FrictionFriction– DampingDamping– ElectrostaticsElectrostatics

Page 3: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Hair simulationHair simulation

• Verlet integration is used for Verlet integration is used for quick and efficient simulationquick and efficient simulation

• Similar to Jacobsen’s Similar to Jacobsen’s implementationimplementation

• Verlet system implements:Verlet system implements:– Stick constraintsStick constraints– Sphere penetration constraintsSphere penetration constraints

Page 4: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Hair rigidityHair rigidity

• Hair has a natural shape to Hair has a natural shape to which it will attempt to return towhich it will attempt to return to

• Gives volumeGives volume• Stability with curvy hair styles is Stability with curvy hair styles is

difficultdifficult• Compromise was achieved by Compromise was achieved by

using straight rigid hair, which is using straight rigid hair, which is stable and realisticstable and realistic

Page 5: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Hair rigidity (2)Hair rigidity (2)

•As simulation proceeds, hair deviates from ideal rest pose•a is the rigidity of the hair segment•l is the length of all hair segments•vn are the hair vertices•A and B are normalized direction vectors between vertices•R is the resistance force

Page 6: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Hair aerodynamicsHair aerodynamics

• Air resistance dampens the hair Air resistance dampens the hair and gives the hair weightand gives the hair weight

• The medium can be air or waterThe medium can be air or water• Interesting effects can be Interesting effects can be

achieved by having the hair semi-achieved by having the hair semi-immersed in waterimmersed in water

• Vector fields can be used to Vector fields can be used to simulate wind, water currents or simulate wind, water currents or electrostatic effectselectrostatic effects

Page 7: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Hair aerodynamics (2)Hair aerodynamics (2)

•vc and vp are the hair vertex positions for the current frame and the previous frame respectively•d is the time delta since the last frame•W is the wind vector in the vector field for the current hair vertex position•m is the friction coefficient with the medium, i.e. water will be more viscous than air•Hair has a very low terminal velocity – a quadratic friction model should be used if the hair exceeds a certain velocity•To roughly simulate this, m is switched to a much higher value when the magnitude of P exceeds a certain threshold

Page 8: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Hair optimizationHair optimization

• SSE implementation is essential for XboxSSE implementation is essential for Xbox• Algorithm can be run into PS2 microcode as wellAlgorithm can be run into PS2 microcode as well• Vectorize correctly!Vectorize correctly!

– Do Do notnot process all components of vectors at once in SSE process all components of vectors at once in SSE– Compute four hair segments at a time instead, Compute four hair segments at a time instead,

computing one vertex component per instructioncomputing one vertex component per instruction– Hair segments should be stored in SSE-friendly formatHair segments should be stored in SSE-friendly format

Page 9: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Rendering of hairRendering of hair• Strip generationStrip generation• LightingLighting

– Diffuse & ambient lightingDiffuse & ambient lighting– Specular highlightsSpecular highlights

• Shadow castingShadow casting• Shader overviewShader overview• Texture choicesTexture choices• Xbox performanceXbox performance

Page 10: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Rendering Cont’dRendering Cont’d

• Hair strands must be Hair strands must be converted to strips in converted to strips in order to render themorder to render them

• For best visual quality, For best visual quality, strips need to be strips need to be properly aligned with properly aligned with the head (see figure)the head (see figure)

• Use tangent of head Use tangent of head normals to give hair normals to give hair strips a directional strips a directional vector that will make vector that will make them lay flat against them lay flat against the headthe head

Strip GenerationStrip Generation

Page 11: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Rendering Cont’dRendering Cont’d

• Strip created from Strip created from sequence of control points sequence of control points for current frame (physical for current frame (physical representation of hair representation of hair strand)strand)

• Unable to create vertices Unable to create vertices on GPU, therefore we on GPU, therefore we duplicate the control points duplicate the control points and manipulate them on and manipulate them on the hardware to form the the hardware to form the stripsstrips

• Strips are generated by Strips are generated by using a combination of the using a combination of the uv’s, width, and directional uv’s, width, and directional vector information for each vector information for each control pointcontrol point

Strip Generation (cont’d)Strip Generation (cont’d)

Page 12: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Rendering Cont’dRendering Cont’d

• Polygon normals didn’t light very well, Polygon normals didn’t light very well, made strips appear very polygonalmade strips appear very polygonal

• Best solution came from using a hack to Best solution came from using a hack to generate normal. Generated by generate normal. Generated by subtracting pre-defined control point subtracting pre-defined control point from the vertex position to generate a from the vertex position to generate a proper normalproper normal– Not a perfect solution. Depending on hair Not a perfect solution. Depending on hair

layout, can have some instances of improper layout, can have some instances of improper lighting, but these aren’t very obvious. lighting, but these aren’t very obvious. Overall, proved to be the best solution.Overall, proved to be the best solution.

LightingLighting

Page 13: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Rendering Cont’dRendering Cont’d

• Diffuse and ambient lightingDiffuse and ambient lighting– Final lighting solution supports the use Final lighting solution supports the use

of 2 directional lights, 2 positional of 2 directional lights, 2 positional (point) lights, and an ambient term(point) lights, and an ambient term

• Specular lighting Specular lighting – Performed on vertex shader using Performed on vertex shader using

directional lights and a specular map to directional lights and a specular map to give proper looking shimmer to hairgive proper looking shimmer to hair

Lighting cont’dLighting cont’d

Page 14: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Rendering Cont’dRendering Cont’d

• Shadow castingShadow casting– Use of shadow maps chosen over Use of shadow maps chosen over

stencil shadows for visual and stencil shadows for visual and performance reasonsperformance reasons

– Use shadow maps (textures) Use shadow maps (textures) rendered with subtractive blend to rendered with subtractive blend to cast shadows on hero and cast shadows on hero and environment. environment.

– Quick render as no lighting Quick render as no lighting calculations are needed for hair calculations are needed for hair when rendering to shadow texturewhen rendering to shadow texture

ShadowsShadows

Page 15: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Rendering Cont’dRendering Cont’d

mov r0, v0mov r0, v0 # copy position to r0# copy position to r0

mov r8, -r10mov r8, -r10 # Move positive position # Move positive position translation into xtranslation into x

mov r9, r10mov r9, r10 # Move negative position # Move negative position translation into ytranslation into y

# (u < 1.0f)? r8 : r9# (u < 1.0f)? r8 : r9

slt r7, v5.x, v5.wslt r7, v5.x, v5.w

add r6, r8, -r9add r6, r8, -r9

mad r7, r7, r6, r9mad r7, r7, r6, r9

# Now translate the vertex ...# Now translate the vertex ...

add r0.xyz, r0.xyz, r7.xyzadd r0.xyz, r0.xyz, r7.xyz

# Get the normal from the head center ...# Get the normal from the head center ...

add r1, r0.xyz, -c[CENTER_MASS]add r1, r0.xyz, -c[CENTER_MASS]

# Normalize the normal ...# Normalize the normal ...

dp3 r2.x, r1, r1dp3 r2.x, r1, r1

rsq r3.x, r2.xrsq r3.x, r2.x

mul r1.xyz, r1.xyz, r3.xmul r1.xyz, r1.xyz, r3.x

Shader code (strip generation)Shader code (strip generation)

Page 16: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Rendering Cont’dRendering Cont’d

• Textures should have a width/height Textures should have a width/height ratio of 1:8 for best visual results ratio of 1:8 for best visual results (although any size can be used)(although any size can be used)

• To create the illusion of individual To create the illusion of individual strands of hair, 32-bit textures strands of hair, 32-bit textures should be used to allow proper should be used to allow proper transparency transparency

• To alleviate the problem of the scalp To alleviate the problem of the scalp showing through, the textures showing through, the textures should contain a color ramp from should contain a color ramp from dark to light to blend roots in with dark to light to blend roots in with the scalpthe scalp

Texture selectionTexture selection

Page 17: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Rendering Cont’dRendering Cont’d

• Xbox GPU performance measures as viewed through PIX Xbox GPU performance measures as viewed through PIX (Performance Investigator for Xbox)(Performance Investigator for Xbox)

• 263,853 ns * 10263,853 ns * 10-9-9 sec/ns ÷ 0.01667 sec/frame (60 Hz) = 0.015 sec/ns ÷ 0.01667 sec/frame (60 Hz) = 0.015• Hair render takes approximately 1.5% of a 60 Hz frame Hair render takes approximately 1.5% of a 60 Hz frame

Hair performanceHair performance

Page 18: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

Rendering Cont’dRendering Cont’d

• Xbox CPU performance measures as viewed Xbox CPU performance measures as viewed through in-engine performance analyzerthrough in-engine performance analyzer

Hair performanceHair performance

Page 19: “Strong manageable hair without all the fuss” Jason Lacroix & Dominic Filion Software Developers Artificial Mind & Movement, Inc. jason.lacroix@a2m.comdominic.filion@a2m.com

• That, in a nutshell, is how it worksThat, in a nutshell, is how it works• Questions, CommentsQuestions, Comments• ThanksThanks

ConclusionConclusion