1 / 65

CIS 350 – I Game Programming Instructor: Rolf Lakaemper

CIS 350 – I Game Programming Instructor: Rolf Lakaemper. FRACTAL LANDSCAPES. What ?. In this lecture we will learn how to generate Fractal Heightfield Terrains. What ?. What are we talking about ?. What ?. Heightfield Terrain: A 2D grid system of height values,

efrat
Download Presentation

CIS 350 – I Game Programming Instructor: Rolf Lakaemper

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CIS 350 – I Game Programming Instructor: Rolf Lakaemper

  2. FRACTAL LANDSCAPES

  3. What ? In this lecture we will learn how to generate Fractal Heightfield Terrains

  4. What ? What are we talking about ?

  5. What ? Heightfield Terrain: A 2D grid system of height values, defining a 3d landscape

  6. What ? Fractal: extremely irregular curves or shapes for which any suitably chosen part is similar in shape to a given larger or smaller part when magnified or reduced to the same size Main characteristic: Self Similarity

  7. What ? Self Similarity

  8. What ? Self Identity: Von Koch Snowflake

  9. Fractals Von Koch Snowflake Iterating the snowflake algorithm to infinity, the boundary of the 1d snowflake becomes part of the 2d AREA of the plane it is constructed in (take it intuitively !)

  10. Fractals Von Koch Snowflake It therefore makes sense to define its dimensionality BETWEEN one and two !

  11. Fractals The idea of defining the dimensionality is straightforward: Example: 1 dimensional object, a line A line is self similar: it can be divided into N parts, each of which is scaled down by the ratio r = 1/N from the whole. Example: 2 dimensional object, a rectangle Also self similar, can be divided into N similar parts of scale r = 1/sqrt(N)

  12. Fractals We can also state: N = 1 / (r^D) = (1/r)^D Hence D results from given r,N as: D = log(N) / log(1/r)

  13. Fractals D = log(N) / log(1/r) Is the fractal dimensionality of a self similar object. What’s the dimensionality of the Koch Snowflake ?

  14. Fractals N = 4 Scale r = 1/3 D = log(4) / log(3) D = 1.2619 Intuitive ?

  15. Fractals The interesting news: There’s a lot of math behind fractals !

  16. Fractals The good news: To use them, an understanding of math is not necessary. They are algorithmically SIMPLE.

  17. Fractals Since we only want to use fractals, let’s go straight to algorithms Algorithms for Random Fractals

  18. Fractals Random fractals: In contrast to exact self similar fractals (e.g. the Koch snowflake), also termed as deterministic fractals, an additional element of randomness is added to simulate natural phenomena. An exact computation of fractals is impossible, since their level of detail is infinite ! Hence we approximate.

  19. Random Fractals First Case Study: Brownian Motion As the botanist R. Brown 1827 discovered, small particles of solid matter suspended in a liquid can be seen under a microscope to move in an irregular and erratic way. The modeling of this movement is one of the great topics of statistical mechanics.

  20. Random Fractals The motion of these particles has certain properties, which match the properties of shapes in nature.

  21. Fractals There are two main classes of algorithms simulating random fractals, e.g. brownian motion: • Recursive approximation: input fractal is recursively improved in resolution, example: midpoint displacement • Only one approximation, namely the final resolution, is computed. Example: Fourier filtering

  22. Fractals We will use MIDPOINT DISPLACEMENT

  23. Fractals A 1D example to draw a mountain : Start with a single horizontal line segment. Repeat for a sufficiently large number of times { Repeat over each line segment in the scene { Find the midpoint of the line segment. Displace the midpoint in Y by a random amount. Reduce the range for random numbers. } }

  24. Fractals Result:

  25. Fractals Result:

  26. Fractals Note: To apply the mathematics of fractals to the algorithm and to determine the correct fractal dimension, the random number generator must have a certain property, i.e. it must deliver random numbers with Gaussian distribution. This does not seem to be crucial for the application of creating landscapes. We can use the C++ / JAVA random numbers.

  27. Fractals Extension to 2 dimensions: The Diamond – Square Algorithm (by Fournier, Fussel, Carpenter)

  28. Fractals Data Structure: Square Grid • Store data (efficiently) in 2D Array. • Modification is very trivial. • Not possible to define all terrain features. • Good for Collision detection

  29. Fractals Data Structure: Square Grid

  30. Diamond Square The basic idea: Start with an empty 2D array of points. To make it easy, it should be square, and the dimension should be a power of two, plus one (e.g. 33x33). Set the four corner points to the same height value. You've got a square.

  31. Diamond Square This is the starting-point for the iterative subdivision routine, which is in two steps: The diamond step: Take the square of four points, generate a random value at the square midpoint, where the two diagonals meet. The midpoint value is calculated by averaging the four corner values, plus a random amount. This gives you diamonds when you have multiple squares arranged in a grid.

  32. Diamond Square Step 2: The square step: Taking each diamond of four points, generate a random value at the center of the diamond. Calculate the midpoint value by averaging the corner values, plus a random amount generated in the same range as used for the diamond step. This gives you squares again.

  33. Diamond Square This is done repeatedly, but the next pass is different from the previous one in two ways. First, there are now four squares instead of one. Second, and this is main point: the range for generating random numbers has been reduced by a scaling factor r, e.g. r = 1/4 (remember the fractal dimension ?)

  34. Diamond Square Again:

  35. Diamond Square Some steps: taken from http://www.gameprogrammer.com/fractal.html#midpoint

  36. Diamond Square The scaling factor r, determining the range of random displacement R, defines the roughness ( => fractal dimension !) of the landscape. Some examples for diff. r and R R(n+1) = R(n) * 1 / (2^H), 0 < H < 1

  37. Diamond Square H=0, 1/(2^H) = 1

  38. Diamond Square H=0.2, 1/(2^H) = 0.87

  39. Diamond Square H=0.4, 1/(2^H) = 0.76

  40. Diamond Square H=0.6, 1/(2^H) = 0.65

  41. Diamond Square H=0.8, 1/(2^H) = 0.57

  42. Diamond Square H=1, 1/(2^H) = 0.5

  43. Diamond Square Let’s have a look at a MATLAB implementation…

  44. Open GL But how to DISPLAY a heightfield ?

  45. Open GL For now we just need a tool that can visualize 3D data in connection with C++ / JAVA. The math behind 3D scenes will not be part of today’s class. We will also not render or give a deep introduction into the display tool, but will only describe and use …

  46. Open GL OPEN GL

  47. Open GL What is OpenGL ? • OpenGL provides the programmer with an interface to graphics hardware • Powerful rendering and modeling library • Available on all major platforms • OPEN SOURCE (FREE) • Designed for use in all graphic applications, from CAD to games • EASY to use • E.g. used in the core engine of Quake3

  48. Open GL OpenGL • Developed by Silicon Graphics (SGI) • Adopted by Microsoft (of course there’s now a microsoft and SGI version for PCs…) • Provides graphic functionality only, NO window handling (this is done by an additionol module, GLUT) • Collection of several hundred functions providing access to all features offered by the graphic hardware

  49. Open GL Internally OpenGL works as a state machine (A collection of states tells OpenGL what to do). The OpenGL API offers the interface to set various aspects of the state machine, e.g. line color, thickness, texture etc. An example for state parameters of the API: GL_DOUBLEBUFFER, GL_FOG, GL_FOG_COLOR, GL_POINTSIZE, GL_CURRENT_COLOR, etc. …

  50. Open GL OpenGL primitives • The basic geometric entities • OpenGL offers points, lines, line_strip, line_loop, triangles, triangle_strip, triangle_fan, quads, quad_strip, polygon • (notation: GL_POINTS, GL_LINES, …) • These are the tools you are finally drawing with !

More Related