---
title: 【Unite Tokyo 2019】Unityでレイトレーシングしよう！レイトレーシング実装と最適化の解説
tags:  #unite #unity #unitetokyo #unite tokyo 2019  
author: [Unity Technologies Japan](https://www.docswell.com/user/UnityJapan)
site: [Docswell](https://www.docswell.com/)
thumbnail: https://bcdn.docswell.com/page/63EK3PPRED.jpg?width=480
description: 2019/9/25-6に開催されたUnite Tokyo 2019の講演スライドです。 パウロ シルバ（エヌビディア）  こんな人におすすめ ・Unityでレイトレーシングをやってみたい人、もしくは、やってみたけどうまくいかなかった人 ・Unityを使って美しいレンダリングをしてみたい人  受講者が得られる知見 ・Unityのレイトレーシング機能に関する基本的な理解 ・Unityのレイトレーシング機能の効果的な使い方と最適化の方法  Unityのイベント資料はこちらから： https://www.slideshare.net/UnityTechnologiesJapan/clipboards
published: September 26, 19
canonical: https://www.docswell.com/s/UnityJapan/ZNXG7K-unite-tokyo-2019unity-176172017
---
# Page. 1

![Page Image](https://bcdn.docswell.com/page/63EK3PPRED.jpg)



# Page. 2

![Page Image](https://bcdn.docswell.com/page/4L73GXXGE5.jpg)

Real-Time Ray Tracing
Paulo Silva
Developer Technology Engineer, NVIDIA


# Page. 3

![Page Image](https://bcdn.docswell.com/page/V87D122NEG.jpg)

Announcements
•
Target Audience:
•
•
Level:
•
•
•
Engineers &amp; Technical Artists
Beginner (no programming)
Intermediate (some programming)
Warning:
•
This is Beta software and is still changing
•
Slides will be available
•
Session recording will also be available
3


# Page. 4

![Page Image](https://bcdn.docswell.com/page/4VJPQ11NE8.jpg)

Outline
•
History Of Ray-Tracing
•
Rasterization vs Ray-Tracing
•
Basic Example
•
Scriptable Pipelines &amp; DXR Details
•
Performance Advice
•
More Resources
4


# Page. 5

![Page Image](https://bcdn.docswell.com/page/L2EV5YYYEQ.jpg)

History of Ray-Tracing
5


# Page. 6

![Page Image](https://bcdn.docswell.com/page/Z57G699WJL.jpg)

What is Ray-Tracing?
•
Rendering method
•
Simulates light path
•
Most modern movies use it for SFX
•
Photo-realistic rendering
•
Car &amp; Architecture visualization
6
Rendered in unity using real-time ray tracing


# Page. 7

![Page Image](https://bcdn.docswell.com/page/V4EQ4WWQ7P.jpg)

History
•
Whitted 1980
•
Cook 1984
•
Kajiya 1986
•
Shiny
•
Fuzzy
•
Path Tracing
•
Reflections
•
Motion Blur
•
Rendering Equation
•
Refractions
•
Soft Shadows
•
Diffuse Interreflections
•
Shadows
•
Caustics
7


# Page. 8

![Page Image](https://bcdn.docswell.com/page/DKJ4QKKY71.jpg)

History
•
Whitted 1980
•
Cook 1984
•
8
Kajiya 1986


# Page. 9

![Page Image](https://bcdn.docswell.com/page/PLE1PXXN7G.jpg)

Rasterization vs Ray-Tracing
9


# Page. 10

![Page Image](https://bcdn.docswell.com/page/8GEW2NKMJ2.jpg)

Rasterization: Very Simplified
Vertex Shader
Rasterizer
10
Pixel Shader


# Page. 11

![Page Image](https://bcdn.docswell.com/page/W47ZD3ZME3.jpg)

Ray-Tracing: Very Simplified
Trace Rays
Intersection Test
11
Shade &amp; Trace


# Page. 12

![Page Image](https://bcdn.docswell.com/page/KYJ61XZ5EV.jpg)

Rasterization vs Ray-Tracing: Key Ideas
Rasterizer
Ray Tracing
Question
Which pixel □ does triangle △ cover?
Which triangles △ does pixel □ see?
Operation
Pixel □ in triangle △
Ray → triangle △ intersection
Streaming
Triangles △
Rays →
Inefficiency Overdraw △
Many → collisions
Speedups
Bounding volume hierarchy BVH (AABBs)
(Hierarchical) Z-buffering
12


# Page. 13

![Page Image](https://bcdn.docswell.com/page/5GJ54XWG74.jpg)

Rasterization: Hacks
SSAO
Shadow Maps
SSR
13


# Page. 14

![Page Image](https://bcdn.docswell.com/page/4LE3GX4PJ5.jpg)

Rasterization vs Ray-Tracing: AO
SSAO
Ray-Tracing AO
14


# Page. 15

![Page Image](https://bcdn.docswell.com/page/V8ED12Q3JG.jpg)

Rasterization vs Ray-Tracing: Shadows
Shadow Maps (No baked light maps)
Ray-Tracing Shadows
15


# Page. 16

![Page Image](https://bcdn.docswell.com/page/4V7PQ1LPJ8.jpg)

Rasterization vs Ray-Tracing: Reflections #1
SSR
Ray-Tracing Reflections
16


# Page. 17

![Page Image](https://bcdn.docswell.com/page/L2JV5YQVJQ.jpg)

Rasterization vs Ray-Tracing: Reflections #2
SSR
Ray-Tracing Reflections
17


# Page. 18

![Page Image](https://bcdn.docswell.com/page/Z5EG69W17L.jpg)

Basic Example
18


# Page. 19

![Page Image](https://bcdn.docswell.com/page/V4JQ4W3NEP.jpg)

Basic Example
•
No programming needed
•
Setup needed to get started
•
Shows off the main features
•
•
•
•
•
Reflections
Shadows
Ambient Occlusion
Global Illumination
Compare to Rasterization
Cornell Box
19


# Page. 20

![Page Image](https://bcdn.docswell.com/page/DK74QK13E1.jpg)

System Requirements
•
RTX GPU for complex Ray Tracing Effects*
•
Windows 10 v1809
•
Unity 2019.3b1
20


# Page. 21

![Page Image](https://bcdn.docswell.com/page/PLJ1PXGZEG.jpg)

Setup
•
In Player settings set:
•
•
•
DirectX12 (Experimental)
REALTIME_RAYTRACING_SUPPORT
ENABLE_RAYTRACING
21


# Page. 22

![Page Image](https://bcdn.docswell.com/page/8GJW2NK672.jpg)

Basic Demo Scene
•
Let’s create a Cornell Box
22


# Page. 23

![Page Image](https://bcdn.docswell.com/page/W4EZD3ZRJ3.jpg)

Basic Demo: Add Ray Tracing
•
Add the Raytracing Environment
23


# Page. 24

![Page Image](https://bcdn.docswell.com/page/KY761XZ1JV.jpg)

Basic Demo: Reflections
After
Before
24


# Page. 25

![Page Image](https://bcdn.docswell.com/page/5G754XWLE4.jpg)

Basic Demo – Shadows
After
Before
25


# Page. 26

![Page Image](https://bcdn.docswell.com/page/V9J2VXQ3JR.jpg)

Basic Demo – Indirect Illumination
After
Before
26


# Page. 27

![Page Image](https://bcdn.docswell.com/page/5DEY38W87M.jpg)

Basic Demo: Raster vs Ray Tracing
Ray-Tracing
Raster (no baked lights)
27


# Page. 28

![Page Image](https://bcdn.docswell.com/page/2VJNVQ9978.jpg)

Scriptable Pipelines &amp; DXR Details
28


# Page. 29

![Page Image](https://bcdn.docswell.com/page/GYE96D23E3.jpg)

Scriptable Pipelines &amp; DXR Details
Required for next section:
•
DXR shader types
•
Acceleration structures
What is DXR?
•
DXR = D3D12 ray tracing
•
HDRP uses Scriptable Pipelines
•
These use DXR ray tracing
DXR shaders in HDRP
29


# Page. 30

![Page Image](https://bcdn.docswell.com/page/5GE8Z35L7D.jpg)

DXR Shaders
•
Ray Generation
•
•
Closest-hit
•
•
e.g.: sample skybox
Any-hit
•
•
e.g.: calculate color
Miss shader
•
•
defines how rays start
run once per hit for transparency
Intersection
•
Intersect arbitrary shapes
DXR Shader Graph
30


# Page. 31

![Page Image](https://bcdn.docswell.com/page/MLELDVYQ7R.jpg)

DXR Acceleration Structures
Acceleration Structure
Bounding Boxes are Axis Aligned (AABB)
34


# Page. 32

![Page Image](https://bcdn.docswell.com/page/54JMPGDKJW.jpg)

Performance Advice
35


# Page. 33

![Page Image](https://bcdn.docswell.com/page/ZPJR1Z46J9.jpg)

Performance Advice - Reflections
Smooth – Coherent Rays
Rough – Rays Diverge
•
•
Smooth reflective surfaces are cheaper than rough surfaces
Keep shaders simple when using rough surfaces
36


# Page. 34

![Page Image](https://bcdn.docswell.com/page/NPEXY92D7X.jpg)

Performance Advice -Transparency
Opaque – No Any-Hit call
Transparent – many Any-Hits calls
•
•
Keep Any-Hit shaders simple
When possible make objects opaque (Use LOD)
37


# Page. 35

![Page Image](https://bcdn.docswell.com/page/63EK3PMDED.jpg)

Performance Advice – Acceleration Structures
Static Object
•
Dynamic Rigid Body
Correctly tag objects as static, dynamic, animated
38
Animated Character


# Page. 36

![Page Image](https://bcdn.docswell.com/page/4L73GXYPE5.jpg)

Performance Advice – Acceleration Structures
AS
AS
AS
AS
One Object ☺
Separate Objects ☹
•
Group geometry together when possible
39


# Page. 37

![Page Image](https://bcdn.docswell.com/page/V87D1253EG.jpg)

Performance Advice
Performance
Quality
Ray Count
Ray Length
Denoiser Quality
Small Transparent Objects
40


# Page. 38

![Page Image](https://bcdn.docswell.com/page/4VJPQ1GPE8.jpg)

More Resources
43


# Page. 39

![Page Image](https://bcdn.docswell.com/page/L2EV5Y6VEQ.jpg)

More Resources
•
Ray-Tracing Gems (free pdf):
http://www.realtimerendering.com/raytracinggems/
•
SIGGRAPH 2018 DXR Tutorial:
http://intro-to-dxr.cwyman.org/
•
Gameworks Ray-Tracing:
https://developer.nvidia.com/gameworks-ray-tracing
•
DXR Specification:
https://microsoft.github.io/DirectX-Specs/d3d/Raytracing.html
•
Unity HDRP DXR Build:
get 2019.3b1 from unity hub, or download the following version
https://github.com/Unity-Technologies/Unity-Experimental-DXR
44


# Page. 40

![Page Image](https://bcdn.docswell.com/page/Z57G69N1JL.jpg)

Please try real-time ray tracing
and make something amazing!
Thank You
45


