Kyle Hayward's

Portfolio

Terrain Rendering

Description

This project deals with terrain, water, and sky visualization. It was developed in C# with the Managed DirectX API. It focused on representing Mie and Rayleigh scattering for both sky light and aerial perspective. The terrain is managed by a quadtree data structure that is combined with frustum culling to cull away patches that are not in the view. The water has realistic coastal properties, exhibits Fresnel reflection and refraction, and has soft intersections with the terrain.

Features

  • Supports up to 2048x2048 multi-textured terrain

  • Water with reflection and refraction

  • Soft water edges

  • Under water fogging and depth fogging

  • Dynamic sky with atmospheric scattering

  • Volumetric clouds

  • Frustum culling

  • Bloom post-processing

Screen Shots

Video

Source Snippet

/// <summary>
/// Builds a quadtree from a vertex grid
/// </summary>
/// <param name="node">The root of the current subtree</param>
/// <param name="R">The bounds of the node</param>
/// <param name="gridVerts">All the vertices of the grid</param>
private void recursiveTerrainBuild(SubGrid node, ref Rectangle R, VertexPosNormTex[] gridVerts)
{
    if (R.Width <= 32)
    {
        mNumLeaves++;

        //build the vertex and index buffers for this node
        buildSubGridMesh(ref R, gridVerts, true, node);
        node.IsLeaf = true;

        return;
    }

    //calc dimensions of this node
    buildSubGridMesh(ref R, gridVerts, false, node);

    int newWidth = R.Width / 2;
    int newHeight = R.Height / 2;
    int newSubRows = R.Width / newWidth;
    int newSubCols = R.Height / newHeight;

    int index = 0;
    ///  SubGrid        r | c
    ///  Top-Left    :  0   0
    ///  Top-Right   :  0   1
    ///  Bottom-Left :  1   0
    ///  Bottom-Right:  1   1
    for (int r = 0; r < newSubRows; r++)
    {
        for (int c = 0; c < newSubCols; c++)
        {
            Rectangle rec = new Rectangle(
                                R.Left + c * (newWidth),
                                R.Top + r * (newHeight),
                                (newWidth),
                                (newHeight));

            node.children[index] = new SubGrid(newWidth + 1, newHeight + 1);

            recursiveTerrainBuild(node.children[index], ref rec, gridVerts);

            index++;
        }
    }
}

Downloads

Binary:

Source: