Skip to content

Instantly share code, notes, and snippets.

@sebbbi
Last active March 28, 2018 19:28
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sebbbi/2371bd0b67056df990f7d34c5505fcb2 to your computer and use it in GitHub Desktop.
Save sebbbi/2371bd0b67056df990f7d34c5505fcb2 to your computer and use it in GitHub Desktop.
BDF2 integrator in HLSL
void BFD2(inout ParticleSimulationData Particle, float3 Accel)
{
float3 x = Particle.Position;
float3 v = Particle.Velocity;
float3 x1 = Particle.PositionPrev;
float3 v1 = Particle.VelocityPrev;
Particle.Position = (4.0/3.0) * x - (1.0/3.0) * x1 + 1.0 * ((8.0/9.0) * v - (2.0/9.0) * v1 + (4.0/9.0) * TimeStep2 * Accel);
Particle.PositionPrev = x;
}
void BDF2VelocityUpdate(inout ParticleSimulationData Particle)
{
Particle.Velocity = (3.0/2.0) * Particle.Position - 2.0 * Particle.PositionPrev + 0.5 * Particle.PositionPrev2;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment