Run-Time Terrain Deformation in Unreal Engine 4
Total Page:16
File Type:pdf, Size:1020Kb
Master of Science in Game and Software Engineering May 2020 Run-time Terrain Deformation in Unreal Engine 4 Rikard Magnom 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 Master of Science in Game and Software Engineering. The thesis is equivalent to 20 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): Rikard Magnom E-mail: [email protected] University advisor: Adjunct Prof. Stefan Petersson 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. When developing video games, an often desired trait is that of player immersion. Player immersion can be achieved through many different ways. How- ever, a common technique used is to allow the player to affect the environment in some way, through destruction or deformation. Unreal Engine 4 is a commonly used commercial game engine, that lacks features necessary to deform terrain at run-time. Objectives. This thesis explores the viability of run-time performant terrain defor- mation in Unreal Engine version 4.23. A deformation technique of a depth-based Dynamically-Displaced Height Map (DDHM) is selected for implementation and tested with various sizes of landscape terrains. Methods. A small literature study is performed to select a feasible run-time terrain deformation technique. The technique is then implemented in the engine, along with modifications to the engine to provide the necessary functionality. The implementa- tion is then tested on performance and accuracy. Results. The DDHM technique is shown to provide run-time performant terrain de- formation for smaller terrain sizes, consisting of an individual landscape component. The selected technique does not meet the run-time requirements for full, large-scale deformation. Conclusions. Run-time performant terrain deformation is shown to be achievable in Unreal Engine 4.23. While the selected technique fails to achieve satisfying results for larger terrain sizes, results on individual landscape components show feasibility for generic technique implementations. Keywords: terrain, deformation, real-time, unreal engine i Sammanfattning Bakgrund. Under utvecklingen av datorspel är det ofta en eftertraktad egenskap att kunna övertyga spelaren om realismen i spelvärlden. Detta kan uppnås på flera sätt, men en vanlig teknik är att låta spela påverka omgivningen i spelet på något sätt, genom förstörelse eller deformering. Unreal Engine 4 är en vida använd kom- mersiell spelmotor som saknar funktionalitet för att deformera terräng i realtid. Syfte. Syftet med detta arbete är att utforska genomförbarheten i att tillföra ter- rängdeformering i realtid i Unreal Engine version 4.23. En deformeringsteknik in- volverande en “Dynamically-Displaced Height Map” (DDHM) väljs ut för implemen- tation och testas med olika storlekar på landskapsterräng. Metod. En mindre litteraturstudie genomförs för att välja en rimlig teknik för ter- rängdeformering i körtid. Tekniken implementeras sedan i motorn, i sambard med modifikationer till motorn för att tillföra nödvändig funktionalitet. Implementatio- nen testas sedan på prestanda och precision. Resultat. DDHM-tekniken visas kunna tillföra körtidsduglig terrängdeformering för mindre terrängstorlekar, bestående av individuella landskapskomponenter. Tekniken möter inte realtidskriterierna för full, storskalig terrängdeformation. Slutsatser. Deformering av terräng i körtid visas vara genomförbart i Unreal Engine 4.23. Den utvalda tekniken visar lovande resultat för mindre storlekar av landskap- sterräng, men misslyckas att prestera för större terrängstorlekar. Nyckelord: terräng, deformering, realtid, unreal engine iii Acknowledgments First and foremost I would like to sincerely thank Stefan Petersson for his superb guidance and valuable feedback during the writing of this thesis, and for helping me stay sane throughout the process. I also express great gratitude towards Logic Artists for collaborating with me in the execution of this thesis, and for giving me free reign to work whenever needed throughout the process. An additional special thank you to my dear friend James Partridge for his assistance in proofreading. Finally, a warm thank you to my mother and my grandparents, for staying supportive of me forever and always. v Contents Abstract i Sammanfattning iii Acknowledgments v 1 Introduction 1 1.1 Environment Interaction . 1 1.2 Objectives and Research Questions . 1 1.3 Terminology . 2 2 Related Work 3 2.1 Hardware Tessellation . 3 2.2 Unreal Engine Landscape Systems . 4 2.3 Displacement mapping . 5 2.4 Parallax mapping . 5 3 Method 7 3.1 Literature Study . 7 3.2 Depth-based DDHM . 9 3.3 Visual Representation . 11 4 Implementation 13 4.1 Deformation Actor . 13 4.1.1 Actor Initialization . 13 4.1.2 Class Structure . 13 4.2 Engine Source Code Modifications . 15 4.3 Engine Limitations . 17 4.3.1 Limitations of the USceneCaptureComponent2D . 18 4.3.2 Limitations of the Landscape Module . 18 5 Results 21 5.1 Experimental Results . 21 5.1.1 Testing Environment . 21 5.1.2 Full Algorithm Performance . 22 5.1.3 Render Target Import Performance . 23 5.1.4 Heightmap Update Performance . 23 5.1.5 Average Error . 24 vii 5.1.6 Conversion Resolution Scalar . 24 6 Analysis and Discussion 27 6.1 DDHM . 27 6.2 Generic Run-time Deformation . 27 6.3 Sustainability . 28 6.4 Validity Threats . 28 7 Conclusions 29 8 Future Work 31 References 33 A Deformation Actor Source Code 37 viii List of Figures 2.1 Visual example of overlapping landscape components. Note the du- plicated vertices [13]. 4 2.2 Parallax mapping used on a wall texture in Bethesdas The Elder Scrolls IV: Oblivion [28]. 5 3.1 Details of the first Google Scholar database search of the small liter- ature study. 7 3.2 Details of the first BTH Summon database search of the small litera- ture study. 8 3.3 Details of the second BTH Summon database search of the small lit- erature study. 9 3.4 Details of the third BTH Summon database search of the small liter- ature study. 9 3.5 The depth capture camera configuration for generation of a DDHM [1]. 10 3.6 The process of depth information being converted to a heightmap through the DDHM technique. (a) shows the object depth clipping through the terrain and being rendered to the depth capture render target. (b) shows the depth value data being used to repopulate the height map. [1] . 11 3.7 Example of one iteration of the terrain deformation. (a) shows the original unmodified terrain. (b) shows the sphere mesh used for this deformation example, rendered for demonstration purposes. (c) shows the resulting deformation in the terrain. 11 3.8 Example of height levels converging to set stages as a result of colour banding in the depth buffer. This example shows the result on the landscape after 30 iterations. 12 4.1 One iteration of the implementation performed on a flat landscape, visualized in gray, deforming around a cube shaped mesh, visualized in orange. (a) shows the configuration before the deformation. (b) shows the result of one iteration of the implementation. 14 4.2 The orthographic projection matrix. The direction parameters left, right, top, bottom represent the size of the orthographic projection from the center. The parameters far and near represent the distance from the camera of the far and near planes respectively. 18 5.1 Execution time of the algorithms performed on a single landscape component with no collision updating. 22 ix 5.2 Average error distance per vertex with the DepthCaptureCamera placed with the near plane at various distances from the landscape mesh. 24 x List of Tables 4.1 All modified engine source code files. 17 5.1 The results of the execution time of a full iteration with collision up- dating enabled. 22 5.2 The results of the execution time of a full iteration with collision up- dating disabled. 23 5.3 The results of the execution time of the render target import. 23 5.4 The results of the execution time of Algorithm 3 with collision updat- ing enabled. 23 5.5 The results of the execution time of Algorithm 3 with collision updat- ing disabled. 24 5.6 Depth buffer heightmap resolution and resolution conversion scalar at various distances of the DepthCaptureCamera. 25 xi List of Algorithms 1 ImportHeightmapFromRenderTarget . 15 2 DeformActorInitialize . 16 3 UpdateLandscapeHeightData . 17 xiii Chapter 1 Introduction In video game development, an often desired element is that of player immersion. Player immersion, which involves convincing the player of the realism of the inter- active game world they are experiencing. A strong contributor to player immersion involves being able to directly interact and affect the game environment. This can be done a multitude of ways such as simply being able to have the environment respond to player interaction [21]. 1.1 Environment Interaction One common form of environment interaction found in video games is the ability for the player to destroy parts of the environment dynamically. Destructible environ- ments in games have a long history, dating back to early examples such as the 1978 arcade game Space Invaders, which featured cover for the player to hide behind. This cover would then progressively get destroyed upon being hit [3]. This trend continued into the 3D era of video games, with series such as Volition’s Red Faction utilizing interactive and fully destructive environments as a primary selling point.