Home Page
Projects > Fractal Landscape
Projects > Fractal Landscape

Warning: you do not have javascript enabled. This WILL cause layout glitches.
Fractal Landscape Thumbnail
Fractal Landscape v1.05
A “high-detail” limited-size fractal landscape generator and rendering engine
Rating: 9 (This gets a 9 instead of a 10 because i didn’t completely achieve the original goals :-( (being infinite size).)
Project Time: 7/2/2003-10/31/2003: 100+
Languages: C++, Direct3D, GPU ASM, OpenGL
Requirements: DirectX, OpenGL
Downloads: Binary Source (See any updates below for prior versions)
Sections: Information, Content, Concepts, Updates, Comments
Renders real-time dynamically created (diamond-square algorithm) fractal landscapes with 5 detail levels (1=barely any, 5=incredible detail).
Original Readme (Slightly modified):

This is a completely dynamic 3D fractal landscape make from scratch in C++ with the DirectX and OpenGL SDKs. The first fully working version (see the first update for more information) was originally made in 2 or 3 days as a portfolio entry.

The user can walk around via the “W/A/S/D” keys, and rotate the camera (to a degree, for better interaction) almost fully around, via the mouse. The colors of the areas depend upon the height that they are at, ranging from water to mountain peaks with snow. The landscape is dynamically lighted from the sun. The lowest height levels (under water) also fog the rest of the map, produce bubbles, and include an alpha blended layer over it to form a water front.

The landscape can go from 3 to 5 levels of depth (for performance sake). It is suggested you use the highest depth level your computer can handle.

The world uses custom fractal calculating routines and dynamic quad-tree based polygon removal (See Technical Details for more information). The sky also includes clouds that use a remapped version of the same fractal map that generated the landscape.

Just as a note, this was programmed specifically as a portfolio example and was not meant for speed. It runs around 40 FPS on a GeForce4. I invented a way to use a hybrid ray tracing/rasterisation with mixed graphics card and a custom CPU implementation to make it theoretically run 60+ FPS on any modern graphics card that I did try to implement, but unfortunately, all the graphics cards I tested didn’t support reading the z-buffers manually, or allowing the z-buffer to be created in ram, so it ran slower than expected, around 1-2 seconds per frame.

Recommended Specs:
The sun was made by Adam Shen.

This is one of the most fun personal projects I have ever done ^_^. I put a ton of researching, experimenting, optimizing, and time into it.

I played with a huge amount of graphics algorithms (mostly culling) and visual effects. Unfortunately, much of what I wanted and tested was undoable/unavailable at the time due to hardware limitations, and the software (non GPU) implementations proved too slow, so I couldn’t get it going infinitely like I had hoped. I therefore limited the user to a fixed area of landscape somewhere in the range of (incredibly random guess) .5 square miles. I may decide to revisit this when DirectX 10 is available for XP, with time permitting.

This also contained some vertex shader experiments when they were first introduced. Unfortunately, pixel shaders were not really available at the time so I didn’t get to implement effects with them.

Important notes:
  • The current version uses the DirectX input API (DirectInput), so your antivirus may warn you that the application is trying to gain full keyboard access, which may be marked as a “key logger”. This is a normal thing that happens with most all games.

  • Different detail levels are available. The higher the level, the more detailed, but the more work for the engine.
  • The landscape is always dynamically generated. Different detail levels of the fractal can be regenerated individually, keeping the detail levels above it the same, or all detail levels can be regenerated at once.
  • A good “Example Fractal” is available.
  • There are both OpenGL and DirectX implementations.
  • Toggleable options:
    • Full Screen mode: Full screen is used instead of just a window
    • Wireframe: Render scene as wireframe instead of filled polygons
    • Clouds: Turn on and off the clouds in the sky
    • Dynamic Lighting: Turn off shadow lighting based upon the sun’s position against polygon’s facing direction. All colors will appear uniform at the same height when this is turned on.
    • Distance Fogging
  • Revolving sun: The Sun’s position changes landscape shadows. See Dynamic Lighting. The Sun’s position can be dragged with the mouse in the option dialog.
  • Different types of occlusion culling (for speed): Quad tree and viewable bounding box (see Technical Details for more information)
  • Special Effects:
    • Height Color: Polygon colors are dynamically generated at runtime based upon height, instead of normal pre generation.
    • Distance Color: Polygon colors are dynamically generated based upon their distance from your camera’s position. They go from shades of (closest to farthest) red to green to blue.
    • Waving: Landscape gets wavy through trigonometric (sin/cos) functions. Waves can be increased and decreased through shortcut keys (see Controls).
  • Options are available through keyboard shortcuts or through the options dialog GUI.
  • Option shortcut keys are underlined in the option dialog.

Technical details:
  • The landscape is made through a diamond square algorithm fractal generator.
  • The clouds use the same generated fractal as the landscape.
  • The main engine speedups are done through equal quad tree areas for view frustum culling of terrain data.
  • The engine also has a type of occlusion culling in which areas are rendered front to back and if a bounding box for an area has no pixels seen, the area is not needed to be drawn. This is done after view frustrum culling.
  • The “Special Effects” are done through vertex shaders and are currently only available for the DirectX implementation of the engine.
  • See this paper I wrote in 2003 about the project for in-depth technical details.

Controls: (Shortcut keys are underlined in the option dialog)
  • Basic:
    • Mouse Movement - Left & right rotates the camera around in a circle via the x axis; up & down for y axis for up to 90 degrees down, and 45 degrees up.
    • W/A/S/D” (or arrow keys) - Forward, left, back, right (in order) keys. Left and right strafes; and forward goes 3 times faster than the other directions.
    • enter - Toggle the options dialog
    • esc - Exit the program
  • Graphics Engine
    • X” - Toggle the DirectX engine
    • G” - Toggle the OpenGL engine
  • Toggleable Options
    • F” - Toggle full screen mode
    • I” - Toggle wireframe
    • C” - Toggle clouds
    • L” - Toggle lighting/sun
    • O” - Toggle fog
  • Generating landscape
    • =\+” - Increase the fractal level by 1. The fractal level is basically the detail of the landscape. By default, it goes up to 5 levels, as any larger starts taking incredible amounts of memory and processing.
    • -” - Decreases the fractal level by 1. This will revert the landscape back to the state it was in before the previous increase.
    • N” - Re-randomizes all fractal levels back to a level 5 like when the program starts
    • R” - Re-randomize the current fractal level
    • E” - Example fractal. Restarts the map to a custom fractal that is a good example
  • Other options
    • J/K” - Revolve sun counter-clockwise and clockwise
    • [/]” - Increase/Decrease waving effect (“Waving” special effect must be turned on)
    • Q” - Turn on Quad Tree culling
    • U” - Turn on Quad Tree and Occlusion culling (See Technical Details)

Precompiled source code options/definitions: (These are found in Definitions.h)
  • ScreenWidth: Drawing Screen Width
  • ScreenHeight: Drawing Screen Height
  • MaxFracLevs: Maximum Fractal Levels Achieved Via the “+” key
  • MinFracLevs: Minimum Fractal Levels Achieved via the “-” key
  • MoveSpeed: The speed at which a stroke of the forward key moves the camera in the world
  • AreaViewable: The perspective area from straight forward the viewer can see, 45 degrees is natural for 3D applications. Do not set the value to 180 or above. The smaller the area viewable (less area viewed), the faster the frame-rate, due to the quad tree culling routines.


Normal View - This uses the provided example fractal with the camera in the southwest corner
Normal View

Revolving Sun - Same position but with the sun near the north position
Rotated Sun

No Fog - Same position with the fog turned off
No Fog

Wireframe - Same position with the camera angled downwards and wireframe turned on

Alternate View - This is the same provided example fractal with the camera in the southeast corner
Alternate View

Range View - “Distance Color” mode
Range View

Alternate Landscape - This is a different randomly generated landscape
Alternate Landscape

Options - The options window
Graphics, 3d algorithms, speed optimization
Dakusan License v2.0 @ 2009-11-04 16:06:57 - Download

I have updated the licensing information across the board for my website and all its projects to the Dakusan License v2.0, a slightly modified version of the Original BSD License.

The Copyright page and all project downloads have been updated accordingly.

Added Readme files to all project downloads @ 2009-09-19 05:35:19

Binary and source zip downloads for all Projects now have readme files in them, except as mentioned below.

This only applies to the Draw Image Project in Web Scripts, and not the Directory Manager project (The only project zip file now without a readme).

Fractal Landscape Technical Paper v1.0 @ 2008-10-13 01:53:46 - Download

I finally got around to touching up the paper I wrote in 2003 on how I made the Fractal Landscape, which also includes some theories and stuff. The overview states “The purpose of this paper is to report my discoveries over the last few months from working on my fractal landscape program.”.

I don’t even want to try and relate here how much of a bitch it was converting it from the shit that Microsoft Word outputs into a clean and W3C compliant HTML. But then again, that’s always a problem with Word output, which is why I try to not deal with it often, or convert it to plain text first when possible.

A PDF copy is also available.

Fractal Landscape v1.05 @ 2008-10-02 19:23:25 - Download
The following updates have been made to the Fractal Landscape project, v1.05:
  • DirectX Bug (reported in last update): The water sometimes overlaps solid objects where it shouldn’t. This is due to some alpha blending setting conflicting with the z-buffer.
    • Cause: The problem was my graphics card doesn’t seem to like 16 bit depth buffers much (in this case, the w-buffer, which is mostly the same thing as a z-buffer). Oddly, this wasn’t a problem with any older graphics cards I had tested it on, and OpenGL seems to have no problem with a 16 bit depth buffer.
    • Solution: The code now has the graphics cards choose the highest available depth buffer solution for DirectX using “CheckDepthStencilMatch” (32bit, 24DX8 (24bit), or 16bit).
  • DirectX Bug (reported in last update): The clouds do not show up at most viewing angles when fogging is turned on.
    • Cause: An improper fog rendering setting
    • Solution: “SetRenderState(D3DRS_FOGVERTEXMODE, D3DFOG_LINEAR);” has been changed to “SetRenderState(D3DRS_FOGTABLEMODE, D3DFOG_LINEAR);”.
  • DirectX Bug (reported in last update): If fogging is turned on while a “Special Effect” is also on, all landscape surfaces show as pure white.
    • Cause/Solution: Same as for the above bug (improper fog rendering setting)
  • DirectX Bug (reported in last update): When leaving full screen mode the window’s title bar is sometimes pushed off the screen.
    • Cause: DirectX does not keep window settings when switching to exclusive video mode.
    • Solution: On resuming from full screen, “WS_BORDER” is added back to the window style.
  • Code Cleanup (OpenGL): The 1bit stencil buffer has been turned off. Not sure why I even had this on in the first place.
  • Code Cleanup (DirectX): Removed “D3DPRESENTFLAG_VIDEO” from the Direct3D present parameters flag and added “D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL”.
  • Code Optimization: Added some floating point optimization in the height position determination when the camera position moves.
  • Engine Feature/Fix: The Engine now makes sure the user does not start underwater when a new fractal is initialized.
    • Solution: The engine detects if the camera starts under the water, and if so, it picks the closest height map point that is above water and sets the camera there.
  • Other: I compiled this one using the normal Microsoft Visual C++ compiler instead of the Intel C++ Compiler, which has resulted in a ~40% decrease in the executable size.
Fractal Landscape v0.5 and v1.0 @ 2008-09-30 17:02:14 - Download

I’ve finally gotten around to getting my Fractal Landscape program up with information, yay.

I am currently releasing two “versions”:
  1. The first “version” (which I will henceforth call OrgVer) is the original version I made that was specifically put together for a portfolio I was assembling when looking for a job at game companies in 2003.
    • I threw OrgVer together as quick as I could as I was eager to start looking for a job at the time and needed some good working examples. Because of this, I didn’t concentrate on making the code pretty or maintainable like I do with most other code, as I never planned on releasing the source code for it. However, since it is a legacy version and I decided to continue with the project later on, I don’t mind releasing this original version’s source code now.
    • I have made slight modifications to OrgVer as following so it can more easily be compiled and such:
      • This was originally compiled for a specific version of DirectX 8, and has been updated for DirectX 9. This entailed changing a few function call names and their parameters.
      • There were originally 2 separate versions included with OrgVer. One was the normal code base, and the other had just a few modifications to include graphics card occlusion culling. I have haphazardly combined the two files through macros found in the “#if UseOcclusion==1” section (UO, NUO, OrOp).
      • Executable version information (which always includes the Hyrulean Productions Icon) has been added.
    • The original compile (fully working with the fractal generation, lighting, and some other stuff), which I did not keep, was made in 2 to 3 days in, I estimate, 25 to 30 hours (including research on how to generate fractals and such). I worked on it for 2 or 3 more weeks after that though and finished OrgVer with about 1,411 lines of code.
    • It only has a DirectX Engine (no OpenGL version in this one).
    • Controls are as follows: (For more detailed information on the controls, see the corresponding keys in the “Controls” section)
      • Mouse Movement - Rotates the camera.
      • =\+” - Increase the fractal level by 1.
      • -” - Decreases the fractal level by 1.
      • R” - Re-randomize the current fractal level.
      • enter - Re-randomizes all levels back to a level 5.
      • W/A/S/D” - Forward, left, back, right (in order) keys
      • L” - Toggle lighting/sun
      • M” - Re-centers the mouse cursor. Only available in non-FullCPU mode.
      • E” - Example fractal
      • F” - Toggle full screen
      • J/K” - Revolve sun counter-clockwise and clockwise
      • C” - Toggle clouds
      • O” - Toggle wireframe
      • esc - Exit the program
    • Source Code Definitions (See the “Source Code Definitions” section). The differences are as follows:
      • FullCpu: This toggles FullCpu mode for the executable.
        • When in FullCpu mode (1), which is the default:
          • DirectX handles keyboard and mouse input events.
          • Program receives all keyboard/mouse input even if window does not have focus.
          • The mouse cursor is locked to the window when it has focus.
          • Frames are redrawn consistently, immediately after each other.
        • When not in FullCpu mode (0), which is event driven:
          • The Windows’ event message system is used to handle keyboard/mouse input
          • Frames are only drawn when an update to the screen has occurred via a keyboard/mouse action.
          • This mode is less resource intensive.
      • UseOcclusion: Turn on hardware occlusion culling
      • WinStyle: This is not found in OrgVer
    • Downloads:
      • v0.5 Binaries - There are 3 executables of OrgVer found in this archive that only differ from toggled “Source Code Definitions”:
      • v0.5 Source - Important Note: Source code has not been cleaned up and was originally never intended for release. See above information in this update for more details.
  2. The second “version” I am releasing was finished, I believe, within one to two months after OrgVer, when I decided to pick the project back up for fun and make it more organized, optimized, user friendly, and add some more bells and whistles :-). I completely rewrote the engine infrastructure to use a complex object oriented approach in c++ with polymorphism, multiple inheritance, virtual classes, and such.
    • The source code and files of this version have not really been modified since I finished them in 2003, except, as always, for adding in executable version information.
    • Downloads: v1.0 Binary

There are also 2 other source trees I made of the project that I need to see to and possibly release. They are DirectX and OpenGL versions that use experimental ray-tracing techniques to speed up height-map rendering, which I wrote a paper about (Aug 2003) and will release it later too under this project after checking over it.

I redid all the screenshots for the project page and added lots of information including: The (formatted and updated) original readme, important notes, features, technical details, controls, and source code options.

[Fixed in v1.05] Regrettably, when I seem to run the engine through the DirectX implementation, there are a lot of bugs on newer graphics cards. The OpenGL implementation seems to still work on all new graphics cards though :-). I am including a list of bugs here that I need to look into that didn’t exist on any of the graphics cards I tried this on when I originally made it, and will see to fixing them later. [Most or all of] these bugs apply to both versions released in this update.

DirectX Bugs: [Fixed in v1.05]
  • The water sometimes overlaps solid objects where it shouldn’t. This is due to some alpha blending setting conflicting with the z-buffer.
  • The clouds do not show up at most viewing angles when fogging is turned on.
  • When leaving full screen mode the window’s title bar is sometimes pushed off the screen.
  • If fogging is turned on while a “Special Effect” is also on, all landscape surfaces show as pure white.

Other options I may add in the future:
  • Infinite fractal range (this one would take a major rewrite). This would also allow better Level of Detail (LOD) optimizations.
  • Running the engine in Windows’ event mode. This is currently available in the OrgVer “first version” available in this update. See “FullCpu” (the turned off version) in Source Code Definitions in this update.
  • Re-mappable keyboard shortcuts
  • Make “Special effects” available in OpenGL. Unfortunately, when I programmed this, the shaders I wanted weren’t really properly supported in OpenGL.
  • Integrate the “ray-tracing” modes
  • Dialog box keyboard shortcuts, including enter and escape
  • Option to have the engine pause when window loses focus
  • Make sure user doesn’t start under water [Added in v1.05]
  • Real shadows based upon the height-map (Not likely that I’m going to worry about this)
  • Lens flair when looking at the sun. I tried this at one point and failed pretty miserably, heh. Couldn’t get it to look right! This kind of thing is so pas sé/old school though ^_^;.
To add comments, please go to the forum page for this project (guest comments are allowed for the Projects, Posts, and Updates Forums).
Comments are owned by the user who posted them. We accept no responsibility for the contents of these comments.

No comments for this Project