Skip to content

Instantly share code, notes, and snippets.

@supertask
Created January 18, 2022 14:15
Show Gist options
  • Save supertask/f4462e54de148a885b5f72af5888be89 to your computer and use it in GitHub Desktop.
Save supertask/f4462e54de148a885b5f72af5888be89 to your computer and use it in GitHub Desktop.
Keijiro's GVoxelizer triangle FX
// -- Triangle fx --
// Simple scattering animation
// We use smoothstep to make naturally damped linear motion.
// Q. Why don't you use 1-pow(1-param,2)?
// A. Smoothstep is cooler than it. Forget Newtonian physics.
float ss_param = smoothstep(0, 1, param);
// Random motion
float3 move = RandomVector(seed + 1) * ss_param * 0.5;
// Random rotation
float3 rot_angles = (RandomVector01(seed + 1) - 0.5) * 100;
float3x3 rot_m = Euler3x3(rot_angles * ss_param);
// Simple shrink
float scale = 1 - ss_param;
// Apply the animation.
float3 t_p0 = mul(rot_m, p0 - center) * scale + center + move; //triangle position 0
float3 t_p1 = mul(rot_m, p1 - center) * scale + center + move; //triangle position 1
float3 t_p2 = mul(rot_m, p2 - center) * scale + center + move; //triangle position 2
float3 normal = normalize(cross(t_p1 - t_p0, t_p2 - t_p0));
// Edge color (emission power) animation
float edge = smoothstep(0, 0.1, param); // ease-in
edge *= 1 + 20 * smoothstep(0, 0.1, 0.1 - param); // peak -> release
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment