Bone Attachemnts
- CPU Animator
- GPU Animator
CPU Animator
writes animated bone positions back to the LocalTransform
components of corresponding bone entities. No special preparation step is needed to work on bone attachments properly. Just make the attachment entity a child of required bone entity.
Bone entities cannot be moved by the GPU animation engine. The simple attachment process used in the CPU Animator
would not work. Because bone calculation is performed on GPU, all frame bone placement data is stored in GPU memory and cannot be copied to the main memory to be used by entities at the same frame. Nevertheless, a special shader can be created, which will move all model vertex positions according to the animation frame.
Bone attachment shader using ShaderGraph
The process is similar to the making of a deformation-aware shader for an ECS skinned mesh renderer.
- Create a new shader graph according to the render pipeline used in your project.
- Open it and add the
Custom Function
node. - Set
Type
toFile
. - Set
Name
toGPUAttachmentMeshMover
. - Set
Source
toGPUAttachmentShaderNode.hlsl
(located atRukhanka.Runtime/GPUAnimationEngine/Resources/GPUAttachment
directory). - Configure three input ports of this custom node:
vertex
with typeVector 3
.normal
with typeVector 3
.tangent
with typeVector 3
.
- Configure three output ports:
animatedVertex
with typeVector 3
.animatedNormal
with typeVector 3
.animatedTangent
with typeVector 3
.
- Create three additional nodes in the shader graph:
Geometry Position
withSpace
property set toObject
.Geometry Normal Vector
withSpace
property set toObject
.Geometry Tangent Vector
withSpace
property set toObject
.
- Connect the
Out
port of thePosition
node with thevertex
port of theGPUAttachmentMeshMover (Custom Function)
node. - Connect the
Out
port of theNormal Vector
node with thenormal
port of theGPUAttachmentMeshMover (Custom Function)
node. - Connect the
Out
port of theTangent Vector
node with thetangent
port of theGPUAttachmentMeshMover (Custom Function)
node. - Connect the
animatedPosition
,animatedNormal
, andanimatedTangent
output ports of theGPUAttachmentMeshMover (Custom Function)
node to the vertex position, normal, and tangent ports in the master node respectively.
You should get the following shader graph:
- Complete fragment part of the shader graph with appropriate texture sampling (albedo, normal map), color modulation, etc.
Use the created shader as a material shader of your GPU-attached meshes.
Marking mesh as GPU attachment
Rukhanka must supply a GPU attachment shader with appropriate rig data. To be able to do this, you must add GPU Attachment Authoring
Unity component to every authoring mesh in authoring GameObject:
Object with GPU bone attachment shader but without GPU Attachment Authoring
will be rendered incorrectly, or will completely disappear from the scene.
GPU attachments will work normally as ordinary CPU attachments