-
// BirdCharacter.h
class BirdCharacter : public AActor
{
public:
Vec3 velocity;
Vec3 wingNormal;
float stamina;
float hunger;
float featherFlexibility;
void Tick(float dt) override;
void UpdatePhysics(float dt);
void UpdateAnimation(float dt);
void HandleAbilities(float dt);
}; -
// FlockComputeShader.hlsl — Boids + Steering + Territory Aggression
StructuredBuffer<float4> BirdPositions;
StructuredBuffer<float4> BirdVelocities;
RWStructuredBuffer<float4> OutVelocities;
[numthreads(512, 1, 1)]
void main(uint3 id : SV_DispatchThreadID)
{
float3 pos = BirdPositions[id.x].xyz;
float3 vel = BirdVelocities[id.x].xyz;
float3 cohesion = 0;
float3 alignment = 0;
float3 separation = 0;
for(uint i=0;i<BIRD_COUNT;i++)
{
float3 p = BirdPositions[i].xyz;
float3 d = p - pos;
float dist = length(d);
if(dist < 0.001) continue;
// Neighborhood rules
if(dist < 20) cohesion += p;
if(dist < 15) alignment += BirdVelocities[i].xyz;
if(dist < 8) separation -= normalize(d) * (1.0 / dist);
}
cohesion = (cohesion / 50) - pos;
alignment /= 50;
float3 steering =
normalize(cohesion) * 0.4 +
normalize(alignment) * 0.3 +
normalize(separation) * 0.8;
float3 outVel = normalize(vel + steering) * 20;
OutVelocities[id.x… -
// 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;
} -
// 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;
} -
// Aerodynamics.cpp
AeroForces Aerodynamics::ComputeForces(
const Vec3& v,
const Vec3& n,
float area,
float density,
float flex)
{
float speed = v.Length();
float angle = acos(Clamp(Dot(Normalize(v), n), -1.0f, 1.0f));
// Classic aerodynamic lift model
float liftCoeff = sin(angle * 2.0f) * (1.0f + flex);
float dragCoeff = 0.02f + 0.3f * pow(sin(angle), 2.0f);
Vec3 lift = Cross(Cross(v, n), v).Normalized() * liftCoeff * speed * speed * area * density;
Vec3 drag = -Normalize(v) * dragCoeff * speed * speed * area * density;
// Turbulence: procedural noise + thermal updrafts
Vec3 turbulence = Vec3(
PerlinNoise3D(v * 0.1f),
PerlinNoise3D(v * 0.1f + 10),
PerlinNoise3D(v * 0.1f + 20)
) * flex * 0.5f;
return { lift, drag, turbulence };
} -
// Aerodynamics.h
#pragma once
#include "Math.h"
struct AeroForces {
Vec3 lift;
Vec3 drag;
Vec3 turbulence;
};
class Aerodynamics
{
public:
static AeroForces ComputeForces(
const Vec3& velocity,
const Vec3& wingNormal,
float wingArea,
float airDensity,
float featherFlexibility);
};