terrain set09115 intro to graphics programming. breakdown basics what do we mean by terrain? how...

35
TERRAIN SET09115 Intro to Graphics Programming

Upload: elijah-hutchinson

Post on 16-Jan-2016

236 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

TERRAINSET09115 Intro to Graphics Programming

Page 2: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Breakdown

Basics What do we mean by terrain? How terrain rendering works

Generating terrain Working with height maps

Rendering realistic terrain Texturing

Page 3: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Recommended Reading

Non specific Reimer has a tutorial on terrain

rendering in XNA http://www.riemers.net/ The principles are essentially the same

Page 4: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Basics

Page 5: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Review

Texturing is the process of applying image data to a surface Wall can be defined using simple geometry Image of a brick wall can be added to make

it a brick wall Image of wooden wall can be added to

make it a wooden wall Texturing is the third part of what can be

considered core 3D rendering Geometry, Lighting, Texturing

Page 6: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Review

Shaders are small programs that run on the GPU

Shaders allow us to implement effects that we may wish for in our rendered scene Lighting, texturing being the most basic

Three types of shader Vertex Geometry Fragment (or pixel)

Page 7: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

What is Terrain Rendering?

Terrain rendering is the process of rendering realistic world surfaces Can be real-world or alien world

The goal of terrain rendering is to provide an outdoor environment for your game Even cityscapes can have underlying

terrain Terrain rendering generally focuses on

the development of hills, valleys, mountains, etc. These can be procedurally generated

Page 8: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Example

Page 9: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

How Terrain Rendering Works Terrain rendering utilises base triangle

meshes, manipulated by a height map, with relevant lighting and texturing added

Four key concepts Generation of a triangle grid Reading of texture data to set vertex

heights Generation of normals for each vertex Texturing / colouring of vertices based on

height / change in height

Page 10: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Triangle Grid

The basic part of a terrain is a large, flat grid of triangles A 2D array of 3D

vertices Each vertex initially

has a height of 0 The heights of each

vertex are manipulated, leading to a terrain like effect

Page 11: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Height Map

To get the heights of an individual vertex, we use a height map

Each pixel of the texture represents a height value of the terrain Dark low, light

high

Page 12: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Texturing and Lighting

Finally, we add texturing and lighting to the terrain to get the effect we want Normals have to

be generated (or read from an image)

Textures can be blended

Page 13: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Question?

Page 14: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Generating Terrain

Page 15: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Height Map Examples

Page 16: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Terrain Mesh

The goal is to create a triangle mesh that represents the terrain to be rendered

Each vertex has a height based on the colour of the height map Some smoothing

may be required

Page 17: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Texture Data

As you know, a texture is just a 2D array of pixels

Each pixel has an RGB(A) value associated with it when it is read in

These pixels can be analysed to determine there colour We can use the intensity calculation from

last week This value can then be used to set the

individual y components of our vertices

Page 18: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Creating a Height Map

Sometimes you will want to create a height map from real world data You can normally acquire height data from

somewhere Sometimes you may want your artist to

generate your height map Think Sim City or similar

You can also generate this map yourself Procedural Bryce (http://www.daz3d.com/i/products/bryce?)

Page 19: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Filtering and Smoothing

Depending on how you get your height data, you might have a limited range For example, if you used the red

component, you only have 255 unique values

Technique is to take these values as large steps, and then filter based on the neighbouring vertex heights Take the average of the vertex and its eight

neighbours

Page 20: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Generating Normals

For each vertex, we have to also generate the normals

Generally, we calculate based on the neighbouring vertices Use cross product to

generate Can also use normal

maps Coming up next week

Page 21: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Lighting a Terrain

Once we have a terrain and the normals, we can go about lighting it

Use the same techniques as before Ambient light Diffuse light Specular light (depends on the terrain)

We can also use occlusion maps and other light maps to help provide more realistic lighting Longer to generate

Page 22: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Example

Page 23: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Questions?

Page 24: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Rendering Realistic Terrain

Page 25: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Colouring by Height

Simplest method to increase believability of the terrain is to colour vertices based on height Easily done in the

shader Choose a number of

colours and based on height use that colour

Page 26: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Colouring by Height Change

We can also colour based on the change of height Steeper slopes have different colours

Usually we want to combine this with colouring by height to provide a more realistic terrain Height used to determine base colour Steepness used to determine colour to

blend with

Page 27: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Texturing by Height

We can perform the same operation as colouring using textures

Normally we want to blend textures between heights Looks too artificial

otherwise

Page 28: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Texturing by Height Change

We can also take into account the change in height as a blend factor for the terrain Provide cliff faces

This will provide the most realistic terrain using standard techniques

Page 29: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Using Multiple Terrain Maps

Sometimes we want to use multiple terrain maps to provide other features For example a road

Blending textures allows us to create realistic features in our terrain

Page 30: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Grass and Vegetation

One final step in generating terrain is adding vegetation Trees Grass

We won’t be doing this in the practical, but if you are interested you should do some further reading

Common technique for adding grass is billboarding

Common technique for adding trees is instancing

Page 31: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Billboarding

Billboarding involves rendering sprites in world space

As sprites are 2D, they always face the camera Gives a weird effect

when moving Billboarding is often

used in particle effects

Page 32: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Example

Page 33: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Questions?

Page 34: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

To do this week…

Practical this week is on lighting Ambient, diffuse, specular, phong

Long practical, with lots of shade usage Terrain will be the last practical we do

Three weeks time If you are interested, there are numerous

tutorials online so you don’t have to wait

Page 35: TERRAIN SET09115 Intro to Graphics Programming. Breakdown  Basics  What do we mean by terrain?  How terrain rendering works  Generating terrain

Summary

Terrain rendering is one of the commonest techniques used in 3D games Realistic outdoor environments being the

goal Generating terrain is actually quite easy

Height map Triangle mesh Terrain textures

You normally want to optimise as well Sub grids of the terrain for culling