NEON COASTER — a roller coaster with a follow camera
NEON COASTER is an automatic four-car ride around a three-dimensional night course, viewed through an EyeRig that continuously follows the lead car. A closed Catmull–Rom curve generates the rails, sleepers, supports, and vehicle poses, combining climbs, drops, turns, and banking into one lap. Behind the last car, control points move gradually to change the course shape; on the next lap, the cars follow the updated rail. Three outer rings of 72 buildings form a skyline; each building's width, depth, and height vary by a signed 2–4 meters from their baseline dimensions. Their windows range from warm white and cream to amber and orange. Metallic rails and cars, an emissive guide, city lights, and speed particles share the same PBR frame to make the motion of the camera and track communicate speed.
Running and controls
Open neon_coaster.html in a WebGPU-capable browser. The train starts automatically with TURBO ON at 183 km/h. Pressing TURBO switches to the normal 118 km/h speed; PAUSE suspends vehicle motion and the emission of new speed particles. MUSIC starts or stops the 175 BPM run_neon preset. Audio begins only after a button press; master volume is 40% and BGM volume is 34%.
The follow camera uses a 70° short-side field of view for a wider view of the course. Drag on the Canvas to adjust the follow angle, and use the wheel to change the distance from the train between 6 and 33 units. Zooming out provides a broad view of the course. The top display reports current speed, height, and bank angle. The Canvas tracks the window size.
webg features used
CoasterApp extends WebgSceneApp, connecting a follow-mode EyeRig and several colored Deferred Lighting sources to the standard PBR scene. The camera hierarchy is attached to the lead car and looks 3.5 units ahead in vehicle-local space. Its position is 12 units behind and 2.6 units above the vehicle, with the course bank used as the up-direction reference. The short-side field of view is set to 70°; follow orientation uses a response of 18 and a maximum angular speed of 720 degrees per second.
Rail twist is created as banking around the direction of travel, by rotating the local side and up axes. At normalized lap position t, a fine four-cycle wave sin(8πt) × 8° is combined with a gradual one-cycle wave sin(2πt + 0.7) × 13°; multiplying their sum by 45/21 keeps the theoretical bank range within ±45°. The resulting orientation is shared by the rail cross-sections, sleepers, and cars, and the Follow camera uses the car's banked up direction. The waves depend on lap position, so their timing is laid out across the whole course.
The rails and emissive guide are tube meshes generated along the curve with Shape. The center guide divides the full course into four equal sections, glowing green, orange, blue, and white in order. The original nine-point curve is resampled into 12 control points, forming 12 Catmull–Rom spans and 12 render chunks. The 12 control points produce broad, smooth changes across the course. Each Catmull–Rom control point affects four neighboring spans. When the last car enters span b, the control point two points behind, P[b−2], begins to move; all four affected spans (b−4 through b−1) are already behind the train. A change starts every span. The target is offset from the control point's initial position by up to ±3.0 laterally and ±1.8 vertically, then reached smoothly over 0.82 seconds. Only the four affected chunks are rebuilt: their three rails and support shapes. Sleeper transforms are updated to match. Cars sample the same control-point array, so they follow the updated rail on the next lap.
Sleepers, cars, and distant beacons use instances of shared geometry. The lead car is red, while the following cars use dark blue metallic materials with restrained self-illumination so the full train remains legible through dark sections. A single level of slim, reflective silver tube handrails runs slightly inside the body edges of all four cars. The horizontal tubes sit about 0.14 units above the body top, forming a low frame. The pillar sides use a blue-gray material with high metallic and low roughness values, producing sharp reflections of the colored lights. The floor is a dark blue-gray surface with reduced metallic reflection, keeping the night setting while revealing its outline slightly. PBR materials, environment lighting, six point lights, a directional shadow map, SSR, and Bloom combine metallic reflections with emissive details. SSAO and depth of field are disabled to emphasize moving rail silhouettes, reflections, and light.
SceneYAML defines rendering settings and the standard ComputeParticleEmitter. While the train moves, red-to-orange particles spawn just outside each side of the lead car about every 0.045 seconds. The count on each side oscillates between 2 and 16 over about 1.4 seconds, creating waves of spark density. Particles travel diagonally backward at 45 degrees with speeds from 1.05 to 3.75 and disappear after 0.2 to 0.55 seconds. A Compute Shader updates their positions, velocities, and lifetimes. GameAudioSynth synthesizes the BGM from its built-in score.
What to check
Verify that the lead car, rails, and direction of travel remain visible together, and that the camera follows smoothly through climbs and drops. During turns, the vehicle and camera share the course bank; after a drag adjustment, the camera continues tracking the lead direction. Keep riding to see a control point move behind the last car and the affected rails, sleepers, and supports update smoothly. On the next lap, verify that the cars stay on the updated rail. PAUSE also freezes the control point and geometry changes. The ride starts at 183 km/h with TURBO ON; pressing it switches to the normal 118 km/h speed. Look for low handrails on all four cars and periodic thickening and thinning of the spark trails on both sides.
In the night scene, compare the city pillar caps cycling through cyan, magenta, green, and orange, the mostly cyan and magenta distant beacons, metallic rail highlights, and the particle trail behind the train. SSR uses information already visible on screen, so reflections change with camera position and near screen edges.
Reading the implementation
scene.yaml contains rendering and particle settings. track.js evaluates the curve and builds the course and train. CoasterApp.js installs the follow camera and lighting. main.js handles ride updates, the HUD, controls, music, and shutdown. style.css defines the full-window presentation and responsive HUD. Sample-specific extensions stay in this folder and use the published webg core modules directly.