Summary
The following is a real-time shader scene demo produced for a rendering module in the IET masters course. This demo features a simple scene with a boat moving around a coastal region and employs several real time shader effect methods. Shader effects applied to this scene includes reflection, height maps, vertexs varying with frequency of the music, bump mapping, textures, shadow mapping and bloom.
Basic scene with multiple shaders
The scene produced features several objects, these include the cliff plane, the wave plane, the boat, the light house and the sphere above the boat. The planes are created from first principles, while the boat, lighthouse and sphere are loaded in from external made .fbx files.
Each of these is textured based on the model’s UV coordinates in the vertex shader, with the relevant colour pixel being applied to the mapped coordinate. These colour maps are diffuse, with the diffuse, ambient and secular properties for each object passed into the shader separately so as to give full artistic control over the scene properties.
different values applied to the material property colours produces different light effects
The boat with a wood texture an bump map
The cliffs, texture and bump mapped with a rock texture
The scene features three lights sources, all three of which are spotlights with the same cut off angle and exponent, chosen to optimise the scene atmosphere. The intensity value of the light is based on the distance to the light source and an intensity value fed into the shader. The lighting effects seen in the demo are caused by applying spikes in this intensity value at given times. These effects are calculated in the pixel shader.
The scene also contains two illumination models. The majority of the scene uses the popular Phong illumination model, while the wave plane uses the more efficient Blinn-Phong model which uses a half vector in place of the costly calculation of the reflection vector. In modern systems the difference in efficiency causes minimal effect on the scene and thus the Phong is seen as an acceptable method. These methods are applied in the pixel shaders.
The scene features three lights sources, all three of which are spotlights with the same cut off angle and exponent, chosen to optimise the scene atmosphere. The intensity value of the light is based on the distance to the light source and an intensity value fed into the shader. The lighting effects seen in the demo are caused by applying spikes in this intensity value at given times. These effects are calculated in the pixel shader.
The scene also contains two illumination models. The majority of the scene uses the popular Phong illumination model, while the wave plane uses the more efficient Blinn-Phong model which uses a half vector in place of the costly calculation of the reflection vector. In modern systems the difference in efficiency causes minimal effect on the scene and thus the Phong is seen as an acceptable method. These methods are applied in the pixel shaders.
Vertex Shader
The scene features two vertex shaders. The first of which is a simple height map shader. This method reads in a height map into the vertex shader and sets each vertex’s height (y position) based on this map. This is applied to a plane in order to make the cliffs seen in the demo.
The second vertex shader effect is used to make the waves. This shader is based on the music from the demo music, with the current music frequency values passed into the vertex shader. The height of the vertex is set based on the music frequency and the particular vertex’s z position, varying with time, causing the wave like pattern seen in the demo.
The second vertex shader effect is used to make the waves. This shader is based on the music from the demo music, with the current music frequency values passed into the vertex shader. The height of the vertex is set based on the music frequency and the particular vertex’s z position, varying with time, causing the wave like pattern seen in the demo.
showing the two planes with different vertex shader effects
the planes when the music has stopped, and thus the plan is flat and only the height mapped plane is raised
Shadows
Shadows are essential for the building of a realistic scene. For this demo shadow mapping was used. This involves creating a depth map for the scene from the light sources perspective, storing the depth not the colour of the scene. Once the depth map is created it is fed into the full scene rendering with the distance to the light of a pixel checked an compared with the depth map values and if the calculated depth is greater than the stored depth(from the map) then this pixel is in shadow. The bias depth is used to remove the surface acne caused by the shadow map fixed precision.
This method scales well to several objects and handle self shadowing of objects. Due to the change in object height caused by the different vertex shaders in the scene, three different shadow map creation methods had to be employed in order to ensure that the cliffs and waves created are shadowed correctly. This involved having different shadow vertex shaders, which applied the same vertex effect method as the vertex shaders do.
This scene also contains multiple lights sources which means multiple depth maps had to be created. All three depth maps (one of each light) where created in the same way and all passed to the final scene pixel shader. This shader is then looped for each light source checking the depth map values, and determining what was in shade, with the overall output being additive result of these checks. As each light source is at a different position trial and error methods had to be applied to achieve acceptable frustum clipping ranges for accurate shadows for each light source.
the shadows in the scene
Lighting effect
Dynamic cube mapping was used to generate reflective surfaces in the scene. This is done by placing the camera at the centre of a cube, in the position of the object having the reflective mapped built for it. The camera is then placed at each face of the cube, rendering the other objects in the scene to this face. This takes six passes, i.e. one pass per face to render the cube texture.
dynamic cube mapped Fresnel reflectance
Post process effect
Two post processing effects where implemented in this project although only one of them was used in the final demo.
Depth of field
Depth of field is an effect in which the foreground and background of an object being looked at is becomes unclear. This occurs with eyes naturally but is also frequently applied as a motion film technique. The first step taken in the creation of depth of field is to take a depth map from the perspective of the camera (rather than the lights sources as in the shadow maps). In order to blur the scene as required a blur scene shader is implemented which modifies the texture coordinate in question using the distance as a lookup texture containing the normal scene, so it takes the top-left, top-right, bottom-left and bottom-right pixel, adds them together and divides it by 4 to get the average about a pixel, thus creating blur. To further blur the scene this blurred image then has the same post processing effect applied to it (i.e. is blurred twice)
In order to find what is in focus in the scene a shader is used, which takes the negative of the near clipping plane and multiplies it with the modified far clipping plane(far clipping plane divided by far-near), and dividing it by how far away the focal-point is, subtracted by the modified far clipping plane. This is used to calculate how far this point is from the distance point set in the shader, fading out based on the set Range value. This should create a realistic scene with object fading in and out of focus based on their distance to the camera. However, through much trial and error variable which gave satisfactory results which fit the intended demo scene were not found and thus the effect was dropped from the final demo.
Bloom
Bloom was chosen to also be implemented in the scene. This is a post processing effect which causes colours to flow to surrounding pixels brightening or overexposing them; making dark pixels on the edge of bright pixels lose detail.
First the scene is rendered as a texture and then the bright areas are extracted and stored in a separate scene. The bloom shader is used to extract these bright colours based on some threshold. This bright area texture is then blurred using the same shader implemented for depth of field (and is again used twice on the scene to get full effect).
Another shader is then used to combine the two textures (the blurred bright scene and the original scene). This shader adjusts the bloom and original scene colours based on the intensity values set in the shader (this is done in the pixel shader). Areas in the original scene where the bloom is bright are darkened out to avoid burning out this area. Then these two textures are simply added together.
the scene with no post processing effect
the scene with bloom only applied
the scene with depth of field only applied










