Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
HairSettings Class Reference

This class defines the setup of a hair groom, it can be shared between multiple hair instances. More...

#include <HairSettings.h>

Inheritance diagram for HairSettings:
RefTarget< HairSettings >

Classes

class  Gradient
 Gradient along a hair strand of a value, e.g. compliance, friction, etc. More...
 
class  GradientSampler
 
class  GridSampler
 
struct  Material
 The material determines the simulation parameters for a hair strand. More...
 
struct  RStrand
 A hair render strand. More...
 
struct  RVertex
 A render vertex. More...
 
struct  SkinPoint
 Information about where a hair strand is attached to the scalp mesh. More...
 
struct  SkinWeight
 How much a vertex is influenced by a joint. More...
 
struct  SStrand
 A hair simulation strand. More...
 
struct  SVertex
 A simulated vertex in a hair strand. More...
 
struct  SVertexInfluence
 Describes how a render vertex is influenced by a simulated vertex. More...
 

Public Member Functions

void InitRenderAndSimulationStrands (const Array< SVertex > &inVertices, const Array< SStrand > &inStrands)
 
void Init (float &outMaxDistSqHairToScalp)
 
void InitCompute (ComputeSystem *inComputeSystem)
 Must be called after Init to setup the compute buffers.
 
float GetNeutralDensity (uint32 inX, uint32 inY, uint32 inZ) const
 Sample the neutral density at a grid position.
 
uint32 GetNumVerticesPadded () const
 Get the number of vertices in the vertex buffers padded to a multiple of mMaxVerticesPerStrand.
 
void PrepareForScalpSkinning (Mat44Arg inJointToHair, const Mat44 *inJointMatrices, Mat44 *outJointMatrices) const
 Calculates the pose used for skinning the scalp.
 
void SkinScalpVertices (Mat44Arg inJointToHair, const Mat44 *inJointMatrices, Array< Vec3 > &outVertices) const
 
void SaveBinaryState (StreamOut &inStream) const
 Saves the state of this object in binary form to inStream. Doesn't store the compute buffers.
 
void RestoreBinaryState (StreamIn &inStream)
 Restore the state of this object from inStream.
 
- Public Member Functions inherited from RefTarget< HairSettings >
 RefTarget ()=default
 Constructor.
 
 RefTarget (const RefTarget &)
 
 ~RefTarget ()
 assert no one is referencing us
 
void SetEmbedded () const
 
RefTargetoperator= (const RefTarget &)
 Assignment operator.
 
uint32 GetRefCount () const
 Get current refcount of this object.
 
void AddRef () const
 Add or release a reference to this object.
 
void Release () const
 

Static Public Member Functions

static void sResample (Array< SVertex > &ioVertices, Array< SStrand > &ioStrands, uint32 inNumVerticesPerStrand)
 Resample the hairs to a new fixed number of vertices per strand. Must be called prior to Init if desired.
 
- Static Public Member Functions inherited from RefTarget< HairSettings >
static int sInternalGetRefCountOffset ()
 INTERNAL HELPER FUNCTION USED BY SERIALIZATION.
 

Public Attributes

Array< SVertexmSimVertices
 Simulated vertices. Used by mSimStrands.
 
Array< SStrandmSimStrands
 Defines the start and end of each simulated strand.
 
Array< RVertexmRenderVertices
 Rendered vertices. Used by mRenderStrands.
 
Array< RStrandmRenderStrands
 Defines the start and end of each rendered strand.
 
Array< Float3mScalpVertices
 Vertices of the scalp mesh, used to attach hairs. Note that the hair vertices mSimVertices must be in the same space as these vertices.
 
Array< IndexedTriangleNoMaterialmScalpTriangles
 Triangles of the scalp mesh.
 
Array< Mat44mScalpInverseBindPose
 Inverse bind pose of the scalp mesh, joints are in model space.
 
Array< SkinWeightmScalpSkinWeights
 Skin weights of the scalp mesh, for each vertex we have mScalpNumSkinWeightsPerVertex entries.
 
uint mScalpNumSkinWeightsPerVertex = 0
 Number of skin weights per vertex.
 
uint32 mNumIterationsPerSecond = cDefaultIterationsPerSecond
 
float mMaxDeltaTime = 1.0f / 30.0f
 Maximum delta time for the simulation step (to avoid running an excessively long step, note that this will effectively slow down time)
 
UVec4 mGridSize { 32, 32, 32, 0 }
 Number of grid cells used to simulate the hair. W unused.
 
Vec3 mSimulationBoundsPadding = Vec3::sReplicate(0.1f)
 Padding around the simulation bounds to ensure that the grid is large enough and that we detect collisions with the hairs. This is added on all sides after calculating the bounds in the neutral pose.
 
Vec3 mInitialGravity { 0, -9.81f, 0 }
 Initial gravity in local space of the hair, used to calculate the unloaded rest pose.
 
Array< MaterialmMaterials
 Materials used by the hair strands.
 
Array< SkinPointmSkinPoints
 For each simulated vertex, where it is attached to the scalp mesh.
 
AABox mSimulationBounds { Vec3::sZero(), 1.0f }
 Bounds that the simulation is supposed to fit in.
 
Array< float > mNeutralDensity
 Neutral density grid used to apply forces to keep the hair in place.
 
float mDensityScale = 0.0f
 Highest density value in the neutral density grid, used to scale the density for rendering.
 
uint32 mMaxVerticesPerStrand = 0
 Maximum number of vertices per strand, used for padding the compute buffers.
 
Ref< ComputeBuffermScalpVerticesCB
 
Ref< ComputeBuffermScalpTrianglesCB
 
Ref< ComputeBuffermScalpSkinWeightsCB
 
Ref< ComputeBuffermSkinPointsCB
 
Ref< ComputeBuffermVerticesFixedCB
 
Ref< ComputeBuffermVerticesPositionCB
 
Ref< ComputeBuffermVerticesBishopCB
 
Ref< ComputeBuffermVerticesOmega0CB
 
Ref< ComputeBuffermVerticesLengthCB
 
Ref< ComputeBuffermVerticesStrandFractionCB
 
Ref< ComputeBuffermStrandVertexCountsCB
 
Ref< ComputeBuffermStrandMaterialIndexCB
 
Ref< ComputeBuffermNeutralDensityCB
 
Ref< ComputeBuffermSVertexInfluencesCB
 

Static Public Attributes

static constexpr uint32 cNoInfluence = ~uint32(0)
 
static constexpr uint32 cDefaultIterationsPerSecond = 360
 

Additional Inherited Members

- Protected Attributes inherited from RefTarget< HairSettings >
atomic< uint32mRefCount
 Current reference count.
 
- Static Protected Attributes inherited from RefTarget< HairSettings >
static constexpr uint32 cEmbedded
 A large value that gets added to the refcount to mark the object as embedded.
 

Detailed Description

This class defines the setup of a hair groom, it can be shared between multiple hair instances.

Member Function Documentation

◆ GetNeutralDensity()

float HairSettings::GetNeutralDensity ( uint32 inX,
uint32 inY,
uint32 inZ ) const
inline

Sample the neutral density at a grid position.

◆ GetNumVerticesPadded()

uint32 HairSettings::GetNumVerticesPadded ( ) const
inline

Get the number of vertices in the vertex buffers padded to a multiple of mMaxVerticesPerStrand.

◆ Init()

void HairSettings::Init ( float & outMaxDistSqHairToScalp)

Initialize the structure, calculating simulation bounds and vertex properties

Parameters
outMaxDistSqHairToScalpMaximum distance^2 the root vertex of a hair is from the scalp, can be used to check if the hair matched the scalp correctly

◆ InitCompute()

void HairSettings::InitCompute ( ComputeSystem * inComputeSystem)

Must be called after Init to setup the compute buffers.

◆ InitRenderAndSimulationStrands()

void HairSettings::InitRenderAndSimulationStrands ( const Array< SVertex > & inVertices,
const Array< SStrand > & inStrands )

Split the supplied render strands into render and simulation strands and calculate connections between them. When this function returns mSimVertices, mSimStrands, mRenderVertices and mRenderStrands are overwritten.

Parameters
inVerticesVertices for the strands.
inStrandsThe strands that this instance should have.

◆ PrepareForScalpSkinning()

void HairSettings::PrepareForScalpSkinning ( Mat44Arg inJointToHair,
const Mat44 * inJointMatrices,
Mat44 * outJointMatrices ) const

Calculates the pose used for skinning the scalp.

Parameters
inJointToHairTransform to bring the model space joint matrices to the hair local space
inJointMatricesModel space joint matrices of the joints in the face
outJointMatricesJoint matrices combined with the inverse bind pose

◆ RestoreBinaryState()

void HairSettings::RestoreBinaryState ( StreamIn & inStream)

Restore the state of this object from inStream.

◆ SaveBinaryState()

void HairSettings::SaveBinaryState ( StreamOut & inStream) const

Saves the state of this object in binary form to inStream. Doesn't store the compute buffers.

◆ SkinScalpVertices()

void HairSettings::SkinScalpVertices ( Mat44Arg inJointToHair,
const Mat44 * inJointMatrices,
Array< Vec3 > & outVertices ) const

Skin the scalp mesh to the given joint matrices and output the skinned scalp vertices

Parameters
inJointToHairTransform to bring the model space joint matrices to the hair local space
inJointMatricesModel space joint matrices of the joints in the face
outVerticesReturns skinned vertices

◆ sResample()

void HairSettings::sResample ( Array< SVertex > & ioVertices,
Array< SStrand > & ioStrands,
uint32 inNumVerticesPerStrand )
static

Resample the hairs to a new fixed number of vertices per strand. Must be called prior to Init if desired.

Member Data Documentation

◆ cDefaultIterationsPerSecond

uint32 HairSettings::cDefaultIterationsPerSecond = 360
staticconstexpr

◆ cNoInfluence

uint32 HairSettings::cNoInfluence = ~uint32(0)
staticconstexpr

◆ mDensityScale

float HairSettings::mDensityScale = 0.0f

Highest density value in the neutral density grid, used to scale the density for rendering.

◆ mGridSize

UVec4 HairSettings::mGridSize { 32, 32, 32, 0 }

Number of grid cells used to simulate the hair. W unused.

◆ mInitialGravity

Vec3 HairSettings::mInitialGravity { 0, -9.81f, 0 }

Initial gravity in local space of the hair, used to calculate the unloaded rest pose.

◆ mMaterials

Array<Material> HairSettings::mMaterials

Materials used by the hair strands.

◆ mMaxDeltaTime

float HairSettings::mMaxDeltaTime = 1.0f / 30.0f

Maximum delta time for the simulation step (to avoid running an excessively long step, note that this will effectively slow down time)

◆ mMaxVerticesPerStrand

uint32 HairSettings::mMaxVerticesPerStrand = 0

Maximum number of vertices per strand, used for padding the compute buffers.

◆ mNeutralDensity

Array<float> HairSettings::mNeutralDensity

Neutral density grid used to apply forces to keep the hair in place.

◆ mNeutralDensityCB

Ref<ComputeBuffer> HairSettings::mNeutralDensityCB

◆ mNumIterationsPerSecond

uint32 HairSettings::mNumIterationsPerSecond = cDefaultIterationsPerSecond

◆ mRenderStrands

Array<RStrand> HairSettings::mRenderStrands

Defines the start and end of each rendered strand.

◆ mRenderVertices

Array<RVertex> HairSettings::mRenderVertices

Rendered vertices. Used by mRenderStrands.

◆ mScalpInverseBindPose

Array<Mat44> HairSettings::mScalpInverseBindPose

Inverse bind pose of the scalp mesh, joints are in model space.

◆ mScalpNumSkinWeightsPerVertex

uint HairSettings::mScalpNumSkinWeightsPerVertex = 0

Number of skin weights per vertex.

◆ mScalpSkinWeights

Array<SkinWeight> HairSettings::mScalpSkinWeights

Skin weights of the scalp mesh, for each vertex we have mScalpNumSkinWeightsPerVertex entries.

◆ mScalpSkinWeightsCB

Ref<ComputeBuffer> HairSettings::mScalpSkinWeightsCB

◆ mScalpTriangles

Array<IndexedTriangleNoMaterial> HairSettings::mScalpTriangles

Triangles of the scalp mesh.

◆ mScalpTrianglesCB

Ref<ComputeBuffer> HairSettings::mScalpTrianglesCB

◆ mScalpVertices

Array<Float3> HairSettings::mScalpVertices

Vertices of the scalp mesh, used to attach hairs. Note that the hair vertices mSimVertices must be in the same space as these vertices.

◆ mScalpVerticesCB

Ref<ComputeBuffer> HairSettings::mScalpVerticesCB

◆ mSimStrands

Array<SStrand> HairSettings::mSimStrands

Defines the start and end of each simulated strand.

◆ mSimulationBounds

AABox HairSettings::mSimulationBounds { Vec3::sZero(), 1.0f }

Bounds that the simulation is supposed to fit in.

◆ mSimulationBoundsPadding

Vec3 HairSettings::mSimulationBoundsPadding = Vec3::sReplicate(0.1f)

Padding around the simulation bounds to ensure that the grid is large enough and that we detect collisions with the hairs. This is added on all sides after calculating the bounds in the neutral pose.

◆ mSimVertices

Array<SVertex> HairSettings::mSimVertices

Simulated vertices. Used by mSimStrands.

◆ mSkinPoints

Array<SkinPoint> HairSettings::mSkinPoints

For each simulated vertex, where it is attached to the scalp mesh.

◆ mSkinPointsCB

Ref<ComputeBuffer> HairSettings::mSkinPointsCB

◆ mStrandMaterialIndexCB

Ref<ComputeBuffer> HairSettings::mStrandMaterialIndexCB

◆ mStrandVertexCountsCB

Ref<ComputeBuffer> HairSettings::mStrandVertexCountsCB

◆ mSVertexInfluencesCB

Ref<ComputeBuffer> HairSettings::mSVertexInfluencesCB

◆ mVerticesBishopCB

Ref<ComputeBuffer> HairSettings::mVerticesBishopCB

◆ mVerticesFixedCB

Ref<ComputeBuffer> HairSettings::mVerticesFixedCB

◆ mVerticesLengthCB

Ref<ComputeBuffer> HairSettings::mVerticesLengthCB

◆ mVerticesOmega0CB

Ref<ComputeBuffer> HairSettings::mVerticesOmega0CB

◆ mVerticesPositionCB

Ref<ComputeBuffer> HairSettings::mVerticesPositionCB

◆ mVerticesStrandFractionCB

Ref<ComputeBuffer> HairSettings::mVerticesStrandFractionCB

The documentation for this class was generated from the following files: