Skip to content

Lab 6: Displacing a Grid in a Vertex Shader

drebain edited this page Jun 14, 2017 · 1 revision

Lab 6: Displacing a Grid in a Vertex Shader

In this lab you will displace the vertices of a grid using values from a scalar function. This is useful for tasks such as generating procedural terrain.

The code for this lab is in the 'assignment3' subfolder of the icg repository.

Sampling the Function

The provided vertex shader includes a parameter uv that gives the position of each vertex in texture space (i.e. one corner of the grid is [0,0] and the opposite corner is [1,1]). Use this as the input to a scalar function or expression to calculate a height displacement value. You can use something like sin(uv.x) + cos(uv.y).

Displacing the Vertices

Recall that vertex positions are passed into the shader in model space. They are then transformed with the MVP matrix that puts them into screen space before being given to the GPU rasterizer. You will want to apply the displacement as a vertical translation to the model space position of each vertex.