COMP 4801 Final Year Project. Ray Tracing for Computer Graphics. Final Project Report FYP Runjing Liu. Advised by. Dr. L.Y.

Similar documents
Intro to Ray-Tracing & Ray-Surface Acceleration

Enhancing Traditional Rasterization Graphics with Ray Tracing. October 2015

Photorealistic 3D Rendering for VW in Mobile Devices

Lighting. To do. Course Outline. This Lecture. Continue to work on ray programming assignment Start thinking about final project

CS 4620 Midterm, March 21, 2017

Photorealism: Ray Tracing

INFOGR Computer Graphics. J. Bikker - April-July Lecture 10: Ground Truth. Welcome!

CPSC GLOBAL ILLUMINATION

Shadows. COMP 575/770 Spring 2013

Sung-Eui Yoon ( 윤성의 )

Ray tracing. Computer Graphics COMP 770 (236) Spring Instructor: Brandon Lloyd 3/19/07 1

CS354 Computer Graphics Ray Tracing. Qixing Huang Januray 24th 2017

Enabling immersive gaming experiences Intro to Ray Tracing

Ray Tracing. Kjetil Babington

Deferred Rendering Due: Wednesday November 15 at 10pm

Computer Graphics 1. Chapter 7 (June 17th, 2010, 2-4pm): Shading and rendering. LMU München Medieninformatik Andreas Butz Computergraphik 1 SS2010

Review for Ray-tracing Algorithm and Hardware

Interpolation using scanline algorithm

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Ray Tracing. Computer Graphics CMU /15-662, Fall 2016

Metal for Ray Tracing Acceleration

Practical 2: Ray Tracing

Effects needed for Realism. Computer Graphics (Fall 2008) Ray Tracing. Ray Tracing: History. Outline

03 RENDERING PART TWO

lecture 18 - ray tracing - environment mapping - refraction

Topic 12: Texture Mapping. Motivation Sources of texture Texture coordinates Bump mapping, mip-mapping & env mapping

Topic 11: Texture Mapping 11/13/2017. Texture sources: Solid textures. Texture sources: Synthesized

DEFERRED RENDERING STEFAN MÜLLER ARISONA, ETH ZURICH SMA/

SUMMARY. CS380: Introduction to Computer Graphics Ray tracing Chapter 20. Min H. Kim KAIST School of Computing 18/05/29. Modeling

Computer Graphics. Lecture 13. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura

Introduction to Visualization and Computer Graphics

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

Computer Graphics (CS 543) Lecture 13b Ray Tracing (Part 1) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Assignment 6: Ray Tracing

Topic 11: Texture Mapping 10/21/2015. Photographs. Solid textures. Procedural

Mach band effect. The Mach band effect increases the visual unpleasant representation of curved surface using flat shading.

INFOGR Computer Graphics

Rendering: Reality. Eye acts as pinhole camera. Photons from light hit objects

Real-Time Universal Capture Facial Animation with GPU Skin Rendering

NVIDIA Case Studies:

Motivation. Sampling and Reconstruction of Visual Appearance. Effects needed for Realism. Ray Tracing. Outline

Recollection. Models Pixels. Model transformation Viewport transformation Clipping Rasterization Texturing + Lights & shadows

Computer Graphics Ray Casting. Matthias Teschner

782 Schedule & Notes

6.837 Introduction to Computer Graphics Final Exam Tuesday, December 20, :05-12pm Two hand-written sheet of notes (4 pages) allowed 1 SSD [ /17]

Game Technology. Lecture Physically Based Rendering. Dipl-Inform. Robert Konrad Polona Caserman, M.Sc.

Global Illumination CS334. Daniel G. Aliaga Department of Computer Science Purdue University

Ray Tracing. Brian Curless CSEP 557 Fall 2016

Advanced Graphics. Path Tracing and Photon Mapping Part 2. Path Tracing and Photon Mapping

Computer Graphics. Lecture 10. Global Illumination 1: Ray Tracing and Radiosity. Taku Komura 12/03/15

Pipeline Operations. CS 4620 Lecture 14

Computer Graphics. Lecture 14 Bump-mapping, Global Illumination (1)

Chapter 7 - Light, Materials, Appearance

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CMSC427 Advanced shading getting global illumination by local methods. Credit: slides Prof. Zwicker

COMP371 COMPUTER GRAPHICS

Lighting and Shading

Global Illumination. COMP 575/770 Spring 2013

Chapter 11 Global Illumination. Part 1 Ray Tracing. Reading: Angel s Interactive Computer Graphics (6 th ed.) Sections 11.1, 11.2, 11.

So far, we have considered only local models of illumination; they only account for incident light coming directly from the light sources.

Rendering Part I (Basics & Ray tracing) Lecture 25 December 1, 2015

Pipeline Operations. CS 4620 Lecture 10

CS580: Ray Tracing. Sung-Eui Yoon ( 윤성의 ) Course URL:

Enhancing Traditional Rasterization Graphics with Ray Tracing. March 2015

Effects needed for Realism. Ray Tracing. Ray Tracing: History. Outline. Foundations of Computer Graphics (Spring 2012)

CS 4620 Program 3: Pipeline

CS 4620 Program 4: Ray II

Graphics for VEs. Ruth Aylett

CS 465 Program 5: Ray II

Accelerating Ray-Tracing

The Rasterization Pipeline

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

PantaRay: Fast Ray-traced Occlusion Caching of Massive Scenes J. Pantaleoni, L. Fascione, M. Hill, T. Aila

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

Level of Details in Computer Rendering

Recursion and Data Structures in Computer Graphics. Ray Tracing

Ray Tracing. CSCI 420 Computer Graphics Lecture 15. Ray Casting Shadow Rays Reflection and Transmission [Ch ]

Raycast Rendering Maya 2013

SEOUL NATIONAL UNIVERSITY

Lecture 11: Ray tracing (cont.)

History of computer graphics

Final Project: Real-Time Global Illumination with Radiance Regression Functions

Interactive Methods in Scientific Visualization

Comp 410/510 Computer Graphics. Spring Shading

Topics and things to know about them:

Practical Techniques for Ray Tracing in Games. Gareth Morgan (Imagination Technologies) Aras Pranckevičius (Unity Technologies) March, 2014

Radeon ProRender and Radeon Rays in a Gaming Rendering Workflow. Takahiro Harada, AMD 2017/3

Scalable multi-gpu cloud raytracing with OpenGL

Building a Fast Ray Tracer

Module Contact: Dr Stephen Laycock, CMP Copyright of the University of East Anglia Version 1

Introduction Ray tracing basics Advanced topics (shading) Advanced topics (geometry) Graphics 2010/2011, 4th quarter. Lecture 11: Ray tracing

Lecture 12: Advanced Rendering

COMP environment mapping Mar. 12, r = 2n(n v) v

Ray Tracing: Whence and Whither?

SAMPLING AND NOISE. Increasing the number of samples per pixel gives an anti-aliased image which better represents the actual scene.

Ray Casting. Outline in Code. Outline. Finding Ray Direction. Heckbert s Business Card Ray Tracer. Foundations of Computer Graphics (Fall 2012)

Review. Stephen J. Guy

Global Rendering. Ingela Nyström 1. Effects needed for realism. The Rendering Equation. Local vs global rendering. Light-material interaction

Other Rendering Techniques CSE 872 Fall Intro You have seen Scanline converter (+z-buffer) Painter s algorithm Radiosity CSE 872 Fall

Computer graphics and visualization

Transcription:

COMP 4801 Final Year Project Ray Tracing for Computer Graphics Final Project Report FYP 15014 by Runjing Liu Advised by Dr. L.Y. Wei 1

Abstract The goal of this project was to use ray tracing in a rendering engine to enhance real-time graphics. For many years real-time rendering has been realized with techniques using rasterization approaches. The ease of implementing rasterized rendering engine is promised by highly optimized graphics hardware. However, there are other alternative rendering methods. This paper introduces an approach that combines rasterization and ray tracing techniques to approximate reflection and refraction effect in real-time. 2

Table of Contents Table of Contents... 3 List of Figures... 4 1 Introduction... 5 2. Implementation... 6 2.1 Whitted ray tracing on CPU... 7 2.2 Vertex shader for ray casting... 9 2.3 Compute shader for ray-triangle intersection test... 12 Summary... 14 References... 16 3

List of Figures Figure 1 Images rendered by the ray tracer... 8 Figure 2 Unity's default rendering pipeline...10 Figure 3 Vertex shader applied to the floor...11 Figure 4 Vertex shader applied to the sphere...11 Figure 5 Timeline of CPU and GPU usage...14 Figure 6 Flow chart of the program...14 Figure 7 Thread allocation for a 1024x768 image...14 4

1 Introduction The benefit of ray tracing is that it can accurately simulate the transport of light and produce photorealistic images with very simple algorithms. The integration of ray tracing into a real-time game engine would be beneficial for adding specific image effects that would be difficult to produce by a rasterization renderer. This project was implemented on the Unity platform which has its own scene editor and rendering pipeline. The original rendering pipeline is based fully on rasterization. The scene editor manages 3D models with BSP tree for spatial partitioning. But for ray tracing, the spatial partitioning alone is not enough for raising the frame rate to an interactive level. Therefore, this projects also make use of the rasterization pipeline and shader programming to unearth the power of the GPU in accelerating ray tracing. 5

2. Implementation The implementation of this project was divided into three phases. In the first phase, a simple ray tracer that runs fully on the CPU is implemented. In the second phase, I utilized vertex shaders to replace ray casting with rasterization. In the third phase, DirectCompute shaders were brought into the program so that ray-triangle intersection test was performed on the GPU while the CPU remained responsible for ray casting and shading. 6

2.1 Whitted ray tracing on CPU The simple ray tracer follows the Whitted ray tracing algorithm (Whitted, 1980). It casts primary rays, shadow rays, reflective and refractive rays recursively. Local illumination is applied to the the ray casting hit points. Phong, Blinn Phong and simple diffuse shading models are implemented as options for surface shadings. A pixel color is calculated for each primary ray hit point on objects according to the following equation: Pixel color = (Diffuse + Specular) * Light intensity + Reflection/Refraction (1) This approach is very slow but produces fairly good images. On my personal laptop with average Intel core i7 processors, it takes about five minutes to render a frame with resolution of 1024 x 768. The scene has 73 meshes with 10590 triangle. The same scene is also used for testing in phase three. 7

Figure 1 Images rendered by the ray tracer 8

2.2 Vertex shader for ray casting In the ray tracing program implemented in phase one, although BSP tree is used by default in Unity to accelerate ray-object hit detection, the intersection tests still take a lot of time to run. This become a serious bottleneck of the program. One way to walk around the expensive intersection tests was to cast less rays into the scene. Therefore, in phase two the ray casting procedure is replaced with vertex shaders that return the texture colors of visible objects and construct secondary rays. By this means, the recursive level of the ray tracing process is decreased by 1. This methodology makes use of Unity s deferred rendering pipeline, as illustrated in figure 1. The program replaced the G-buffer contents in the deferred shading path with data to be used in later ray tracing. Since a vertex shader will only be applied when the vertex becomes visible to the camera, the visibility problem is solved easily with the vertex shader. Next, the G-buffer contents are passed to the ray tracer script to cast secondary rays and determine the shading of the vertex. The implementation of the vertex shader follows the deferred rendering pipeline. It reads the vertex data once and produce temporal results in multiple rendering targets (MRT). These rendering targets are typically frame buffers that could be read as 2D textures. The rendering buffers store diffuse color, world position and 9

reflection direction for the reflective surfaces in RGBA channels. The ray tracer script then decodes the colors into 32-bit float vectors and performs ray tracing. Figure 3 and Figure 4 show some results of the intermediate frame buffers and their final images. Figure 2 Unity's default rendering pipeline 10

Figure 3 Vertex shader applied to the floor Figure 4 Vertex shader applied to the sphere 11

2.3 Compute shader for ray-triangle intersection test The idea is a humble version of what Nathan Carr (2002) described in his paper as a ray engine. Since CPU intersection test is too slow, they are moved to be calculated on the GPU. The obstacle in implementation is that GPUs are not built for recursions whereas the ray tracing algorithm makes a fair amount of recursive calls. The good thing is that parallelism is easily supported by the GPU. This is non-trivial because the tracing of each ray is independent of each other. With shared memory containing the geometry data, the program could allocate one thread for each ray to finish the intersection calculation. However, there is a limitation on memory. The data shared by each thread is stored as textures and structured buffers. The limitation of memory is easily reached as the scene complexity grows, and could cause potential cease of the program. Another limitation is the IO speed between CPU and GPU. This now becomes the bottleneck that slows down the frame rate. Figure 5 shows the timeline of CPU and GPU usage when rendering a simple scene, where the peak appears during the transfer of data storage. The flow of the program is illustrated in figure 6 in charts. The compute shader is executed on the GPU on a fixed update every few frames. It gets mesh data and rays from the main program and returns the hit information for each pixel. 12

The DX11 compute shader I used for this project supports up a maximum of 1024 threads per group. The X and Y dimension of number of threads can be up to 1024. Say for a rendering target of 1024x768 pixels, the threads are allocated as in figure 7 so that each thread is responsible for the calculation of a pixel. Compared to the straightforward approach in phase 1, this method achieves averagely half of the rendering time needed for the same scene, without losing of image quality. Potential improvements to this method include constructing a spatial partition data structure such as BSP or BVH for the meshes passing to the GPU, as well as compressing the data buffers so that less bytes are needed for the IO between the CPU and the GPU. 13

Figure 5 Timeline of CPU and GPU usage Figure 6 Flow chart of the program Figure 7 Thread allocation for a 1024x768 image 14

Summary In this project, ray tracing is used to produce image effects such as reflection, refraction and simple shadows and illuminations. Apart from a simple ray tracer that follows the standard ray tracing algorithm, two approaches are implemented and presented in this report to accelerate the rendering. These two approaches can be combined or used separately, depending on the scene to be rendered. The vertex shader approach is more suitable for local ray traced reflections rather than the whole scene. The compute shader approach is more flexible so it can be adapted to various kind of ray tracing. The thing that needs to be taken care of is the supported GPU memory limit on different platforms. 15

References Carr, N. A. (2002). The ray engine. In Proceedings of the ACM SIGGRAPH/EUROGRAPHICS conference on Graphics hardware (pp. 37-46). Eurographics Association. Glassner, A. (1989). An introduction to ray tracing. Morgan Kaufmann. Pharr, M., & Humphreys, G. (2004). Physically based rendering: From theory to implementation. Morgan Kaufmann. Whitted, T. (1980). An improved illumination model for shaded display. Communications of the ACM, 23(6), pp. 343-349. 16