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

#include <Hair.h>

Inheritance diagram for Hair:
NonCopyable

Classes

struct  DrawSettings
 
struct  LeafShape
 
struct  UpdateContext
 

Public Types

enum class  ERenderStrandColor {
  PerRenderStrand , PerSimulatedStrand , GravityFactor , WorldTransformInfluence ,
  GridVelocityFactor , GlobalPose , SkinGlobalPose
}
 
using RenderPositionsToFloat3 = std::function<void(ComputeBuffer *, Float3 *, uint)>
 Function that converts the render positions buffer to Float3 vertices for debugging purposes. It maps an application defined format to Float3. Third parameter is the number of vertices.
 

Public Member Functions

 Hair (const HairSettings *inSettings, RVec3Arg inPosition, QuatArg inRotation, ObjectLayer inLayer)
 Constructor / destructor.
 
 ~Hair ()
 
void Init (ComputeSystem *inComputeSystem)
 Initialize.
 
void SetPosition (RVec3Arg inPosition)
 Position and rotation of the hair in world space.
 
void SetRotation (QuatArg inRotation)
 
RMat44 GetWorldTransform () const
 
void OnTeleported ()
 The hair will be initialized in its default pose with zero velocity at the new position and rotation during the next update.
 
void SetScalpVerticesCB (ComputeBuffer *inBuffer)
 Ability to externally provide the scalp vertices buffer. This allows skipping skinning the scalp during the simulation update. You may need to override JPH_SHADER_BIND_SCALP_VERTICES in HairSkinRootsBindings.h to match the format of the provided buffer.
 
void SetScalpTrianglesCB (ComputeBuffer *inBuffer)
 Ability to externally provide the scalp triangle indices buffer. This allows skipping skinning the scalp in during the simulation update. You may need to override JPH_SHADER_BIND_SCALP_TRIANGLES in HairSkinRootsBindings.h to match the format of the provided buffer.
 
void SetScalpToHead (Mat44Arg inMat)
 When skipping skinning, this allow specifying a transform that transforms the scalp mesh into head space.
 
void OverrideRenderPositionsCB (const RenderPositionsToFloat3 &inRenderPositionsToFloat3)
 Enable externally set render vertices buffer (with potentially different vertex layout). Note that this also requires replacing the HairCalculateRenderPositions shader.
 
void SetRenderPositionsCB (ComputeBuffer *inBuffer)
 Allow setting the render vertices buffer externally in case it has special requirements for the calling application. You may need to override JPH_SHADER_BIND_RENDER_POSITIONS in HairCalculateRenderPositionsBindings.h to match the format of the provided buffer.
 
void Update (float inDeltaTime, Mat44Arg inJointToHair, const Mat44 *inJointMatrices, const PhysicsSystem &inSystem, const HairShaders &inShaders, ComputeSystem *inComputeSystem, ComputeQueue *inComputeQueue)
 
ComputeBufferGetScalpVerticesCB () const
 Access to the resulting simulation data.
 
ComputeBufferGetScalpTrianglesCB () const
 Skinned scalp triangle indices.
 
ComputeBufferGetPositionsCB () const
 Note transposed for better memory access.
 
ComputeBufferGetVelocitiesCB () const
 Note transposed for better memory access.
 
ComputeBufferGetVelocityAndDensityCB () const
 Velocity grid.
 
ComputeBufferGetRenderPositionsCB () const
 Render positions of the hair strands (see HairSettings::mRenderStrands to see where each strand starts and ends)
 
void ReadBackGPUState (ComputeQueue *inComputeQueue)
 Read back the GPU state so that the functions below can be used. For debugging purposes only, this is slow!
 
void LockReadBackBuffers ()
 Lock/unlock the data buffers so that the functions below return valid values.
 
void UnlockReadBackBuffers ()
 
const Float3GetScalpVertices () const
 Access to the resulting simulation data (only valid when ReadBackGPUState has been called and the buffers have been locked)
 
const Float3GetPositions () const
 
const QuatGetRotations () const
 
StridedPtr< const Float3GetVelocities () const
 
StridedPtr< const Float3GetAngularVelocities () const
 
const Float4GetGridVelocityAndDensity () const
 
const Float3GetRenderPositions () const
 
void Draw (const DrawSettings &inSettings, DebugRenderer *inRenderer)
 Debug functionality to draw the hair and its simulation properties.
 
- Public Member Functions inherited from NonCopyable
 NonCopyable ()=default
 
 NonCopyable (const NonCopyable &)=delete
 
void operator= (const NonCopyable &)=delete
 

Protected Types

using Gradient = HairSettings::Gradient
 
using GradientSampler = HairSettings::GradientSampler
 

Protected Member Functions

void InitializeContext (UpdateContext &outCtx, float inDeltaTime, const PhysicsSystem &inSystem)
 

Protected Attributes

RefConst< HairSettingsmSettings
 
RVec3 mPrevPosition
 
RVec3 mPosition
 
Quat mPrevRotation
 
Quat mRotation
 
bool mTeleported = true
 
ObjectLayer mLayer
 
Mat44 mScalpToHead = Mat44::sIdentity()
 
bool mRenderPositionsOverridden = false
 
RenderPositionsToFloat3 mRenderPositionsToFloat3
 
Ref< ComputeBuffermScalpJointMatricesCB
 
Ref< ComputeBuffermScalpVerticesCB
 
Ref< ComputeBuffermScalpTrianglesCB
 
Ref< ComputeBuffermTargetPositionsCB
 
Ref< ComputeBuffermTargetGlobalPoseTransformsCB
 
Ref< ComputeBuffermGlobalPoseTransformsCB
 
Ref< ComputeBuffermShapePlanesCB
 
Ref< ComputeBuffermShapeVerticesCB
 
Ref< ComputeBuffermShapeIndicesCB
 
Ref< ComputeBuffermCollisionPlanesCB
 
Ref< ComputeBuffermCollisionShapesCB
 
Ref< ComputeBuffermMaterialsCB
 
Ref< ComputeBuffermPreviousPositionsCB
 
Ref< ComputeBuffermPositionsCB
 
Ref< ComputeBuffermVelocitiesCB
 
Ref< ComputeBuffermVelocityAndDensityCB
 
Ref< ComputeBuffermConstantsCB
 
Array< Ref< ComputeBuffer > > mIterationConstantsCB
 
Ref< ComputeBuffermRenderPositionsCB
 
Ref< ComputeBuffermScalpVerticesReadBackCB
 
Ref< ComputeBuffermPositionsReadBackCB
 
Ref< ComputeBuffermVelocitiesReadBackCB
 
Ref< ComputeBuffermVelocityAndDensityReadBackCB
 
Ref< ComputeBuffermRenderPositionsReadBackCB
 
const Float3mScalpVertices = nullptr
 
Float3mPositions = nullptr
 
QuatmRotations = nullptr
 
JPH_HairVelocity * mVelocities = nullptr
 
const Float4mVelocityAndDensity = nullptr
 
const Float3mRenderPositions = nullptr
 

Detailed Description

Hair simulation instance

Note that this system is currently still in development, it is missing important features like:

  • Level of detail
  • Wind forces
  • Advection step for the grid velocity field
  • Support for collision detection against shapes other than ConvexHullShape
  • The Gradient class is very limited and will be replaced by a texture lookup
  • Gravity preload factor is not fully functioning yet
  • It is wasteful of memory (e.g. stores everything both on CPU and GPU)
  • Only supports a single neutral pose to drive towards
  • It could use further optimizations

Member Typedef Documentation

◆ Gradient

◆ GradientSampler

◆ RenderPositionsToFloat3

using Hair::RenderPositionsToFloat3 = std::function<void(ComputeBuffer *, Float3 *, uint)>

Function that converts the render positions buffer to Float3 vertices for debugging purposes. It maps an application defined format to Float3. Third parameter is the number of vertices.

Member Enumeration Documentation

◆ ERenderStrandColor

enum class Hair::ERenderStrandColor
strong
Enumerator
PerRenderStrand 
PerSimulatedStrand 
GravityFactor 
WorldTransformInfluence 
GridVelocityFactor 
GlobalPose 
SkinGlobalPose 

Constructor & Destructor Documentation

◆ Hair()

JPH_NAMESPACE_BEGIN Hair::Hair ( const HairSettings * inSettings,
RVec3Arg inPosition,
QuatArg inRotation,
ObjectLayer inLayer )

Constructor / destructor.

◆ ~Hair()

Hair::~Hair ( )

Member Function Documentation

◆ Draw()

void Hair::Draw ( const DrawSettings & inSettings,
DebugRenderer * inRenderer )

Debug functionality to draw the hair and its simulation properties.

◆ GetAngularVelocities()

StridedPtr< const Float3 > Hair::GetAngularVelocities ( ) const
inline

◆ GetGridVelocityAndDensity()

const Float4 * Hair::GetGridVelocityAndDensity ( ) const
inline

◆ GetPositions()

const Float3 * Hair::GetPositions ( ) const
inline

◆ GetPositionsCB()

ComputeBuffer * Hair::GetPositionsCB ( ) const
inline

Note transposed for better memory access.

◆ GetRenderPositions()

const Float3 * Hair::GetRenderPositions ( ) const
inline

◆ GetRenderPositionsCB()

ComputeBuffer * Hair::GetRenderPositionsCB ( ) const
inline

Render positions of the hair strands (see HairSettings::mRenderStrands to see where each strand starts and ends)

◆ GetRotations()

const Quat * Hair::GetRotations ( ) const
inline

◆ GetScalpTrianglesCB()

ComputeBuffer * Hair::GetScalpTrianglesCB ( ) const
inline

Skinned scalp triangle indices.

◆ GetScalpVertices()

const Float3 * Hair::GetScalpVertices ( ) const
inline

Access to the resulting simulation data (only valid when ReadBackGPUState has been called and the buffers have been locked)

◆ GetScalpVerticesCB()

ComputeBuffer * Hair::GetScalpVerticesCB ( ) const
inline

Access to the resulting simulation data.

Skinned scalp vertices

◆ GetVelocities()

StridedPtr< const Float3 > Hair::GetVelocities ( ) const
inline

◆ GetVelocitiesCB()

ComputeBuffer * Hair::GetVelocitiesCB ( ) const
inline

Note transposed for better memory access.

◆ GetVelocityAndDensityCB()

ComputeBuffer * Hair::GetVelocityAndDensityCB ( ) const
inline

Velocity grid.

◆ GetWorldTransform()

RMat44 Hair::GetWorldTransform ( ) const
inline

◆ Init()

void Hair::Init ( ComputeSystem * inComputeSystem)

Initialize.

◆ InitializeContext()

void Hair::InitializeContext ( UpdateContext & outCtx,
float inDeltaTime,
const PhysicsSystem & inSystem )
protected

◆ LockReadBackBuffers()

void Hair::LockReadBackBuffers ( )

Lock/unlock the data buffers so that the functions below return valid values.

◆ OnTeleported()

void Hair::OnTeleported ( )
inline

The hair will be initialized in its default pose with zero velocity at the new position and rotation during the next update.

◆ OverrideRenderPositionsCB()

void Hair::OverrideRenderPositionsCB ( const RenderPositionsToFloat3 & inRenderPositionsToFloat3)
inline

Enable externally set render vertices buffer (with potentially different vertex layout). Note that this also requires replacing the HairCalculateRenderPositions shader.

◆ ReadBackGPUState()

void Hair::ReadBackGPUState ( ComputeQueue * inComputeQueue)

Read back the GPU state so that the functions below can be used. For debugging purposes only, this is slow!

◆ SetPosition()

void Hair::SetPosition ( RVec3Arg inPosition)
inline

Position and rotation of the hair in world space.

◆ SetRenderPositionsCB()

void Hair::SetRenderPositionsCB ( ComputeBuffer * inBuffer)
inline

Allow setting the render vertices buffer externally in case it has special requirements for the calling application. You may need to override JPH_SHADER_BIND_RENDER_POSITIONS in HairCalculateRenderPositionsBindings.h to match the format of the provided buffer.

◆ SetRotation()

void Hair::SetRotation ( QuatArg inRotation)
inline

◆ SetScalpToHead()

void Hair::SetScalpToHead ( Mat44Arg inMat)
inline

When skipping skinning, this allow specifying a transform that transforms the scalp mesh into head space.

◆ SetScalpTrianglesCB()

void Hair::SetScalpTrianglesCB ( ComputeBuffer * inBuffer)
inline

Ability to externally provide the scalp triangle indices buffer. This allows skipping skinning the scalp in during the simulation update. You may need to override JPH_SHADER_BIND_SCALP_TRIANGLES in HairSkinRootsBindings.h to match the format of the provided buffer.

◆ SetScalpVerticesCB()

void Hair::SetScalpVerticesCB ( ComputeBuffer * inBuffer)
inline

Ability to externally provide the scalp vertices buffer. This allows skipping skinning the scalp during the simulation update. You may need to override JPH_SHADER_BIND_SCALP_VERTICES in HairSkinRootsBindings.h to match the format of the provided buffer.

◆ UnlockReadBackBuffers()

void Hair::UnlockReadBackBuffers ( )

◆ Update()

void Hair::Update ( float inDeltaTime,
Mat44Arg inJointToHair,
const Mat44 * inJointMatrices,
const PhysicsSystem & inSystem,
const HairShaders & inShaders,
ComputeSystem * inComputeSystem,
ComputeQueue * inComputeQueue )

Step the hair simulation forward in time

Parameters
inDeltaTimeTime step
inJointToHairTransform that transforms from joint space to hair local space (as defined by GetWorldTransform)
inJointMatricesArray of joint matrices in world space, length needs to match HairSettings::mScalpInverseBindPose.size()
inSystemPhysics system used for collision detection
inShadersPreloaded hair compute shaders
inComputeSystemCompute system to use
inComputeQueueCompute queue to use

Member Data Documentation

◆ mCollisionPlanesCB

Ref<ComputeBuffer> Hair::mCollisionPlanesCB
protected

◆ mCollisionShapesCB

Ref<ComputeBuffer> Hair::mCollisionShapesCB
protected

◆ mConstantsCB

Ref<ComputeBuffer> Hair::mConstantsCB
protected

◆ mGlobalPoseTransformsCB

Ref<ComputeBuffer> Hair::mGlobalPoseTransformsCB
protected

◆ mIterationConstantsCB

Array<Ref<ComputeBuffer> > Hair::mIterationConstantsCB
protected

◆ mLayer

ObjectLayer Hair::mLayer
protected

◆ mMaterialsCB

Ref<ComputeBuffer> Hair::mMaterialsCB
protected

◆ mPosition

RVec3 Hair::mPosition
protected

◆ mPositions

Float3* Hair::mPositions = nullptr
protected

◆ mPositionsCB

Ref<ComputeBuffer> Hair::mPositionsCB
protected

◆ mPositionsReadBackCB

Ref<ComputeBuffer> Hair::mPositionsReadBackCB
protected

◆ mPreviousPositionsCB

Ref<ComputeBuffer> Hair::mPreviousPositionsCB
protected

◆ mPrevPosition

RVec3 Hair::mPrevPosition
protected

◆ mPrevRotation

Quat Hair::mPrevRotation
protected

◆ mRenderPositions

const Float3* Hair::mRenderPositions = nullptr
protected

◆ mRenderPositionsCB

Ref<ComputeBuffer> Hair::mRenderPositionsCB
protected

◆ mRenderPositionsOverridden

bool Hair::mRenderPositionsOverridden = false
protected

◆ mRenderPositionsReadBackCB

Ref<ComputeBuffer> Hair::mRenderPositionsReadBackCB
protected

◆ mRenderPositionsToFloat3

RenderPositionsToFloat3 Hair::mRenderPositionsToFloat3
protected

◆ mRotation

Quat Hair::mRotation
protected

◆ mRotations

Quat* Hair::mRotations = nullptr
protected

◆ mScalpJointMatricesCB

Ref<ComputeBuffer> Hair::mScalpJointMatricesCB
protected

◆ mScalpToHead

Mat44 Hair::mScalpToHead = Mat44::sIdentity()
protected

◆ mScalpTrianglesCB

Ref<ComputeBuffer> Hair::mScalpTrianglesCB
protected

◆ mScalpVertices

const Float3* Hair::mScalpVertices = nullptr
protected

◆ mScalpVerticesCB

Ref<ComputeBuffer> Hair::mScalpVerticesCB
protected

◆ mScalpVerticesReadBackCB

Ref<ComputeBuffer> Hair::mScalpVerticesReadBackCB
protected

◆ mSettings

RefConst<HairSettings> Hair::mSettings
protected

◆ mShapeIndicesCB

Ref<ComputeBuffer> Hair::mShapeIndicesCB
protected

◆ mShapePlanesCB

Ref<ComputeBuffer> Hair::mShapePlanesCB
protected

◆ mShapeVerticesCB

Ref<ComputeBuffer> Hair::mShapeVerticesCB
protected

◆ mTargetGlobalPoseTransformsCB

Ref<ComputeBuffer> Hair::mTargetGlobalPoseTransformsCB
protected

◆ mTargetPositionsCB

Ref<ComputeBuffer> Hair::mTargetPositionsCB
protected

◆ mTeleported

bool Hair::mTeleported = true
protected

◆ mVelocities

JPH_HairVelocity* Hair::mVelocities = nullptr
protected

◆ mVelocitiesCB

Ref<ComputeBuffer> Hair::mVelocitiesCB
protected

◆ mVelocitiesReadBackCB

Ref<ComputeBuffer> Hair::mVelocitiesReadBackCB
protected

◆ mVelocityAndDensity

const Float4* Hair::mVelocityAndDensity = nullptr
protected

◆ mVelocityAndDensityCB

Ref<ComputeBuffer> Hair::mVelocityAndDensityCB
protected

◆ mVelocityAndDensityReadBackCB

Ref<ComputeBuffer> Hair::mVelocityAndDensityReadBackCB
protected

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