On this page
Single Object Pivot Data
When the mesh is not authored around the pivot, or when one object needs motion concentrated in a region, the pivot becomes data: a position in object space that the shader reads, and a mask that decides how much of the mesh follows it. The full three-step pattern appears for the first time here: subtract the pivot, rotate, add it back, blended by a per-vertex influence.
Position, pivot, and axis must agree on space. Object-space position with a world-space pivot is a silent, confusing failure.
float3 local = positionOS - pivotOS; // 1. into pivot-local space
local = RotateAroundAxis(local, axisOS, angle);
float3 rotated = pivotOS + local; // 2. back to object space
positionOS = lerp(positionOS, rotated, mask); // 3. influence decides how much
The pattern, fully general¶
The subtract / add form is the pivot pattern in its complete shape:
- Move into pivot-relative space:
local = positionOS - pivotOS. - Rotate around the chosen axis: Rodrigues’ formula, exactly as in Single Object Mesh Pivot, now applied to the offset vector.
- Move back:
rotated = pivotOS + local.
Then the third ingredient that single-pivot data adds: a mask. Vertex alpha as a stiffness/influence channel (0 means pinned to the original pose, 1 means fully rotated) lets one pivot drive a gradient of motion instead of a rigid hinge. The lerp between original and rotated position is the mask application.
Where the data comes from¶
Pivot data doesn’t have to come from one place. It can be:
- Hand-set: a
_PivotOSmaterial property. Fine for one object with one pivot. - Painted: vertex color painted by an artist (influence, stiffness).
- Baked: from object origins or a tool, packed into vertex colors, UVs, or custom streams, and decoded in the shader (the next page covers the bake).
Whatever the source: the packing and the decode must be documented. And, exactly as with masks, debug the pivot before you trust the rotation. Render the pivot, or the distance to it, as color and look at it. If the pivot data is wrong, the motion will be wrong no matter how good the rotation function is.
Visual demo¶
One object, one pivot, and a painted influence in the vertex alpha channel. The pivot debug glow marks the anchor; the influence decides how far each vertex follows the rotation, so the object bends from the pivot instead of swinging around it.
The complete pivot pattern with a property pivot, a painted influence mask, and the debug glow.
Shader "DecompiledArt/VertexAnimation/PivotMotion/SingleObjectPivotData/SingleObjectPivotData"
{
Properties
{
_BaseColor("Base Color", Color) = (0.45, 0.8, 0.35, 1.0)
[Header(Pivot Motion)]
_PivotOS("Pivot OS", Vector) = (0, 0, 0, 0)
_AxisOS("Axis OS", Vector) = (0, 0, 1, 0)
_Speed("Speed", Float) = 1.0
_AngleAmplitude("Angle Amplitude (Radians)", Float) = 0.5
_MaskStrength("Mask Strength", Range(0, 1)) = 1.0
[Header(Debug Pivot)]
[Toggle] _ShowPivotDebug("Show Pivot Debug", Float) = 0
_PivotDebugRadius("Pivot Debug Radius", Float) = 0.25
_PivotDebugColor("Pivot Debug Color", Color) = (1.0, 0.75, 0.05, 1.0)
_PivotDebugIntensity("Pivot Debug Intensity", Float) = 1.5
}
SubShader
{
Tags
{
"RenderType" = "Opaque"
"RenderPipeline" = "UniversalPipeline"
"Queue" = "Geometry"
}
Pass
{
Name "ForwardUnlit"
Tags { "LightMode" = "UniversalForward" }
Cull Back
ZWrite On
ZTest LEqual
HLSLPROGRAM
#pragma vertex Vert
#pragma fragment Frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
#define TWO_PI 6.2831853h
#define INV_TWO_PI 0.15915494h
CBUFFER_START(UnityPerMaterial)
half4 _BaseColor;
float4 _PivotOS;
float4 _AxisOS;
half _Speed;
half _AngleAmplitude;
half _MaskStrength;
half _ShowPivotDebug;
half _PivotDebugRadius;
half4 _PivotDebugColor;
half _PivotDebugIntensity;
CBUFFER_END
struct Attributes
{
float3 positionOS : POSITION;
half4 color : COLOR;
};
struct Varyings
{
float4 positionCS : SV_POSITION;
float3 originalOS : TEXCOORD0;
half4 color : COLOR;
};
// Rotate v around axis by angle (Rodrigues).
float3 RotateAroundAxis(float3 v, float3 axis, half angle)
{
axis = normalize(axis);
half s, c;
sincos(angle, s, c);
return v * c
+ cross(axis, v) * s
+ axis * dot(axis, v) * (1.0 - c);
}
Varyings Vert(Attributes IN)
{
Varyings OUT;
float3 positionOS = IN.positionOS;
float3 pivotOS = _PivotOS.xyz;
float3 axisOS = normalize(_AxisOS.xyz);
OUT.originalOS = positionOS;
// Vertex alpha becomes a stiffness mask:
// 0 = pinned to the original pose, 1 = fully rotated.
half mask = saturate(IN.color.a * _MaskStrength);
// Keep the phase bounded so this stays numerically stable.
half phase = frac(_Time.y * _Speed * INV_TWO_PI) * TWO_PI;
half angle = sin(phase) * _AngleAmplitude;
// The pivot pattern, fully general:
// 1. move into pivot-relative space
float3 local = positionOS - pivotOS;
// 2. rotate around the chosen axis
local = RotateAroundAxis(local, axisOS, angle);
// 3. move back into object space
float3 rotatedPositionOS = pivotOS + local;
// Blend back toward the bind pose so the mask drives partial motion.
positionOS = lerp(positionOS, rotatedPositionOS, mask);
OUT.positionCS = TransformObjectToHClip(positionOS);
OUT.color = IN.color;
return OUT;
}
half4 Frag(Varyings IN) : SV_Target
{
half3 color = _BaseColor.rgb;
if (_ShowPivotDebug == 1.0)
{
// Distance-to-pivot glow: the anchor made visible.
half dist = length(IN.originalOS - _PivotOS.xyz);
half radius = max(_PivotDebugRadius, 1e-4h);
half mask = 1.0h - saturate(dist / radius);
mask *= mask;
color += _PivotDebugColor.rgb * mask * _PivotDebugIntensity;
}
return half4(color, 1.0);
}
ENDHLSL
}
}
FallBack Off
}
🔗 Related Chapters¶
Single Object Mesh Pivot • Multiple Objects Pivot Bake • Authored Masks
Related functions: Cross • Lerp • Length
❤️ Support Shader Story¶
If this article helped you, consider supporting the project on Patreon: you’ll get access to the related source files and reference cheat-sheets.
Your support helps keep this library open and free for everyone.