Portfolio


  • Home
  • DirectX Raytracing
  • Advanced Graphics
  • Roboflux
  • Boat Simulation

BOAT SIMULATION



The project



I created this project for a module called Further games and graphics. In this module I created a basic forward renderer using DirectX11 and learnt about various graphical techniques. Some examples include billboarding, different lighting models and skyboxes.



Lighting



The first part of the project I attempted was to implement sufficient lighting. I started off by implementing flat shading. This was relatively simple and was just an easy way of getting used to using HLSL and the intricacies that go along with it such as structure packing. After flat shading I implemented Gouraud shading with ambient, diffuse and specular light. Finally, I implemented Phong shading which was just a case of moving the calculations taking place from the vertex shader to the pixel shader, so calculations are carried out on a per pixel basis.


Once I had finished implementing the lighting, I looked at implementing different types of lights. In the end I implemented directional, point and spotlights. The spot and point lights used the constant-linear-quadratic attenuation equation to make the light to fall off at range. I used this equation as, although not physically accurate, it allows more control over the range of the light.



Skybox



After the lighting was done, I implemented the skybox. This was done using the pixel shader to map the UV coordinates depending on the viewing angle. I investigated various different ways of implementing the skybox and decided to map the texture onto a sphere. This has the downside that there is a seam at the top and bottom of the skybox. I could get rid of this by using a texture array and mapping the appropriate texture onto a cube using the same technique as with the sphere.



Water generation



To simulate the water, I created a grid and then used a simple sine function with appropriate scaling factors for the Y value. I then used the total runtime to animate the waves. The Z value of each vertex in the grid was used as an offset to ensure the wave effect occurred rather than just moving the whole plane up and down. To do this, I had to create the vertex as a dynamic buffer and upload to it every frame. When calculating the normal at each vertex in the grid I differentiated the sine function used to create the wave and subbed in the appropriate value. I then rotated the returned value (tangent) by 90 degrees and normalised it. To finish off the water I used blending to give it the transparent appearance.


On reflection a better approach would have been to pass the grid of vertices into the pipeline. A water shader could then be used to animate the water taking advantage of the GPU's parallel architecture rather than doing it on the CPU.



Fog



Another feature I implemented was fog. I did this in the pixel shader by passing in a fog start, fog range and fog colour value. If the object is before the fog start value, then there is no fog. If the object is further away than the fog start, then the distance the object is past fog start is divided by the fog range. This then gives a percentage which can be used to lerp between the current pixels colour and the fogs colour.



Billboarding



The final feature I implemented to the framework was billboarding. I used the geometry shader to expand one point into a plane. This was done by finding the vector to the camera. This vector can then be used with the up vector to create a right vector using the dot product. This can then be scaled appropriately depending on how big you want the billboard to be. This ensure the billboard is always looking at the camera. I then used alpha clipping to allow me to create billboards that weren't always a square or rectangle. Once I'd done this, I passed in the position of the billboard to the waters pixel shader and then used a lerp using the distance from the pickup as the scaling factor.