Lecture 1 - Introduction Welcome! , = (, ) , - - PowerPoint PPT Presentation

β–Ά
lecture 1 introduction
SMART_READER_LITE
LIVE PREVIEW

Lecture 1 - Introduction Welcome! , = (, ) , - - PowerPoint PPT Presentation

INFOMAGR Advanced Graphics Jacco Bikker - November 2019 - February 2020 Lecture 1 - Introduction Welcome! , = (, ) , + , , ,


slide-1
SLIDE 1

𝑱 π’š, π’šβ€² = 𝒉(π’š, π’šβ€²) 𝝑 π’š, π’šβ€² + ΰΆ±

𝑻

𝝇 π’š, π’šβ€², π’šβ€²β€² 𝑱 π’šβ€², π’šβ€²β€² π’†π’šβ€²β€²

INFOMAGR – Advanced Graphics

Jacco Bikker - November 2019 - February 2020

Lecture 1 - β€œIntroduction”

Welcome!

slide-2
SLIDE 2

Today’s Agenda:

β–ͺ Advanced Graphics β–ͺ Recap: Ray Tracing β–ͺ Lighthouse 2 β–ͺ Assignment 1

slide-3
SLIDE 3

Website

http://www.cs.uu.nl/docs/vakken/magr β–ͺ Site information overrules official schedule β–ͺ Downloads, news, slides, deadlines, links Please check regularly.

Discord

β–ͺ Please join!

INFOMAGR

Advanced Graphics – Introduction 9

slide-4
SLIDE 4

Abstract

In this course, we explore physically based rendering, with a focus on interactivity. At the end of this course, you will have a solid theoretical understanding of efficient physically based light transport. You will also have a good understanding of acceleration structures for fast ray/scene intersection for static and dynamic scenes. You will have hands-on experience with algorithms for efficient realistic rendering of static and dynamic scenes using ray tracing on CPU and GPU.

INFOMAGR

Advanced Graphics – Introduction 10

Concrete / informal:

  • 1. You’ll know how a photo-

realistic image is produced

  • 2. You know how to do this

quickly / efficient

  • 3. You have built such a renderer
  • 4. You have built an interactive

ray tracer

  • 5. You know how to do this on

the GPU

  • 6. You got a great score
  • 7. You had fun
slide-5
SLIDE 5

Topics

We will cover the following topics: β–ͺ Ray tracing fundamentals; β–ͺ Whitted-style ray tracing; β–ͺ Acceleration structure construction; β–ͺ Acceleration structure traversal; β–ͺ Data structures and algorithms for animation; β–ͺ Stochastic approaches to AA, DOF, soft shadows, … ; β–ͺ Path tracing; β–ͺ Variance reduction in path tracing algorithms; β–ͺ Filtering techniques; β–ͺ RTX, OptiX, Embree, RadeonRays; β–ͺ Various forms of parallelism in ray tracing.

INFOMAGR

Advanced Graphics – Introduction 11

slide-6
SLIDE 6

Lectures

~17 lectures: Tuesday 11:00 – 12:45, Thursday 13:15 – 15:00 ~7 working colleges: Thursday 15:15 – 17:00 Attendance is not mandatory, but of course highly recommended. We move fast; missing a key lecture may be a serious problem.

INFOMAGR

Advanced Graphics – Introduction 12

slide-7
SLIDE 7

Literature

Papers and online resources will be supplied during the course. Slides will be made available after each lecture. Recommended literature: Physically Based Rendering – From Theory to Implementation, Pharr & Humphreys. ISBN-10: 9780128006450. The 3rd edition is available for free: www.pbr-book.org

INFOMAGR

Advanced Graphics – Introduction 13

slide-8
SLIDE 8

Dependencies

It is assumed that you have basic knowledge of rendering (INFOGR) and associated mathematics. You also should be a decent programmer; this is explicitly not a purely theoretical course. You are expected to verify the theory and experience the good and the bad. A brief introduction to GPGPU and SIMD will be provided for those that did not take INFOMOV (pdfs will be available from the website).

INFOMAGR

Advanced Graphics – Introduction 14

slide-9
SLIDE 9

Resources

You will develop a ray tracing testbed for assignment 1. As a starting point, several β€˜templates’ are available: tmpl_2019_v2.zip

A basic C++ framework for graphics programming, which

  • pens a window, provides a 32-bit RGB framebuffer, and some

basic helper classes. A C# version is also available.

tmpl_OCL_2019.zip CUDATemplate2019.zip Tmpl_OCL_Csharp_2018.zip

Frameworks for GPGPU via CUDA and OpenCL.

Lighthouse 2

Open source experimentation framework for real-time ray tracing.

INFOMAGR

Advanced Graphics – Introduction 15

slide-10
SLIDE 10

Assignments

  • 1. (weight: 1):

Ray tracing framework or Lighthouse 2 core

For this assignment, you prepare a testbed for subsequent assignments.

  • 2. (weight: 1):

Acceleration structures

In this assignment, you expand your testbed with efficient acceleration structure construction and traversal. This enables you to run Whitted-style ray tracing in real-time.

  • 3. (weight: 2):

Final assignment

In this assignment, you either implement an interactive path tracer, or a rendering algorithm you chose, using CPU and/or GPU rendering.

INFOMAGR

Advanced Graphics – Introduction 16

slide-11
SLIDE 11

Exam

One final exam at the end of the block. Materials to study: β–ͺ Slides β–ͺ Notes taken during the lectures β–ͺ Provided literature β–ͺ Assignments

INFOMAGR

Advanced Graphics – Introduction 17

slide-12
SLIDE 12

Grading & Retake

Final grade for assignments 𝑄 = (𝑄1 + 𝑄2 + 2 βˆ— 𝑄3) / 4 Final grade for INFOMAGR 𝐻 = (2𝑄 + 𝐹) / 3 Passing criteria: β–ͺ 𝑄 β‰₯ 4.50 β–ͺ 𝐹 β‰₯ 4.50 β–ͺ 𝐻 β‰₯ 5.50 Repairing your grade using the retake exam or retake assignment: β–ͺ only if 5.50 > 𝐻 β‰₯ 4.00 β–ͺ you redo P1 or P2 or P3 or E β–ͺ this replaces the original P1, P2, P3 or E grade.

INFOMAGR

Advanced Graphics – Introduction 18

slide-13
SLIDE 13

Today’s Agenda:

β–ͺ Advanced Graphics β–ͺ Recap: Ray Tracing β–ͺ Lighthouse 2 β–ͺ Assignment 1

slide-14
SLIDE 14

Ray

A ray is an infinite line with a start point: 𝑄(𝑒) = 𝑃 + 𝑒𝐸, where 𝑒 β‰₯ 0. The ray direction 𝐸 is usually normalized: this way, 𝑒 becomes a distance along the ray.

Recap

Advanced Graphics – Introduction 20

slide-15
SLIDE 15

Scene

The scene consists of a number of primitives: β–ͺ Spheres β–ͺ Planes β–ͺ Triangles ...or anything for which we can calculate the intersection with a ray. We also need: β–ͺ A camera (position, direction, FOV, focal distance, aperture size) β–ͺ Light sources

Recap

Advanced Graphics – Introduction 21

slide-16
SLIDE 16

Recap

Ray Tracing

World space β–ͺ Geometry β–ͺ Eye β–ͺ Screen plane β–ͺ Screen pixels β–ͺ Primary rays β–ͺ Intersections β–ͺ Point light β–ͺ Shadow rays Light transport β–ͺ Extension rays Light transport Advanced Graphics – Introduction 22

slide-17
SLIDE 17

Ray setup

A ray is initially shot through a pixel on the screen plane. The screen plane is defined in world space, e.g.: Camera position: 𝐹 = (0,0,0) View direction: π‘Š = (0,0,1) Screen center: 𝐷 = 𝐹 + π‘’π‘Š Screen corners: 𝑄0 = 𝐷 + βˆ’1,1,0 , 𝑄

1 = 𝐷 + 1,1,0 , 𝑄2 = 𝐷 + (βˆ’1, βˆ’1,0)

From here: β–ͺ Change FOV by altering 𝑒; β–ͺ Transform camera by multiplying E, 𝑄0, 𝑄

1, 𝑄2 with the camera matrix.

Recap

Advanced Graphics – Introduction 23

slide-18
SLIDE 18

Ray setup

Point on the screen: 𝑄 𝑣, 𝑀 = 𝑄0 + 𝑣 𝑄

1 βˆ’ 𝑄0 + 𝑀(𝑄2 βˆ’ 𝑄0)

𝑣, 𝑀 ∈ [0,1] Ray direction (normalized): 𝐸 = 𝑄 𝑣, 𝑀 βˆ’ 𝐹 βˆ₯ 𝑄 𝑣, 𝑀 βˆ’ 𝐹 βˆ₯ Ray origin: 𝑃 = 𝐹

Recap

𝑄0 𝑄

1

𝑄2 𝐹 u v Advanced Graphics – Introduction 24

slide-19
SLIDE 19

Ray setup

Alternatives: β–ͺ Taking into account HMD lens distortion

Recap

Advanced Graphics – Introduction 25

slide-20
SLIDE 20

Recap

slide-21
SLIDE 21

Ray setup

Alternatives: β–ͺ Taking into account HMD lens distortion β–ͺ Fisheye lens

Recap

Advanced Graphics – Introduction 27

slide-22
SLIDE 22

Ray setup

Alternatives: β–ͺ Taking into account HMD lens distortion β–ͺ Fisheye lens β–ͺ Complex lens system

Recap

Advanced Graphics – Introduction 28

slide-23
SLIDE 23

Ray Intersection

Given a ray P(𝑒) = 𝑃 + 𝑒𝐸, we determine the closest intersection distance 𝑒 by intersecting the ray with each of the primitives in the scene. Ray / plane intersection: Plane: 𝑄 βˆ™ 𝑂 + 𝑒 = 0 Ray: 𝑄(𝑒) = 𝑃 + 𝑒𝐸 Substituting for 𝑄(𝑒), we get 𝑃 + 𝑒𝐸 βˆ™ 𝑂 + 𝑒 = 0 𝑒 = βˆ’(𝑃 βˆ™ 𝑂 + 𝑒)/(𝐸 βˆ™ 𝑂) 𝑄 = 𝑃 + 𝑒𝐸

Recap

𝑄0 𝑄

1

𝑄2 𝐹 Advanced Graphics – Introduction 29

Math reminder, dot product: 𝐡 βˆ™ 𝐢 = 𝐡𝑦𝐢𝑦 + 𝐡𝑧𝐢𝑧 + 𝐡𝑨𝐢𝑨 𝐡 βˆ™ 𝐢 = cos πœ„ 𝐡 βˆ™ 𝐢 is: the length of the projection of A on B. 𝐡 βˆ™ 𝐢 is a scalar Math notation: 𝑄 is a point, Τ¦ 𝑄 is a vector 𝑒 is a scalar.

slide-24
SLIDE 24

Ray Intersection

Ray / sphere intersection: Sphere: 𝑄 βˆ’ 𝐷 βˆ™ 𝑄 βˆ’ 𝐷 βˆ’ 𝑠2 = 0 Substituting for 𝑄(𝑒), we get 𝑃 + 𝑒𝐸 βˆ’ 𝐷 βˆ™ 𝑃 + 𝑒𝐸 βˆ’ 𝐷 βˆ’ 𝑠2 = 0 𝐸 βˆ™ 𝐸 𝑒2 + 2𝐸 βˆ™ 𝑃 βˆ’ 𝐷 𝑒 + (𝑃 βˆ’ 𝐷)2βˆ’π‘ 2 = 0 𝑏𝑒2 + 𝑐𝑒 + 𝑑 = 0 β†’ 𝑒 = βˆ’π‘ Β± 𝑐2 βˆ’ 4𝑏𝑑 2𝑏 𝑏 = 𝐸 βˆ™ 𝐸 𝑐 = 2𝐸 βˆ™ (𝑃 βˆ’ 𝐷) 𝑑 = 𝑃 βˆ’ 𝐷 βˆ™ 𝑃 βˆ’ 𝐷 βˆ’ 𝑠2

Recap

𝑄0 𝑄

1

𝑄2 𝐹 Negative: no intersections Advanced Graphics – Introduction 30

slide-25
SLIDE 25

Ray Intersection

Efficient ray / sphere intersection:

void Sphere::IntersectSphere( Ray ray ) { vec3 C = this.pos - ray.O; float t = dot( C, ray.D ); vec3 Q = C - t * ray.D; float p2 = dot( Q, Q ); if (p2 > sphere.r2) return; // r2 = r * r t -= sqrt( sphere.r2 – p2 ); if ((t < ray.t) && (t > 0)) ray.t = t; }

Note: This only works for rays that start outside the sphere.

Recap

Advanced Graphics – Introduction 31 O 𝐸 Τ¦ 𝐷 t 𝑅 π‘ž2

slide-26
SLIDE 26

Observations

Ray tracing is a point sampling process: β–ͺ we may miss small details; β–ͺ aliasing will occur. Ray tracing is a visibility algorithm: β–ͺ For each pixel, we find the nearest object (which occludes objects farther away).

Recap

Advanced Graphics – Introduction 32

slide-27
SLIDE 27

Observations

Note: rasterization (Painter’s or z-buffer) is also a visibility algorithm. Rasterization: β–ͺ loop over objects / primitives; β–ͺ per primitive: loop over pixels. Ray tracing: β–ͺ loop over pixels; β–ͺ per pixel: loop over objects / primitives.

Recap

Advanced Graphics – Introduction 33

slide-28
SLIDE 28

Today’s Agenda:

β–ͺ Advanced Graphics β–ͺ Recap: Ray Tracing β–ͺ Lighthouse 2 β–ͺ Assignment 1

slide-29
SLIDE 29

Lighthouse 2

Advanced Graphics – Introduction 35 Application β–ͺ Opens an OpenGL window β–ͺ Prepares the scene β–ͺ Handles user input β–ͺ Calls β€˜Render’ (several samples provided) RenderSystem β–ͺ Loads 3D scene data β–ͺ Owns & maintains the scene β–ͺ Handles animation β–ͺ Synchronizes scene data with a β€˜Core’ β–ͺ Invokes a β€˜Core’ API overview in: API βž”render_api.h You should not have to change anything in the RenderSystem. Core β–ͺ Receives raw triangle data from RenderSystem β–ͺ Performs actual rendering Several are available: β–ͺ Optix7, OptixPrime & Vulkan ray tracing cores; β–ͺ A software rasterizer.

slide-30
SLIDE 30

Lighthouse 2

Advanced Graphics – Introduction 36

Lighthouse 2

The Lighthouse 2 system has been designed to facilitate the development of rendering software based on ray tracing. The RenderSystem takes care of the boring things, such as model loading and scene management. You get to concentrate on the actual ray tracing. The current system needs a high-end NVIDIA device for pretty images. Without a recent GPU,

  • nly a software rasterizer fallback is available. This is where you come in.
slide-31
SLIDE 31

Lighthouse 2

Advanced Graphics – Introduction 37

RenderCore

A core implements the low-level rendering functionality. To build your own: start by copying an existing one. (project folder βž” docs βž” cloning a core.docx) A core receives raw geometry from the RenderSystem:

void RenderCore::SetGeometry( const int meshIdx, const float4* vertexData, const int vertexCount, const int triangleCount, const CoreTri* triangles, const uint* alphaFlags ) { }

No Note: The core is expected to copy the data it

  • receives. There is no guarantee at all

that the RenderSystem leaves the provided data intact after SetGeometry returns. float4: x, , y, z, z, pa padding also also co contain ver ertices. . raw verts ar are for

  • r in

intersection; tri tris ar are for

  • r sh

shading. Ren enderSystem mak akes Cor

  • reTris from Ho

HostTris, Cor

  • reMaterials for
  • rm Ho

HostMaterials an and so on.

  • n.
slide-32
SLIDE 32

Lighthouse 2

Advanced Graphics – Introduction 38

RenderCore

A core implements the low-level rendering functionality. A core receives instances from the RenderSystem:

void RenderCore::SetInstance( const int instanceIdx, const int meshIdx, const mat4& matrix ) { }

No Note: β–ͺ A mesh that is not instanced is not visible. β–ͺ SetInstance always receives a flattened list of instances; there is no hierarchy.

slide-33
SLIDE 33

Lighthouse 2

Advanced Graphics – Introduction 39

RenderCore

A core implements the low-level rendering functionality. A core receives a Render command from the RenderSystem:

void RenderCore::Render( const ViewPyramid& view, const Convergence converge, const float brightness, const float contrast ) { }

No Note: β–ͺ Feel free to ignore brightness and contrast for now. β–ͺ Converge will be true when the camera is

  • stationary. This will be useful later for

path tracing.

slide-34
SLIDE 34

Lighthouse 2

Advanced Graphics – Introduction 40

void Init(); CoreStats GetCoreStats(); void SetProbePos( int2 pos ); void SetTarget( GLTexture* target, uint spp ); void Setting( char* name, float value ); void Render( ViewPyramid& view, Convergence converge, float brightness, float contrast ); void Shutdown(); void SetTextures( CoreTexDesc* tex, int textureCount ); void SetMaterials( CoreMaterial* mat, CoreMaterialEx* matEx, int materialCount ); void SetLights( CoreLightTri* areaLights, int areaLightCount, CorePointLight* pointLights, int pointLightCount, CoreSpotLight* spotLights, int spotLightCount, CoreDirectionalLight* directionalLights, int directionalLightCount ); void SetSkyData( float3* pixels, uint width, uint height ); void SetGeometry( int meshIdx, float4* vertexData, int vertexCount, int triangleCount, CoreTri* triangles, uint* alphaFlags = 0 ); void SetInstance( int instanceIdx, int modelIdx, mat4& transform ); void UpdateToplevel();

slide-35
SLIDE 35

Today’s Agenda:

β–ͺ Advanced Graphics β–ͺ Recap: Ray Tracing β–ͺ Lighthouse 2 β–ͺ Assignment 1

slide-36
SLIDE 36

Ray Tracing Testbed, Option #1: Create a Core

Implement a simple ray tracing core based on the software rasterizer. Ingredients:

SetGeometry: Copy the data, either vertices and triangles or just the triangles. SetInstance: Make sure your geometry has an identity matrix, easier for now. Ignore textures and materials for now; you don’t need this for a simple render. Render: The render method loops over the pixels: Initialize a primary ray Intersect the ray with each triangle to find the closest intersection Visualize the closest intersection (e.g. a greyscale β€˜distance’) From here you can flesh out the other functionality.

Advanced Graphics – Introduction 42

Assignment 1

slide-37
SLIDE 37

Ray Tracing Testbed, Option #2: Rolling Your Own

Implement an experimentation framework for ray tracing. Ingredients:

Scene

Primitives: spheres, planes, triangles I/O (e.g., obj loader) Intersection Materials: diffuse color, diffuse / specular / dielectric, absorption

Camera

Position, target, FOV Ray generation

Ray Renderer

Whitted-style

User interface

Input handling Presentation

Advanced Graphics – Introduction 43

Assignment 1

slide-38
SLIDE 38

Ray Tracing Testbed, Option #2: Rolling Your Own

Regarding the file loading requirement: β–ͺ You may want to start with handcrafted scenes β–ͺ Don’t build your own OBJ loader, that’s a waste of time β–ͺ Use assimp or tinyobjloader (C++) or find a lib if you’re using C#

http://www.stefangordon.com/parsing-wavefront-obj-files-in-c/ http://www.rexcardan.com/2014/10/read-obj-file-in-c-in-just-10-lines-of-code/ https://github.com/ChrisJansson/ObjLoader

β–ͺ Start with small files; minimize your development cycle. Advanced Graphics – Introduction 44

Assignment 1

slide-39
SLIDE 39

Ray Tracing Testbed, Option #1 and #2

Intersecting triangles: An easy to implement and quite efficient algorithm is: Fast, Minimum Storage Ray/Triangle Intersection, MΓΆller & Trumbore, 1997. …which is explained in elaborate detail by scratchapixel.com:

http://www.scratchapixel.com/lessons/3d-basic-rendering/ray-tracing-rendering-a-triangle/moller-trumbore-ray- triangle-intersection

Advanced Graphics – Introduction 45

Assignment 1

slide-40
SLIDE 40

Today’s Agenda:

β–ͺ Advanced Graphics β–ͺ Recap: Ray Tracing β–ͺ Lighthouse 2 β–ͺ Assignment 1

slide-41
SLIDE 41

INFOMAGR – Advanced Graphics

Jacco Bikker - November 2019 – February 2020

END of β€œIntroduction”

next lecture: β€œWhitted-style Ray Tracing”