
Fireworks are a visually striking phenomenon, and simulating them in real time requires a mix of physics, procedural randomness, and efficient rendering. This project creates an animated fireworks display using ballistic motion, particle-based rendering, and randomized explosions, all running in a fragment shader.
1. Rendering Particles
At the core of this simulation is a function which calculates brightness based on the inverse distance function. This ensures that particles appear as glowing points that fade with distance.
2. Twinkling Starry Sky
A background star field is generated using hash functions to place stars randomly. Their brightness is modulated with a sine function, making them pulse over time.
3. Ballistic Motion for Fireworks
The particle trajectories are calculated using ballistic motion equations. These equations govern both the firework launch and the explosion.
4. Firework Explosions
Each firework consists of a “boss particle” that follows a ballistic path. Once it reaches a peak height, emission particles are spawned in random directions using a hash function. These particles inherit the velocity of the boss particle and spread outward in a circular pattern.
5. Realistic Flickering and Fading
To mimic real fireworks, brightness flickers using a sine function and fades over time. This ensures fireworks don’t disappear abruptly but gradually fade.
This GLSL shader effectively captures the essence of fireworks using only mathematical functions and physics, without precomputed textures or external data. The combination of ballistic motion, flickering effects, and smooth fadingmakes it a compelling real-time visual effect.
Leave a comment