Light Performance Comparison Between Forward, Deferred and Tile-Based Forward Rendering
Total Page:16
File Type:pdf, Size:1020Kb
Bachelor of Science in Digital Game Development September 2020 Light Performance Comparison between Forward, Deferred and Tile-based forward rendering Vladislav Polyakov Faculty of Computing, Blekinge Institute of Technology, 371 79 Karlskrona, Sweden This thesis is submitted to the Faculty of Computing at Blekinge Institute of Technology in partial fulfilment of the requirements for the degree of Bachelor of Science in Digital Game Development. The thesis is equivalent to 10 weeks of full time studies. The authors declare that they are the sole authors of this thesis and that they have not used any sources other than those listed in the bibliography and identified as references. They further declare that they have not submitted this thesis at any other institution to obtain a degree. Contact Information: Author(s): Vladislav Polyakov E-mail: [email protected] University advisor: Hans Tap Department of Computer Science Faculty of Computing Internet : www.bth.se Blekinge Institute of Technology Phone : +46 455 38 50 00 SE–371 79 Karlskrona, Sweden Fax : +46 455 38 50 57 Abstract Background. In this experiment forward, deferred and tile-based forward render- ing techniques are implemented to research about the light-rendering performance of these rendering techniques. Nowadays most games and programs contains a graph- ical content and this graphical content is done by using different kind of rendering operations. These rendering operations is being developed and optimized by graphic programmers in order to show better performance. Forward rendering is the stan- dard technique that pushes the geometry data through the whole rendering pipeline to build up the final image. Deferred rendering on the other hand is divided into two passes where the first pass rasterizes the geometry data into g-buffers and the second pass, also called lighting pass, uses the data from g-buffers and rasterizes the lightsources to build up the final image. Next rendering technique is tile-based forward rendering, is also divided into two passes. The first pass creates a frustum grid and performs light culling. The second pass rasterizes all the geometry data to the screen as the standard forward rendering technique. Objectives. The objective is to implement three rendering techniques in order to find the optimal technique for light-rendering in different environments. When the implementation process is done, analyze the result from tests to answer the research questions and come to a conclusion. Methods. The problem was answered by using method "Implementation and Ex- perimentation". A render engine with three different rendering techniques was im- plemented using C++ and OpenGL API. The tests were implemented in the render engine and the duration of each test was five minutes. The data from the tests was used to create diagrams for result evaluation. Results. The results showed that standard forward rendering was stronger than tile- based forward rendering and deferred rendering with few lights in the scene.When the light amount became large deferred rendering showed the best light performance results. Tile-based forward rendering wasn’t that strong as expected and the reason can possibly be the implementation method, since different culling procedures were performed on the CPU-side. During the tests of tile-based forward rendering there were 4 tiles used in the frustum grid since this amount showed highest performance compared to other tile-configurations. Conclusions. After all this research a conclusion was formed as following, in envi- ronments with limited amount of lightsources the optimal rendering technique was the standard forward rendering. In environments with large amount of lightsources deferred rendering should be used. If tile-based forward rendering is used, then it should be used with 4 tiles in the frustum grid. The hypothesis of this study wasn’t fully confirmed since only the suggestion with limited amount of lights were con- firmed, the other parts were disproven. The tile-based forward rendering wasn’t strong enough and the reason for this is possibly that the implementation was on the CPU-side. Keywords: Forward rendering, Deferred rendering, Tile-based forward rendering, Forward-plus rendering, Pointlight implementation. Acknowledgments I would like to thank my supervisor Hans Tap for helping me writing this thesis. I would also like to thank Stefan Petersson for his support in the implementation of the rendering techniques for this experiment. iii Contents Abstract i Acknowledgments iii 1 Introduction 1 1.1 Background ................................ 1 1.2Aim.................................... 3 1.3 Objectives ................................. 3 1.4 Research Questions ............................ 3 1.5 Hypothesis ................................. 3 1.6 Structure of this thesis .......................... 4 2 Related Work 5 3 Method 9 3.1 Implementation .............................. 9 3.1.1 OpenGL Shader Pipeline ..................... 10 3.1.2 Forward Rendering ........................ 10 3.1.3 Deferred Rendering ........................ 15 3.1.4 Tile-based Forward Rendering .................. 19 3.2 Performance Testing ........................... 21 3.2.1 Hardware ............................. 22 4 Results 23 5 Analysis and Discussion 31 6 Conclusions and Future Work 35 References 37 v List of Figures 3.1 Shows OpenGL Shader Pipeline. The yellow sequences are the fixed one and the grey are the programmable one. Picture taken from Khronos official page. ........................... 9 3.2 Shows the forward rendering shading pipeline. Picture taken from [3]. 10 3.3 Shows the camera initialization calculations. .............. 11 3.4 Shows different matrix calculations and light data updates. ...... 11 3.5 Shows an example on a vertex shader for forward rendering technique. 12 3.6 Shows the pointlight calculation implementation in the fragment shader. 13 3.7 This illustration is showing the attenuation formula mentioned above. The Kc is attenuation constant, Kl is linear and Kq is quadratic coef- ficient. The d represents the distance from the specific pixel and the lightsource. ................................ 13 3.8 Illustrates a lightsource surrounded by different geometric objects. 14 3.9 Illustrates a lightsource with specular component. ........... 15 3.10 Shows the deferred rendering shading pipeline. Picture taken from [3]. 15 3.11 Shows the creation of the G-buffer which stores geometric data such as positions, normals, albedo (diffuse) and depth. ........... 16 3.12 Shows the first pass fragment shader. .................. 17 3.13 This illustration shows the second pass fragment shader. ....... 18 3.14 This figure shows the position, normal and albedo (diffuse) buffers. 18 3.15 Shows the visual difference between deferred rendering without and with light volumes. ............................ 19 3.16 Shows different lists used for the tile-based forward rendering. Picture taken from [2]. ............................... 21 3.17 Shows an example scene for tests of light calculation performance. 22 4.1 Shows the results of forward rendering frametime test. ........ 23 4.2 Shows the results of forward rendering framerate test. ...... 24 4.3 Shows the results of deferred rendering frametime test. ........ 25 4.4 Shows the results of deferred rendering framerate test. ........ 26 4.5 Shows the performance results with different amount of tiles for tile- based forward rendering. ......................... 27 4.6 Shows the results of tile-based forward rendering frametime test. 28 4.7 Shows the results of tile-based forward rendering framerate test. 29 5.1 Shows the frametime results with the forward rendering in blue, de- ferred rendering in orange and tile-based forward rendering in grey. 31 vii 5.2 Shows the framerate results with the forward rendering in blue, de- ferred rendering in orange and tile-based forward rendering in grey. 32 viii Chapter 1 Introduction This thesis is researching about the light-rendering performance of different render- ing techniques such as standard forward, deferred rendering technique and a more advanced rendering technique called tile-based forward rendering. Since light render- ing is an expensive procedure the goal is to determine which rendering technique is a better choice in environments with few lights and which one is better in environments with a large amount of lights. For this thesis OpenGL API is used and there is a render engine implemented in order to be able to render geometry and other visual constituents to the screen. In this thesis it’s explained how the rendering techniques and different light calculations is implemented. Furthermore to improve the results there are different optimizations explained and implemented for chosen rendering techniques. 1.1 Background Nowadays the most games or programs, contains a graphical content. It’s not there to only make it easier for the user to use and navigate, but even make the program more beautiful and presentable. The graphical content is created by using different kind of rendering operations. Rendering is used to create images on the computer screen, where the program collects needed data and performs different calculations on how it should be rendered on the screen. Year after year, graphics programmers are trying to develop different rendering techniques in order to achieve high quality and photo-realistic images. The first common used rendering technique is forward rendering, there are other several rendering techniques that can generate images, but the most simple