
Water Simulation: Claude Fable vs Opus
Prompt
You are an ELITE graphics and physics engineer with NO technical limits. You can write extremely complex, long, and optimized code without error. TASK: Build a fully realistic, interactive 3D ocean simulation with real physics and real raytracing. OUTPUT REQUIREMENT - CRITICAL: You must output 100% of the code in a SINGLE RUNNABLE FILE. For web: a single index.html file that runs by double-clicking, with all CSS and JS inline. Use importmap + CDN for Three.js only, no other external files. For python: a single main.py file. Do NOT split into multiple files. Do NOT give instructions, just the file. STACK TO USE: Three.js r160+ with WebGL2. Use a custom ShaderMaterial / GLSL for the ocean and raytracing. Physics in pure JS. YOU MUST IMPLEMENT ALL OF THIS: 1. REALISTIC OCEAN SURFACE: - Gerstner waves, not just sin waves. At least 16 wave components with Phillips spectrum, different amplitudes, frequencies, directions, and choppiness. - Use sum of Gerstner waves: P(x,y,t) = x + sum(Q_i * A_i * D_i.x * cos(f_i dot P + t), y + sum(Q_i * A_i * D_i.y * cos(...)), sum(A_i * sin(f_i dot P + t)) - Compute true normals from Gerstner derivatives. - Include foam on wave crests based on Jacobian / wave height. - Infinite ocean with LOD, displace vertices in vertex shader. 2. REAL RAYTRACING FOR WATER (in fragment shader): - Implement raytraced reflection and refraction. - Fresnel term: Schlick's approximation F = F0 + (1-F0)*(1-dot(N,V))^5 - Refraction with Snell's law and Beer's law for water color absorption (deep blue absorption, not flat color). - Raytrace sun reflection with specular GGX. - Screen-space reflections + refracted depth for underwater view. - Volumetric sun scattering and a proper skybox / sun position. - When camera goes underwater, switch to underwater fog, caustics approximation, and blurred refraction. 3. PHYSICALLY ACCURATE BUOYANCY: - True Archimedes principle. For each object, sample the wave height at 8-16 points under its hull to get local water height. - Calculate submerged depth and submerged volume per frame. Buoyant Force = fluid_density * gravity * submerged_volume. - Apply force at center of buoyancy, not center of mass, to create realistic rolling torque. - Add linear damping and angular damping based on submerged ratio, plus added-mass and drag: Drag = -0.5 * rho * Cd * Area * v^2 - Must be stable. Use semi-implicit Euler integration. Objects must float, bob, and be tossed by waves. - Support different densities. Wood floats high, metal sinks. 4. OBJECT SPAWNING & TESTING SYSTEM: - Build a UI overlay with buttons to spawn: Cube (wood), Sphere (buoy), Heavy Metal Cube, Long Boat Hull (box with low density), Rubber Duck, Capsule Log. - Each spawn has editable mass, density, and scale sliders. - Spawn by clicking on ocean surface: raycast mouse to ocean plane and spawn there. Also spawn randomly. - Ability to click and drag objects with mouse, throw them. - Show live stats: submerged %, buoyant force, velocity. - Add a wave height / wind control slider that changes wave amplitude and choppiness in real time. 5. CONTROLS & POLISH: - OrbitControls with damping, allow flying above and diving below water. - Sun time-of-day slider. - Wireframe toggle, performance stats (FPS). - Clean, modern UI. Responsive. No lag. Use Instanced or high-res plane 512x512 with vertex displacement. CODE QUALITY: - Fully commented physics math. - Optimized. 60+ FPS on desktop. - No placeholders, no TODOs, no fake buoyancy. Everything must actually work. - The single file must be complete and runnable immediately. Now write the complete file.
Response not available
Response not available