π± π, πβ² = π(π, πβ²) π π, πβ² +
π»
π π, πβ², πβ²β² π± πβ², πβ²β² ππβ²β²
INFOMAGR β Advanced Graphics
Jacco Bikker - November 2016 - February 2017
Lecture 1 - Introduction Welcome! , = (, ) , - - PowerPoint PPT Presentation
INFOMAGR Advanced Graphics Jacco Bikker - November 2016 - February 2017 Lecture 1 - Introduction Welcome! , = (, ) , + , , ,
π± π, πβ² = π(π, πβ²) π π, πβ² +
π»
π π, πβ², πβ²β² π± πβ², πβ²β² ππβ²β²
Jacco Bikker - November 2016 - February 2017
Website
http://www.cs.uu.nl/docs/vakken/magr
Please check regularly.
Advanced Graphics β Introduction 3
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.
Advanced Graphics β Introduction 4
Concrete / informal:
realistic image is produced
quickly / efficient
ray tracer
the GPU
Topics
We will cover the following topics:
Advanced Graphics β Introduction 5
Lectures
~13 lectures: Tuesday 11:00 β 12:45, Thursday 13:15 β 15:00 ~7 working colleges: Thursday 15:15 β 17:00 (starting week 2) Attendance is not mandatory, but of course highly recommended. We move fast; missing a key lecture may be a serious problem.
Advanced Graphics β Introduction 6
Literature
Papers and online resources will be supplied during the course. Slides will be made available after each lecture. Recommended literature: Physically Based Rendering, Second Edition β From Theory to Implementation, Pharr & Humphreys. Morgan Kaufmann, 2010. ISBN-10: 0123750792. Recently, the Third Edition was released.
Advanced Graphics β Introduction 7
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.
Advanced Graphics β Introduction 8
Resources
You will develop a ray tracing testbed for assignment 1. As a starting point, several βtemplatesβ are available: Tmpl85.00a
A basic C++ framework for graphics programming, which
basic helper classes.
gpu_lab (available halfway the course)
A basic C++ framework for GPGPU via CUDA and OpenCL.
Template_C#
A basic C# template which uses OpenTK to provide a 32-bit RGB framebuffer as well as OpenGL functionality, and Cloo for using OpenCL.
Advanced Graphics β Introduction 9
Assignments
Ray tracing framework
For this assignment, you prepare a testbed for subsequent assignments.
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.
Final assignment
In this assignment, you either implement an interactive path tracer, or a rendering algorithm you chose, using CPU and/or GPU rendering.
Advanced Graphics β Introduction 10
Exam
One final exam at the end of the block. Materials to study:
Advanced Graphics β Introduction 11
Grading & Retake
Final grade for assignments π = (π1 + π2 + 2 β π3) / 4 Final grade for INFOMAGR π» = (2π + πΉ) / 3 Passing criteria:
Repairing your grade using the retake exam or retake assignment:
Advanced Graphics β Introduction 12
Ray
A ray is an infinite line with a start point: π(π’) = π + π’πΈ, where π’ > 0. The ray direction πΈ is usually normalized.
Advanced Graphics β Introduction 14
Scene
The scene consists of a number of primitives:
..or anything for which we can calculate the intersection with a ray. We also need:
Advanced Graphics β Introduction 15
Ray Tracing
World space
Light transport
Light transport Advanced Graphics β Introduction 16
Ray setup
A ray is initially shot through a pixel on the screen plane. The screen plane is defined in world space: Camera position: E = (0,0,0) View direction: π Screen center: C = πΉ + ππ Screen corners: p0 = π· + β1, β1,0 , π1 = π· + 1, β1,0 , π2 = π· + (β1,1,0) From here:
Advanced Graphics β Introduction 17
Ray setup
Point on the screen: π π£, π€ = π0 + π£ π1 β π0 + π€(π2 β π0) π£, π€ β [0,1] Ray direction (normalized): πΈ = π π£, π€ β πΉ β₯ π π£, π€ β πΉ β₯ Ray origin: π = πΉ
π0 π1 π2 πΉ u v Advanced Graphics β Introduction 18
Ray Intersection
Given a ray π(π’) = π + π’πΈ, 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 π’ = β(π β π + π)/(πΈ β π) π = π + π’πΈ
π0 π1 π2 πΉ Advanced Graphics β Introduction 19
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
π0 π1 π2 πΉ Negative: no intersections Advanced Graphics β Introduction 20
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; // or: ray.t = min( ray.t, max( 0, t ) ); }
Note: This only works for rays that start outside the sphere.
Advanced Graphics β Introduction 21 O πΈ π t π π2
Observations
Ray tracing is a point sampling process:
Ray tracing is a visibility algorithm:
Advanced Graphics β Introduction 22
Observations
Note: Rasterization (Painterβs or z-buffer) is also a visibility algorithm. Rasterization:
Ray tracing:
Advanced Graphics β Introduction 23
An Improved Illumination Model for Shaded Display
In 1980, βState of the Artβ consisted of:
not taking into account fall-off (Phong)
Goal:
Improved model:
** : Williams, L. 1978. Casting curved shadows on curved surfaces. In Computer Graphics (Proceedings of SIGGRAPH 78), vol. 12, 270β274. * : Blinn, J. and Newell, M. 1976. Texture and Reflection in Computer Generated Images. Communications of the ACM 19:10 (1976), 542β547.
Advanced Graphics β Introduction 25
An Improved Illumination Model for Shaded Display*
Physical basis of Whitted-style ray tracing: Light paths are generated (backwards) from the camera to the light sources, using rays to simulate optics.
Color Trace( ray r ) I, N, mat = NearestIntersection( scene, r ) return mat.color * DirectIllumination( I, N )
* : T. Whitted. An Improved Illumination Model for Shaded Display.
Advanced Graphics β Introduction 26
An Improved Illumination Model for Shaded Display
Color Trace( ray r ) I, π, mat = NearestIntersection( scene, r ) return mat.color * DirectIllumination( I, π )
Direct illumination: Summed contribution of unoccluded point light sources, taking into account:
Note that this requires a ray per light source.
Advanced Graphics β Introduction 27
An Improved Illumination Model for Shaded Display
Color Trace( ray r ) I, π, mat = NearestIntersection( scene, r ) if (mat == DIFFUSE) return mat.color * DirectIllumination( I, π ) if (mat == MIRROR) return mat.color * Trace( I, reflect( r.πΈ, π )
Indirect illumination: For perfect specular object (mirrors) we extend the primary ray with an extension ray:
Advanced Graphics β Introduction 28
Reflection
Given a ray direction πΈ and a normalized surface normal π, the reflected vector π = πΈ β 2(πΈ β π)π. Derivation: π€ = π(πΈ β π) π£ = πΈ β π€ π = π£ + (β π€) π = πΈ β π πΈ β π β π(πΈ β π) π = πΈ β 2(πΈ β π)π
π πΈ πΆ π€ π£ Advanced Graphics β Introduction 29
Question 1: For direct illumination, we take into account:
Why? Question 2: We use the summed contribution of all light sources. Is this correct? Question 3: Why do we not sample the light sources for a pure specular surface? (can you cast a shadow on a bathroom mirror?) Question 4: Why do we not apply π β π to reflections? Question 5: Prove geometrically that, for normalized vectors πΈ and π, π = πΈ β 2 πΈ β π π yields a normalized vector.
Advanced Graphics β Introduction 30
An Improved Illumination Model for Shaded Display
Handling partially reflective materials:
Color Trace( ray r ) I, π, mat = NearestIntersection( scene, r ) s = mat.specularity d = 1 β mat.specularity return mat.color * ( s * Trace( I, reflect( r.πΈ, π ) d * DirectIllumination( I, π )
Note: this is not efficient. (why not?)
Advanced Graphics β Introduction 31
An Improved Illumination Model for Shaded Display
Dielectrics
Color Trace( ray r ) I, π, mat = NearestIntersection( scene, r ) if (mat == DIFFUSE) return mat.color * DirectIllumination( I, π ) if (mat == MIRROR) return mat.color * Trace( I, reflect( r.πΈ, π ) if (mat == GLASS) return mat.color * ?
Advanced Graphics β Introduction 32
Dielectrics
The direction of the transmitted vector π depends on the refraction indices π1, π2 of the media separated by the surface. According to Snellβs Law: π1π‘πππ1 = π2π‘πππ2
π1 π2 π‘πππ1 = π‘πππ2 Note: left term may exceed 1, in which case π2 cannot be computed. Therefore:
π1 π2 π‘πππ1 = π‘πππ2 βΊ π‘πππ1 β€ π2 π1 ο¨ πππ ππ’ππππ = arcsin π2 π1 sin π2
π πΈ πΆ π1 π2 π2 π1 Advanced Graphics β Introduction 33
Dielectrics
π1 π2 π‘πππ1 = π‘πππ2 βΊ π‘πππ1 β€ π2 π1
π = 1 β π1 π2
2
1 β πππ‘π1
2
π = ππ½π, πππ π < 0 π1 π2 πΈ + π π1 π2 πππ‘π1 β π , πππ π β₯ 0 Note: πππ‘π1 = π β βπΈ, and π1
π2 should be calculated only once.
* For a full derivation, see http://www.flipcode.com/archives/reflection_transmission.pdf
π πΈ πΆ π1 π2 π2 π1 Advanced Graphics β Introduction 34
Dielectrics
A typical dielectric transmits and reflects light.
π πΈ πΆ π Advanced Graphics β Introduction 35
Dielectrics
A typical dielectric transmits and reflects light. Based on the Fresnel equations, the reflectivity of the surface for non-polarized light is formulated as: πΊ
π = 1
2 π1πππ‘ππ β π2 1 β π1 π2 π‘ππππ
2
π1πππ‘ππ + π2 1 β π1 π2 π‘ππππ
2 2
+ π1 1 β π1 π2 π‘ππππ
2
β π2 cos ππ π1 1 β π1 π2 π‘ππππ
2
+ π2 cos ππ
2
Advanced Graphics β Introduction 36
Reflectance for s-polarized light Reflectance for p-polarized light Reflectance for unpolarized light
Dielectrics
In practice, we use Schlickβs approximation: πΊ
π = π0 + (1 β π0)(1 β πππ‘π)5, where π0 = π1βπ2 π1+π2 2
. Based on the law of conservation of energy: πΊπ’ = 1 β πΊ
π
* An Inexpensive BRDF model for Physically-based Rendering, Schlick, Computer Graphics Forum 13, 1994.
π πΈ πΆ π Advanced Graphics β Introduction 37
Ray Tracing
World space
Light transport
Light transport Advanced Graphics β Introduction 38
Ray Tree
Using Whitted-style ray tracing, hitting a surface point may spawn:
The reflected and transmitted rays may hit another object with the same material. ο¨ A single primary ray may lead to a very large number of ray queries. Advanced Graphics β Introduction 39
Question 6: imagine a scene with several point lights and dielectric materials. Considering the law of conservation of energy, what can you say about the energy transported by each individual ray? Advanced Graphics β Introduction 40
Beerβs Law
Advanced Graphics β Introduction 41
Beerβs Law
Light travelling through a medium loses intensity due to absorption. The intensity π½(π‘) that remains after travelling π‘ units through a substance with absorption π is: π½ π‘ = π½ 0 πβ ln π π‘ In pseudocode:
I.r *= expf( -a.r * s ); I.g *= expf( -a.g * s ); I.b *= expf( -a.b * s );
Advanced Graphics β Introduction 42
Whitted - Summary
A Whitted-style ray tracer implements the following optical phenomena:
Visibility Distance attenuation A shading model: N dot L for diffuse
The ray tracer supports any primitive for which a ray/primitive intersection can be determined. Advanced Graphics β Introduction 43
Ray Tracing Testbed
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 45
Ray Tracing Testbed
Regarding the OBJ file loading requirement:
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
Advanced Graphics β Introduction 46
Ray Tracing Testbed
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 47
Jacco Bikker - November 2016 β February 2017
next lecture: βAcceleration Structuresβ