Download presentation
Presentation is loading. Please wait.
Published byEmma Inga Ekström Modified over 6 years ago
1
Fixed Point Iteration Huw Bowles Technical Lead Studio Gobo
a.k.a. SCIENCE!!! INTRO So… what the heck is fixed point iteration? Rather than give you some dry introduction I’m going to dive straight in and give you..
2
Pop Quiz A quiz! Lets say we have two curves, one is the line y=x and the other is a sin function (ignore the magic numbers, its just for framing), and we are interested to find the intersection between the two lines.
3
Pop Quiz Set equations equal 𝑥=0.6sin (1.7𝑥+1)
Some of you will remember the first step which is to set the equations for the two graphs equal.
4
Pop Quiz Set equations equal Solve for 𝒙 𝒙=0.6sin (1.7𝒙+1)
And then solve for x. Note the bold red font – I will use this convention throughout the talk to indicate the unknown that we are solving for. So far so simple, but theres bad news
5
Pop Quiz Set equations equal Solve for 𝒙 No algebraic solution!
𝒙=0.6sin (1.7𝒙+1) Solve for 𝒙 No algebraic solution! We can’t solve this using algebra because sin is a transcendental function, you can’t just solve for x. This is specific example but is actually pretty representative of applying math in the real world, many or most problems are not amenable to analytic solves. We’ll see some more deceptively simple examples soon. We need to approach this from a different angle.
6
Numerical Methods Newton’s method to the rescue
Numerical methods were invented to solve problems like this. Newtons method is the famous option, which finds when a function is 0. Here we plot the DIFFERENCE between the two curves. We want to find the x intercept here where the difference between the two curves is 0. So lets say we start iterating at the first arrow. Walk down gradient, here we overshoot slightly. After a second step we are close to the solution. This worked well and converged fast to the solution.
7
Numerical Methods Newton’s method to the rescue
However lets say we start iterating over here instead, then we get a flat or almost flat tangent that sends us into outer space where we have no hope of recovering. This will happen any time the gradient is 0, and if it changes sign it will take off in the other direction – bad news if there are any bumps or inflexions etc on that curve. So Newton will converge fast when it works but explodes spectacularly when it doesn’t, which makes it practically useless except in tightly controlled circumstances. The good news is there is an alternative method that is simple and very well suited to games and real-time, and I’m here today to add this new formidable weapon to your arsenal.
8
Fixed Point Iteration (FPI)
Given equation of form: 𝒙=𝐹(𝒙) And initial guess 𝒙 𝟎 Compute iterates 𝒙 𝟏 , 𝒙 𝟐 , 𝒙 𝟑 … 𝒙 𝒊+𝟏 =𝐹( 𝒙 𝒊 ) Allow me to introduce Fixed Point Iteration, or FPI for short. Its definition is very simple. Given any equation of the form x = F(x) – so x on one side and *any* function of x on the other. And an initial guess for the solution x0 We can generate a set of iterates xi – a set of increasingly better approximations to the solution, by plugging each value into F.
9
Fixed Point Iteration (FPI)
Equation 𝒙=0.6sin (1.7𝒙+1) Let 𝐹 𝒙 =0.6 sin (1.7𝒙+1) Initial guess 𝒙 𝟎 =0.05 Iterate: 𝑥 1 =𝐹 𝑥 0 =𝐹 0.05 ≅0.531 𝑥 2 =𝐹 𝑥 1 =𝐹 ≅0.567 … 𝑥 5 =𝐹 𝑥 4 =𝐹 ≅0.558 So our quiz equation looks like this, and we can let our F(x) be the right hand side. Take x0 = 0.05 just because (magic) Evaluate x1 by plugging x0 into F. Compute x2 from x1.. Stop iterating when we detect convergence. Often times I just set the iteration count to fixed – this works surprisingly well, the iteration is not dependent on the derivate and usually very stable.
10
Fixed Point Iteration (FPI)
0.531 0.558 0.05 Lets see a visual representation, here the green curve traces the trajectory of the iteration. Notes: This is called a cobweb plot: en.wikipedia.org/wiki/Cobweb_plot
11
Talk Outline Real world applications of FPI Convergence requirements
Power-ups Ok so FPI seems to be useful in theory, what can we use it for in practice? We’re going to look at 3 real world applications, each demonstrating a different aspect of FPI. I haven’t mentioned the convergence properties – you might put that in the back of your minds for now, we’ll get to this later. Finally we’ll touch briefly on some advanced things we can do to beef up this method for further reading. Some of this is novel research which I’m excited to present for this first time today.
12
Case 1: Gerstner waves Deep water ocean wave shape [6]
Used in Uncharted 3, Disney Infinity: Pirates of the Caribbean [1,2] Are a particular shape - the shape of deep water gravity waves in the ocean. Can sum these together to give a procedural ocean shape. Used this in the Wii version of the potc playset.
13
Case 1: Gerstner waves Problem: Given 𝑥, compute 𝑦 Parametric curve 𝑦
𝑥=𝑡−𝐵 sin 𝑡 𝑦=𝐴 cos 𝑡 𝑦 𝑥 𝑥 So what is the problem? Lets say we want to do height queries to do buoyancy calculations. This curve is defined parametrically – y and x are given as a function of the curve parameter t.
14
Case 1: Gerstner waves Problem: Given 𝑥, compute 𝑦 Parametric curve
𝑥=𝑡−𝐵 sin 𝑡 𝑦=𝐴 cos 𝑡 y is a function of 𝑡 Y is given in our second equation and is a function of t
15
Case 1: Gerstner waves Problem: Given 𝑥, compute 𝑦 Parametric curve
𝑥=𝒕−𝐵 sin 𝒕 𝑦=𝐴 cos 𝒕 y is a function of 𝒕 Need 𝒕 from first equation Same equation form as pop quiz! T is our unknown. Since we know x, we can use the first equation to compute t.
16
Case 1: Gerstner waves Rearrange to get 𝐹 𝑡 =𝑡 form
𝑥=𝒕−𝐵 sin 𝒕 𝒕=𝑥+𝐵 sin 𝒕 Let 𝐹(𝒕) =𝑥+𝐵 sin 𝒕 Initial guess: 𝒕 𝟎 =𝑥 Iterate: 𝒕 𝟏 =𝐹( 𝒕 𝟎 ), … Compute y using 𝒕 𝒏 We know we can’t solve for t directly. Lets instead rearrange the equation to match FPI form. Take an initial guess. It happens that the x and t values oscillate around eachother but stay close, so x is a good guess for t. Iterate as before. Terminate iteration when we’re happy with the converged value tn.
17
Case 1: Gerstner waves Diagram: shadertoy.com/view/MstSRN
Lets see this in action. This plot shows points on the parametric equation for a regular set of t values. This is running live in shadertoy, you can go there to mess around with this. Diagram: shadertoy.com/view/MstSRN
18
Case 1: Gerstner waves 𝑡 0 =𝑥 Diagram: shadertoy.com/view/MstSRN
The blue curve is a y(x) graph of the trochoid which uses FPI. To start with the iteration count is 0. No iterations means no horizontal displacement – y is just a cosine function of t. Diagram: shadertoy.com/view/MstSRN
19
Case 1: Gerstner waves 𝑡 1 =𝐹( 𝑡 0 )
Diagram: shadertoy.com/view/MstSRN
20
Case 1: Gerstner waves 𝑡 2 =𝐹 𝑡 1 Diagram: shadertoy.com/view/MstSRN
21
Case 1: Gerstner waves 𝑡 3 =𝐹 𝑡 2 Diagram: shadertoy.com/view/MstSRN
22
Case 1: Gerstner waves 𝑡 4 =𝐹 𝑡 3 Diagram: shadertoy.com/view/MstSRN
𝑡 4 =𝐹 𝑡 3 By 4 iterations we have something that isn’t visibly improving. Diagram: shadertoy.com/view/MstSRN
23
Case 1 Summary FPI can solve hard problems Extremely general
𝒕=𝐹 𝒕 More octaves? Sure! Stable – no gradient We used this method in the Wii version of the pirates playset of Disney Infinity (DI) 1.0. Naughty dog used a search which I believe can be boiled down to something like this, but the details are unclear to me so I’m not sure.
24
Case 2: Vector Displacement Maps
Simulate the ocean offline instead [1,4] It doesn’t need to be a mathematical function, it works well for data driven problems as well. Simulate an ocean offline which displaces a tessellated plane into an ocean patch as shown on the left. We can then bake out these vector displacements, and use this in a game. This was the method used in assassins creed ocean, and the one we used for the non-wii version of our pirates playset of DI1. [Source: Blender]
25
Case 2: Vector Displacement Maps
Simulate the ocean offline instead We’ll focus on a 1D example by taking a thin slice through the texture. Note that FPI generalises easily to more dimensions, I’ll provide further reading for this later. [Source: Blender]
26
Case 2: Vector Displacement Maps
So here is a side view of the ocean surface.
27
Case 2: Vector Displacement Maps
And here are the displacement vectors that define this surface.
28
Case 2: Vector Displacement Maps
Goal: compute height at 𝑥 x And our goal is to compute the height at x. Note the horizontal displacements – its not a heightfield so we can’t just sample at x.
29
Case 2: Vector Displacement Maps
Goal: compute height at 𝑥 Height given at 𝒖 x u The height is given by the vector sampled at the fractional position u. This is the vector we need to get the height at x.
30
Case 2: Vector Displacement Maps
Need to find 𝒖 which will be displaced to 𝑥 Equation: 𝒖+𝐷 𝒖 =𝑥 x D u So we need to find u that is displaced to x, and we need to write this down as an equation. Lets call the horizontal displacement D. Then we get this simple equation – we want a u such that u + disp at u gives us the surface point at x. This equation could be derived differently but it doesn’t matter – we just need u and x in the same equation. D is data driven, so there’s no way we could solve for this with a formula. We need to do some kind of search.
31
Case 2: Vector Displacement Maps
FPI to the rescue! Equation: 𝒖+𝐷 𝒖 =𝑥 Rearrange: 𝒖=𝑥−𝐷 𝒖 Let F(𝒖)=𝑥−𝐷 𝒖 Guess 𝒖 𝟎 =𝑥 Iterate: 𝒖 𝟏 =𝑥−𝐷 𝒖 𝟎 , … And FPI is a great search method. We just take our equation and rearrange it to get u = F(u) form. It doesn’t matter that D is data driven, FPI just doesn’t mind. Taking x as the first guess makes sense here, if we assume that our horizontal displacements are not too crazy.
32
Case 2: Vector Displacement Maps
Simulate the ocean offline instead The iteration may look something like this. Assume we want to sample the water height at the circle. The first iteration looks at the local displacement and uses that for the first guess. The second iteration does the same and performs a correction on the first step… [Source: Blender]
33
Case 2 Lessons FPI great for searching data
Simple to implement Under-iterated result stable Generalises to higher dimensions That’s how you can sample height from displacement map. We used this on the non-Wii verison of the Pirates playset.
34
Case 3: Distance field terrain
Render terrain represented by Distance Estimator (DE)
35
Lets say this is the outline of our terrain.
This diagram running live:
36
DE The distance estimator (DE) gives the approximate distance to the surface at any point in space. This diagram running live:
37
Case 3: Distance field terrain
Pixel ray 𝒑=𝒐+𝑡𝒅 Want intersection of ray with surface 𝐷𝐸 𝒙 =0 Plug in ray: 𝐷𝐸 𝒐+𝑡𝒅 =0 Solve for 𝑡! But this is not our usual form 𝑡=𝐹(𝑡) Lets approach this problem using FPI. We need to write down an equation which we will solve. Start with the ray equation for a ray going through a particular pixel, represented by origin o and direction d. Next we have the equation for the surface – all points x that are 0 distance from the surface. We obtain our equation by substituting the ray equation in to the DE. We can use this to solve for t. However this is not our usual form t=F(t)
38
Case 3: Distance field terrain
Easy fix: add 𝑡 to both sides 0=𝐷𝐸 𝒐+𝑡𝒅 𝑡=𝑡+𝐷𝐸 𝒐+𝑡𝒅 Let 𝐹(𝑡)=𝑡+𝐷𝐸(𝒐+𝑡𝒅) Start at camera: guess 𝑡 0 =0 Iterate: 𝑡 𝑖+1 = 𝑡 𝑖 +𝐷𝐸 𝒐+ 𝑡 𝑖 𝒅 Standard raymarch algorithm! We can get it in this form easily by adding t to both sides. We can safely add to both sides without changing the solution. Now we have the usual form and can solve. Some may recognize this formula – this is at the heart of of the raymarch loop of all implicit surface raymarcher. Misc note: Normal raymarching terminates when DE < epsilon. This may terminate with the ray INSIDE the surface (DE<0). In my shaders I usually terminate when |DE|<epsilon, which guarantees the ray ends on the surface. The difference is often not noticeable in practice, but was very noticeable for the milk shader I show later.
39
DE Lets show how the iteration converges in this case.
Start with a ray origin and direction shown by this arrow.
40
DE The iteration consults the DE and obtains an estimate for the distance to the surface
41
DE It uses this distance to progress the ray forwards (t = t + DE(…)).
42
DE Continues similarly..
43
DE
44
DE
45
DE
46
DE As ray moves out into open space it takes larger steps – a nice natural compression of the computation.
47
DE
48
DE
49
DE
50
DE
51
DE
52
DE
53
DE
54
Case 3 Lessons Raymarching is equivalent to FPI Why?
FPI is fundamental Any iterative update can be posed as FPI Equation form is t=F(t). F(t) can be literally anything – any kind of heuristic or iterative update. Even newtons method, although I haven’t found it useful to analyse it in this way.
55
Convergence Requirements
Standard form: 𝑥=𝐹(𝑥) Converges when 𝐹 ′ 𝑥 <1 around solution Study raymarch case: 𝑡=𝑡+𝐷𝐸 𝑡 Converges when 1+ 𝐷𝐸 ′ 𝑡 <1 Therefore −2< 𝐷𝐸 ′ 𝑡 <0 The general requirement is the slope of F is less than 1 in size. This sounds limiting. It can be, but I have found it often does converge within a few iterations. We’ll look at ways to improve this later. First, to understand this requirement better, we’ll study the raymarch. Its useful to study the raymarch case for some illustration reasons, and also because some methods have been invented to improve FPI convergence in the context of raymarching. The raymarch form is also interesting because the step in each iteration is explicit. It is given by the term DE() here. Later we will look at modifying the step (scaling it down to help convergence). In general, if we are solving an equation of the form x=F(x), we can get it in this ‘step’ for easily: x=F(x) x=F(x)+x-x x=x + (F(x)-x) The step is then (F(x)-x)
56
Convergence properties
DE(t) t In this diagram, top half is a render of a simple procedural terrain. Every pixel generated by casting a ray using the raymarching algorithm we saw before. The brighter the pixel, the more steps it needed. We’re going to look in detail at the ray marked by the green cross. -2 < DE’(t) < 0
57
Convergence properties
DE(t) t In the graph below I plot the distance estimator values along this ray. And similar to before, the yellow circles show the raymarch steps. You can see that this ray converged to the surface within around 7 steps. The DE is shaded green where the convergence condition is met and red otherwise. Its green at the first intersection and therefore the ray converges. However, if we rotate the camera to the right.. -2 < DE’(t) < 0
58
Convergence properties
DE(t) t DE’(t) < -2 this ray to a bright spot on the terrain, we can see at the bottom that the iteration does not converge because the slope is too steep.
59
Convergence properties
DE(t) t Lets look in detail at the behaviour of the iteration around this intersection.. The step/DE changes from positive to negative – the iteration jumps forwards and backwards around the solution. This is a problem for the iteration. There are a couple of options to enable convergence here. Firstly, we could simply scale down the distance estimates.
60
Convergence properties
0.7DE(t) t This doesn’t change the location of the intersections, but reduces the slope of the DE and allows convergence. So you can see the graph is now green at the intersection point because the slope is within the required range. This is actually a well known trick in raymarching. The trade off is that more iteration steps are required.
61
Convergence properties
DE(t) t I found an alternative solution which detects when the iteraton hops over the intersection by monitoring the sign of the distance estimate. If this happens then we employ a step from what is known as the Secant Method. This connects these two points with a line and uses this line to estimate the position of the intersection.
62
Convergence properties
DE(t) t So the iteration steps to here in this case instead of overshooting like before.
63
Convergence properties
DE(t) t The effect is dramatic, the step counts are hugely reduced. You can see at the bottom that iteration does not overshoot but instead quickly converges down to the solution, even in the presence of large gradients. This idea comes from the Secant Method and slots elegantly into existing raymarching loops.
64
Milky: shadertoy.com/view/Msy3D1
For a while I thought this was a mere academic curiosity but I was able to put it to good use here on this shader which had steep gradients in the heightfield and required very small steps to remove noticeable errors, whereas the secant step fixed it. Milky: shadertoy.com/view/Msy3D1
65
Power-ups If flip flops around solution
Secant step Jumps over/misses solution? Scale down step… Very common with distance estimators Slow to reach solution? Scale up steps… Over-relaxation for raymarching [5] What other things can we do to improve the iteration? We looked at the secant step in the last slides. The iteration may miss solutions especially if there are large gradients in the DE. This is visible as “holes” in the bumps in the render on the previous slides. Here the step is just too large and currently the best fix is to just scale down all steps. Interestingly, if the iteration takes a long time to converge (DE gradient close to 0), it can help to scale UP the steps. There is a very nice geometry argument for when this is ok in [5].
66
The Pattern Write down equation with unknown
Analytical solve? You’re done. Get in form 𝒙=𝐹 𝒙 Iterate 𝒙 𝒊+𝟏 =𝐹 𝒙 𝒊 to taste
67
Summary FPI arises naturally Simple and easy to try
Coherent, stable, good for searching data Unlike Newton! If diverges Try to reduce step size Try Secant Step
68
Summary - Higher Dimensions
FPI not limited to 1D See [3] for application of FPI to image warping Simple to implement, fast Convergence condition for >1D given Behaviour illustrated in the presence of many solutions Technique described to catch all solutions
69
References [1] Bowles, H. and Zimmermann, D. Oceans on a Shoestring: Shape Representation, Meshing and Shading, Advances in Real-Time Rendering in Games course, SIGGRAPH 2013 [2] Gonzales-Ochoa, C. Water Technology of Uncharted, GDC 2012 [3] Bowles, H., Mitchell, K., Sumner, B., Moore, J. and Gross, M.. Iterative Image Warping, Eurographics 2012 [4] Torres, G. and Ricour, H. Technical Challenges of Assassin’s Creed III: Real-Time Water Simulation and High-Quality Linear Gameplay Sequences, SIGGRAPH Asia 2012 [5] Keinert, B., Schaefer, H., Korndoerfer, J., Ganse, U. and Stamminger, M., Enhanced Sphere Tracing, STAG 2014 [6] Tessendorf, J. Simulating Ocean Water, SIGGRAPH 2001
70
Thank you for listening!
And thanks to.. Halldor Fannar, Daniel Zimmermann, Studio Gobo Misc notes: huwbowles.com/fpi-gdc-2016/ Contact LinkedIn: linkedin.com/in/huwbowles I found this talk really challenging to pull together and couldn’t have done it alone. I have to thank Halldor and Daniel for absolutely nailing feedback, and also to my friends and colleagues at studio gobo for their feedback and amazing support. I have a page for this talk which I may add notes or additional links on. My contact deets are there, please me or add me on linked in. And please fill out the evaluation forms, its really important to know how this talk was received.
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.