Simulation and Rendering of RealTime Breaking Waves Adam Lake, David Reagin, John Van Drasek Intel Software Solutions Group (SSG) Modern Game Technologies Project 2/27/2005 “We arrive at the truth, not by the reason only, but also by the heart.” -- Blaise Pascal Motivation • Great real-time results for deep ocean but what about close to shore? – Sum of Sines [Isidoro02], [Finch04] – Tessendorf, etc. [Tessendorf01] • Little work on breaking waves in computer graphics! – Animation and Control of Breaking Waves [Mihalef04] • Navier Stokes and store – None emphasize real-time breaking waves Getting water right requires… • Geometry – Overall shape must be correct • Shading – Lighting and shading • Additional Geometry/Texture – Capillary waves, foam, etc. must be modeled Goal: • Get the geometric solution to look right • Shading and additional geometry are areas of future work – Good candidates for vertex and pixel shaders • If geometry is correct, not as important to interact with shading and lighting values Basic Algorithm 3 passes over 2D Grid: I. II. III. Deep Wave Simulation Shallow Wave Simulation Curling of Wave – – – Classify portions of waveform Modify shape based on this classification Curling breaks ‘height field’ Part I of III: Deep Ocean Simulation Deep Ocean Simulation • Based on Sum of Sines approach of [Finch04], [Isodoro02]: sin( x) 1 f ( x) amplitude 2 steepness • Summation of N waves to simulate Ocean Surface (N==4 for us) – 4 good candidate for SSE optimization!! • x dependent upon wind direction, velocity, wavelength of wave . Normal Generation… 2 techniques: 1. Derivates as presented in [Finch04] • • 2. Good for GPU implementations Possible to make faster with trig lookup tables Compute face normals, then average • • Faster than Option 1 on CPU implementations Must use neighbor list to get performance – Brute force method was painfully slow! Wave Speed and Wavelength Relationship for Deep Ocean Waves speed g wavelength 1.25 wavelength 2 Eqn. from [Garrison02] Wavelength to Velocity Relationship for Deep Waves Figure from [Garrison02] Deep Ocean Wave Demo… Nature vs. Your Next Big Hit • Even these functions are ‘on average’, many parameters can effect wavelength, velocity, direction, etc. • While in nature there are observed relationships…the model gives user control over surface parameters • Ignoring these relationships is fine to tune your deep ocean for your environment Threading [Lake05] – Task Level Decomposition • Thread A: Simulated Game Workload • Thread B: Compute Wave Performance with threading DP vs UP Performance 700 90.00% 80.00% 600 70.00% 500 50.00% 300 40.00% FPS 400 30.00% 200 20.00% 100 10.00% 0 0.00% No WorkloadWorkloadWorkload No WorkloadWorkloadWorkload No WorkloadWorkloadWorkload workload 1 2 3 workload 1 2 3 workload 1 2 3 40x40 Mesh 80x80 Mesh UP FPS DP FPS 140x140 Mesh Speedup Speedup 60.00% Part II of III: Shallow Wave Simulation Breaking Waves Image from [Seafriends]. Shallow Wave Observations • Same variables as deep wave – Wavelength, steepness, velocity, … • Wavelength – Decreases as we approach shore – Specifically, at a depth of ½ wavelength • Steepness – Increases as we approach shore • Fix velocity to maintain phase – Recall wavelength and speed are dependent – If you don’t do this waves will be incorrect • Adjust height – Attempt to preserve water column as it collapses Shallow Wave Algorithm • • • Input: position, wavelength, steepness, position, distance to shore, sealevel, and distance to ocean floor as input: Output: New vertex position in shallow wave simulation For each point, 1. 2. Determine Deep Ocean wave position from Section I. Based on this position: 1. 2. 3. 4. 3. Adjust wavelength 1. Wavelength varies linearly from lamba to ½ lambda in our example 1. In our example steepness varies from x to y in our demo 1. For velocity solve 1. Collapse of water column is what causes break Adjust Steepness Fix Velocity to Maintain phase Adjust Height as it attempts to maintain water column Calculate new position using modified values as input to deep ocean simulation equation! Shallow wave speed and wavelength relationship speed gravity depth 3.1 depth Eqn. from [Garrison02] Shallow Waves demo! Image from [Seafriends04] Part III of III: Breaking Waves! Breaking Waves Image from [Seafriends]. Types of Breaking Waves Image from [Mead03] Side view of breaking wave Image from [Miller76] Side view of breaking wave after collapse Image from [Miller76] Breaking Waves • When waves reach a point that the wavelength is a factor of ~1/7 of waveheight, the wave breaks [Seafriends]. – Dependent on slope, composition, wind velocity, etc. • In our implementation, user can vary parameters The Vortex Image from [Mead03]. Vortex Ratio • Ratio of length to width in practice is often between 1.73 and 4.43 [Mead03]. Cubic form of vortex • Cubic form of Vortex is expressed as [Longuet-Higgins82]: Note: Not actually needed for implementation! Classification of surfing wave breaking Intensity Breaking Algorithm • Input is positions from shallow wave simulation • Pass 3 of the algorithm: – Pass 1: deep wave – Pass 2: shallow wave – Pass 3: curling Breaking Algorithm Overview • For every timestep t: – Move vortex forward as wave moves forward – For each vertex: • Classify based on type • Project point towards vortex based on type, height, and distance to ‘shoreline’ Wave Breaking Algorithm • Classify vertex state: – [TOP, BACK, FRONT, FLAT] – Floating point gotchas, especially FLAT! 2D Slice of Shallow Wave Vertex Positions 0.14 TOP 0.12 Height 0.1 FRONT 0.08 0.06 BACK 0.04 BOTTOM 0.02 0 1 4 7 10 13 16 19 22 25 28 31 34 37 40 43 46 49 52 55 58 61 64 67 70 73 76 79 Vertex Number So, how do we approximate this shape? Image from [Mead03]. Vortex Approximation • Using 2D Circle as attractor: – Pulls vertices based on: • Distance from shore • Height from sealevel • Desired vortex shape – Sphere moves towards sealevel as we move into shore – Sphere decreases in size as we move toward shore Image of Vortex Sizes, etc. Wave Breaking Algorithm • Switch(vertex_state): – TOP or FRONT: 1. Obtain 2D Circle Position: • 2. – Midpoint between FRONT of back wave and BACK of front wave To simulate Vortex, project towards circle based on vertex height BACK: • – Interpolate to remove gap FLAT: • Nothing Results [1/3] 100% of Calculated Radius 0.14 0.12 0.1 0.08 Series2 0.06 0.04 0.02 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 Only showing FRONT and TOP 0.8 Results [2/3] 75% of Calculated Radius 0.14 0.12 0.1 0.08 Series2 0.06 0.04 0.02 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 Results [3/3] 25% of Calculated Radius 0.12 0.1 0.08 0.06 Series2 0.04 0.02 0 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 Breaking Wave Demo! Areas of Future Work • Work in Progress • Lighting and shading – Foam • Interaction with outside environment – Modify ocean floor • Ready but not complete • Model is not restricted to waves coming in straight on…demonstrate this • Stage IV: In the surf… Acknowledgements • Kim Pallister and Pete Baker for giving the resources and time to work on this project. • Jacob Anderson (jwa@beyondordinary.com) at Beyond Ordinary Software Solutions for useful pointers and early discussion. • Discussions with Dean Macri on vortex simulation. • Useful discussions with: Stephen Junkins, Allen Hux, Kim Pallister, William Hachfeld@SGI. • Allison Knowles for title, poster, and acknowledgement photographs. References [1 of 2] • • • • • • • • • • [Black98] Black, K. P., J. A. Hutt & S. T. Mead, 1998. Narrowneck Reef Report 2: Surfing Aspects. Technical Report prepared for the Gold Coast City Council, June,1998. [Cohen98] Aaron Cohen and Mike Woodring. Win32 Multithreaded Programming. O’Reilly and Associates. 1998. [Gomez00] Miguel Gomez. Interactive Simulation of Water Surfaces. Game Programming Gems 1. Edited by Mark Deloura. Pages 187-194. [Finch04] Mark Finch. Effective Water Simulation from Physical Models. GPU Gems: Programming Techniques, Tips, and Tricks for Real-Time Graphics. Edited by Randima Fernando. Pages 5-29. 2004. [Garrison02] Tom Garrison. Oceanography: An Invitation to Marine Science. Wadsworth/Thomson Learning. 2002. http://www.seafriends.org.nz/oceano/waves.htm [Giancoli85] Douglas Giancoli. Physics, Principles with Application, 2nd edition. Prentice Hall, Inc. 1985. [Isidoro02] John Isidoro, Alex Vlachos, and Chris Brennan. Rendering Ocean Water. Direct3D ShaderX: Vertex and Pixel Shader Tips and Tricks. Pages 347-356. 2002. [IMDB04] Credits for Titanic. http://us.imdb.com/title/tt0120338/. [Lake05] Adam Lake and David Reagin. Real-Time Deep Ocean Wave Simulation On MultiThreaded Architectures. Intel developer services: www.intel.com/ids . [Longuet-Higgins76] M.S. Longuet-Higgins,E.D. Cokelet. The Deformation of Steep Surface Waves on Water. I. A Numerical Method of Computation. Proceedings of the Royal Society of London. Series A, Mathematical and Physical Sciences, Vol. 350, No. 1660 (Jul 30, 1976), 1-26. References [2 of 2]: • • • • • • • • • • [Longuet-Higgins80] M.S. Longuet-Higgins, A Technique for Time-Dependent Free-Surface Flows. Proceedings of the Royal Society of London. Series A, Mathematical and Physical Sciences, Vol. 371, No. 1747, Aug. 4, 1980. Pages 441-451. [Longuet-Higgins82] M.S. Longuet-Higgins. Parametric Solutions for Breaking Waves. J. Fluid Mechanics, 1982, vol. 121, pp. 403-424. [Mead03] Shaw Mead. Keynote Address: Surfing Science. Proceedings of the 3red International Surfing Reef Symposium, Raglan, New Zealand. June 22-25, 2003. P. 1-36. [Mihalef04] Viorel Mihalef, Dimitris Metaxas, Mark Sussman. Animation and Control of Breaking Waves. Eurographics/ACM SIGGRAPH Symposium on Computer Animation, 2004. [Miller76] Miller R.L. Role of Vortices in Surf Zone prediction: sedimentation, and wave forces. Beach and Nearshore sedimentation, pp. 92-114, 1976, Tulsa, Oklahoma. Soc. Of Economic Paleontologists and Mineralogists. [Miller76] Miller R.L.. [Mead] Shaw Mead and Kerry Black. Predicting the Breaking Intensity of Surfing Waves. Special Issue of the Journal of Coastal Research on Surfing (in press). Pages 103-130. www.asrltd.co.nz/Paper4Web.pdf . [Schneider01] Jens Schneider and Rudiger Westermann. Towards Real-Time Visual Simulation of Water Surfaces. VMV 2001, Stuttgart, Germany, Nov. 21-23, 2001. [Tessendorf01] Simulating Ocean Water. SIGGRAPH2001 Course Notes. 2001. [QuickMath04] http://www.quickmath.com/. November 4, 2004. Backup • Irribarren Number[cite]: – B is slope – Hb/Linf = ratio of wave height to wavelength Wave Energy as a function of Period • When each vertex of wave reaches breaking point: – Classify vertex as FRONT, BACK, BOTTOM, TOP of waveform • FRONT, BOTTOM and TOP are projected towards virtual sphere to create vortex – • As wave approaches shore: » Sphere decreases in size as wave approaches shore. » Vertices increase their attraction to sphere BACK are projected to create natural arc on back of wave I. Dee p Wav e Sim ulat II. Shal low Wav e Sim ulati I B a S u Breaking • Takes as input the shallow wave that reaches the breaking point: – Curl front of waveform to simulate crash – Back follows Velocity and wavelength are related Image from [Seafriends]