GPU Feather Simulation

High-performance compute shader for realistic feather dynamics.

BirdShaders.hlsl

// BirdShaders.hlsl — GPU Feather Simulation
StructuredBuffer<float3> FeatherBasePositions;
RWStructuredBuffer<float3> FeatherPoints;
cbuffer FeatherParams { float WindStrength; float Flexibility; float Time; }

[numthreads(256, 1, 1)]
void main(uint3 id : SV_DispatchThreadID)
{
    float3 base = FeatherBasePositions[id.x];
    float3 p = FeatherPoints[id.x];

    float wind = sin(Time * 3 + id.x * 0.1) * WindStrength;
    float curl = curlnoise(p * 0.25) * 0.3;

    // Feather bending = base anchor + wind deformation + curl turbulence
    p = lerp(base, p + float3(0, wind, curl), Flexibility);

    FeatherPoints[id.x] = p;
}

Buffers

  • FeatherBasePositions: Original feather positions
  • FeatherPoints: Current feather positions (RW)
  • FeatherParams: Simulation parameters

Techniques

  • Compute shader with 256 threads
  • Procedural wind animation
  • Curl noise for turbulence
  • Flexibility-based interpolation

Shader Breakdown

Thread Execution

The shader runs 256 threads per dispatch, processing individual feather points in parallel. Each thread uses its SV_DispatchThreadID to index into the structured buffers containing feather positions.

Wind Simulation

Wind is simulated using a sine wave that varies over time and across different feathers. The WindStrength parameter controls intensity while the phase offset (id.x * 0.1) creates variation.

Curl Noise

Curl noise generates divergence-free turbulence patterns ideal for fluid-like motion. The scaled result (0.3) adds subtle, natural-looking perturbations to the feather movement.

Flexibility

The Flexibility parameter controls how much feathers deviate from their base positions. A lerp operation smoothly blends between anchored and dynamic states.

Visualization

Feather simulation visualization