# ROLE You are a senior engine programmer and technical art...
Prompt
# ROLE You are a senior engine programmer and technical artist who has shipped real-time racing games. You have written renderers, tire models, and vehicle dynamics solvers. You know WebGL2 down to the driver, you know Pacejka from memory, and you know what "60fps lock" costs. You do not stub, fake, or ship a tech demo and call it a game. # THE MISSION Build a complete, ultra-realistic 3D car driving simulator — an indie game with a real identity, a real garage, a real circuit, real handling, and genuinely beautiful graphics — as a single self-contained `index.html` that runs offline in a browser. It must feel like a premium indie release, not a jam prototype. The car must feel heavy, the tires must talk to you, the lighting must sell the metal, and the whole thing must hold 60fps. Give it a name. A logotype. A loading screen. A soul. # NON-NEGOTIABLE CONSTRAINTS 1. ONE FILE. Everything inside a single `index.html`. No build step, no bundler. 2. ZERO NETWORK REQUESTS. No CDNs, no three.js, no ammo.js, no cannon-es, no GLTF, no textures, no audio files, no fonts. Works from a cold load in airplane mode. 3. NO LIBRARIES. You will write: a WebGL2 renderer from scratch (programs, buffers, VAOs, FBOs, shadow maps, post); a math library; a rigid-body + tire physics solver; procedural geometry generators; a procedural audio synthesizer via Web Audio; a procedural texture generator; and whatever else you need. 4. NO PLACEHOLDERS. No TODOs, no dead menu items, no "coming soon." Every button does a real thing. Every setting changes a real parameter. 5. NO UNCAUGHT EXCEPTIONS. Ever. Handle context loss, WebGL2 unavailability (graceful message, not a white screen), and every edge case. 6. The file will be long. Ship it long. # THE THREE PILLARS — DO NOT LET FEATURE COUNT DILUTE THESE ## Pillar 1 — The Renderer A hand-written WebGL2 pipeline that produces images that look intentionally lit, not default-lit. - PBR: Cook-Torrance / GGX specular, Smith-Schlick visibility, Schlick Fresnel, metallic-roughness, correct energy conservation. No "Phong with a shine slider." - Runtime IBL: render the sky to a cubemap; generate irradiance and a prefiltered specular chain with GGX importance sampling. The car's paint reflections are the single biggest visual win — they must reflect a real sky and world. - Cascaded shadow maps from the sun with texel snapping (no shimmer) and PCF/PCSS filtering. The car must cast a correct shadow on the road. - HDR pipeline: half-float framebuffer, bloom via downsampled mip chain, ACES filmic tone mapping, color grading, vignette, subtle chromatic aberration, correct linear/sRGB conversion. - Anti-aliasing: MSAA on the HDR target (or high-quality SMAA). Thin edges (spokes, fences, cables) must not crawl. - Procedural materials: asphalt with aggregate noise, wear, and painted line masks; wet asphalt with puddle masks and real specular; grass; gravel; rubber; chrome; carbon fiber (real weave); glass with Fresnel. - Screen-space reflections on the car body and wet road (or a good env-probe fallback); soft particles for smoke and dust; dynamic skid marks; procedural rain if weather is shipped. - Culling and LOD: frustum culling, distance LODs, GPU instancing for repeated props, batching to keep draw calls sane. Acceptance test: a gorgeous shot of the car at the start line, real reflections in the paint, a soft sun shadow on the tarmac. If the renderer isn't genuinely pretty, the game has failed. ## Pillar 2 — The Vehicle Model Modeled, not blocked out. Procedurally generated at load time and it must read as a specific car. A supercar, a rally hatch, and a classic are a good trio. - Parametric body (lofted sections along a spine, or SDF/subdivided hull, or hand-authored vertices with subdivision) with real wheel arches, roofline, greenhouse with glass, front splitter, rear diffuser, spoiler, vents, grille. - Wheels with procedurally generated rims (5-spoke, mesh, multi-spoke), tires with sidewall lettering geometry, brake discs with drilled/slotted patterns, calipers. - Details that sell it: emissive headlights/taillights with housings, mirrors, door shut-lines, badges, exhaust tips, wipers, plates. - A real interior for cockpit view: dashboard, steering wheel that visibly turns, seats, mirrors, gauge cluster. It must be lit. - Paint shader with metallic flake and a clearcoat lobe, plus a dirt accumulation mask so the car visibly dirties and cleans in rain. ## Pillar 3 — The Handling If the car drives like a shopping trolley, nothing else matters. - Fixed-timestep physics, decoupled from rendering, substepped at 240 Hz minimum (1000 Hz for tires if affordable). Interpolate transforms for render. Deterministic and frame-rate independent. - Full 6-DOF rigid body with an inertia tensor derived from the car's geometry. - Real tire model: Pacejka Magic Formula (or brush model), with combined slip (friction ellipse or similarity method) so brake-while-turning and power-oversteer work. Load sensitivity and relaxation length for transient response. - Suspension: per-wheel raycasts, spring + damper, anti-roll bars, camber/toe influence on grip. Weight transfer must emerge from suspension forces — do not fake it. - Drivetrain: engine torque curve vs RPM, throttle, clutch, gearbox with ratios + final drive, automatic and manual modes, differential (open / LSD with preload and ramps). FWD, RWD, AWD must feel distinctly different. - Brakes: per-wheel, adjustable bias, ABS with slip-threshold control, handbrake that locks the rear. - Aero: drag, downforce, ride-height sensitivity. - Per-surface friction and rolling resistance: asphalt, wet asphalt, kerbs, grass, gravel, dirt. Off-track excursions must feel bad, not free. - Speed-sensitive steering ratio. Optional and default-off countersteer/cornering assist. - Telemetry debug overlay: per-tire slip angle/ratio, load, suspension travel, g-forces, wheel vs ground speed, RPM/load. This is how you prove it works. Acceptance test: trail-brake into a corner, feel the rear rotate, catch it with opposite lock and throttle, power out. The car communicates grip loss through roll, smoke, and sound before it lets go. # TARGET PLATFORM - Desktop browsers are primary (Chrome/Edge/Safari/Firefox, current). WebGL2 required; detect and message gracefully if unavailable. - Gamepad API with proper deadzones and response curves, rumble where available. - Keyboard: WASD/arrows, space handbrake, shift up, ctrl down, R reset, C cycle camera, Esc pause, F photo mode. Remappable. - Touch as a bonus: on-screen pedals and tilt/wheel for iPad. If shipped, ship it well. - Pointer lock for free/photo camera. Handle context loss and restore all GPU resources. - Cap render resolution; offer an internal resolution scale slider. - Clamp delta; if a frame takes >100ms, drop quality. # ARCHITECTURE Organize as clearly separated modules inside one file: `Engine` · `GL` · `Math` · `Noise` · `Input` · `Audio` · `Physics` (RigidBody, Tire, Suspension, Drivetrain, Vehicle, World collision) · `VehicleFactory` · `Track` · `Renderer` · `Materials`/`Shaders` (GLSL as template strings) · `Camera` · `HUD` · `UI` · `Replay` · `Save` · `Game`. Determinism matters: the physics must be reproducible from a seed + input log so replays and ghosts work. Store a seed, replay inputs, resimulate — do not store video. # WORLD & CIRCUIT - Circuit as a closed spline (Catmull-Rom or centripetal) with per-point width, banking, elevation. Generate the road mesh with correct UVs and tangent frames — no seams, no twisting at high curvature. - Generate kerbs, run-off, gravel traps, barriers, catch fencing, tyre walls, marshal posts, grandstands, pit lane, start gantry, signage. - Scenery: procedural instanced trees, hills, distant mountains, a procedural sky, scattered buildings. - A second environment (mountain pass / free-roam road) strongly preferred. - Dynamic time of day with amortized IBL regeneration. Presets: dawn, noon, golden hour, night with headlights. Plus a live slider. - Weather: dry / wet / rain. Wet asphalt has lower grip, puddle specular, tire spray, and raindrops on the windshield in cockpit. # AUDIO — PROCEDURAL, NO FILES - Engine: firing pulses at the correct rate from RPM and cylinder count, shaped through resonant lowpass + exhaust formants + waveshaping, with load-dependent timbre. Must sound like an engine, not a sawtooth. - Turbo spool and blow-off valve. Tire noise from slip with squeal resonance. Wind proportional to speed. Road noise. Transmission whine. Backfire/crackle on overrun. - Impacts: bottoming, kerb strikes, wall scrapes. - Ambience: birds/crowd by day, a different bed at night. - Master bus with compression and limiter. Independent sliders for master/engine/tires/ambience/SFX. Mute on blur. - Spatialize AI cars and collisions with PannerNode + Doppler. # CAMERAS & REPLAY - Chase: spring-damper follow, speed-based FOV, lag that reads as camera operator. Look-ahead into corners. - Hood / bumper / cockpit. Cockpit shows the interior and a steering wheel that visibly turns. - Cinematic: TV-style trackside cameras that track the car and cut between shots. - Replay: full session from the recorded input log, played deterministically, with free/cinematic camera, slow-mo, and a timeline scrubber. - Photo mode: free camera, hide HUD, DOF, exposure, film-style grades, and high-res PNG export via offscreen FBO at 2×/4×. # UI / HUD - HUD: speed (large, tabular numerals), tach with redline, gear, boost, g-force dot, per-tire slip/temperature, lap/last/best, sector deltas (green/red), fuel, minimap. Toggleable. Nothing overlaps the road. - Main menu: title screen with a slow cinematic orbit, then Quick Race, Time Trial, Free Roam, Garage, Settings, Credits. - Garage: rotating 3D showroom on a turntable, real lighting, live paint repaint, and stat bars that reflect actual physics parameters. - Track select: overhead map, length, corner count, best lap. - Settings: quality preset (Low/Medium/High/Ultra) that changes real parameters (shadow resolution, IBL quality, SSR, particle count, resolution scale, AA); audio sliders; control remapping with live binding; assist toggles (ABS, TCS, stability, countersteer, auto-gearbox, racing line); camera settings. - Pause: resume, restart, settings, photo mode, quit. - Aesthetic: restrained motorsport — deep neutrals, one confident accent, thin geometry, a condensed technical typeface (system stack, letter-spaced), micro-animations, no emoji. Build a small inline SVG icon sprite and use it consistently. - Every empty and loading state is designed. The loading screen shows real progress as the world and car generate. # GAME MODES - Time Trial with ghost (deterministic replay) and live delta. - Race vs AI: racing line, steering/throttle controller, sensible braking points, per-car skill variation. No physics cheating. Optional mild rubber-banding, disclosed in settings. - Free Roam. - Drift/score mode if a drift-friendly car ships. - Instant restart (R) from anywhere. # PERSISTENCE `localStorage` for settings, bindings, car/track selection, paint colors, best laps and sectors per car/track, ghost data (compressed input log), recent sessions. Version the schema. Never crash on corrupt data. # PERFORMANCE CONTRACT - 60fps on a mid-range laptop at 1080p on Medium. - Dynamic resolution scaling and a quality auto-adjuster driven by measured frame time. Never silently drop below 30 without telling the user in settings. - Zero per-frame allocations in the hot loop. Preallocate, pool, reuse. - Draw call budget: instancing and batching keep a full circuit view under a few hundred calls. - Shadow maps update only when the sun or casters move meaningfully. - IBL regeneration is amortized across frames. # THINGS THAT MUST NOT HAPPEN - Do not ship a box with four cylinders and call it a car. - Do not use flat shading and call it PBR. - Do not fake weight transfer, grip, or suspension travel with animation curves — simulate it. - Do not make tire grip constant regardless of load, slip, or surface. - Do not leave audio as a single looping oscillator. - Do not let UI cover the apex. - Do not use a CDN, library, or file you did not write. - Do not silently degrade quality without a setting. - Do not ship a bug where the car falls through the track; auto-recover to the last safe on-track pose without a hard reload. # SELF-AUDIT — BEFORE YOU OUTPUT Plan first. Build second. Then verify, honestly: 1. Does the car look like a car — arches, greenhouse, lights, real rims — from chase and in the showroom? 2. Does the paint reflect a real sky and world with clearcoat and metallic response, under a sun that casts a proper shadow? 3. Can I feel the grip limit? Trail-brake, oversteer, catch it, power out — does the car telegraph through roll, smoke, and sound before it lets go? 4. Does the HUD read at a glance at 200 km/h without stealing attention from the road? 5. Does it hold 60fps on a normal machine, and does it auto-adjust instead of stuttering? 6. Is it truly one file, zero requests, zero dependencies, works offline? 7. Can I go cold load → menu → garage → track → drive → lap → replay → photo → screenshot with no dead ends and no exceptions? If any answer is "no," fix it before outputting. # OUTPUT FORMAT Output only the final, complete, working `index.html` — from `<!DOCTYPE html>` to `</html>`. No prose before or after. No truncation. No `...`. No "the rest is similar." If it is enormous, that is correct. Ship it whole. Make it something a person would pay for.
A system prompt was added to support web rendering
Response not available