π± π, πβ² = π(π, πβ²) π π, πβ² + ΰΆ±
π»
π π, πβ², πβ²β² π± πβ², πβ²β² ππβ²β²
INFOMAGR β Advanced Graphics
Jacco Bikker - November 2019 - February 2020
Lecture 2 - Whitted Welcome! , = (, ) , - - PowerPoint PPT Presentation
INFOMAGR Advanced Graphics Jacco Bikker - November 2019 - February 2020 Lecture 2 - Whitted Welcome! , = (, ) , + , , ,
π± π, πβ² = π(π, πβ²) π π, πβ² + ΰΆ±
π»
π π, πβ², πβ²β² π± πβ², πβ²β² ππβ²β²
Jacco Bikker - November 2019 - February 2020
βͺ Introduction: Appel βͺ Whitted βͺ Cook βͺ Assignment 1
Some Techniques for Shading Machine Renderings of Solids, Arthur Appel, 1964.
Idea: use rays to find geometry and shadows.
Advanced Graphics β Whitted 3
Recap
Advanced Graphics β Whitted 4 π0 π
1
π2 πΉ u v Plane: π β π + π = 0 Ray: π(π’) = π + π’πΈ Substituting for π(π’), we get π + π’πΈ β π + π = 0 π’ = β(π β π + π)/(πΈ β π) π = π + π’πΈ
Advanced Graphics β Whitted 5 Ray: π(π’) = π + π’πΈ
Advanced Graphics β Whitted 6
βͺ Introduction: Appel βͺ Whitted βͺ Cook βͺ Assignment 1
An Improved Illumination Model for Shaded Display
In 1980, βState of the Artβ consisted of: βͺ Rasterization βͺ Shading: either diffuse (N Β· L) or specular ((N Β· H)n), both not taking into account fall-off (Phong) βͺ Reflection, using environment maps (Blinn & Newell *) βͺ Stencil shadows (Williams **)
** : Williams, L. 1978. Casting curved shadows on curved surfaces.. * : Blinn, J. and Newell, M. 1976. Texture and Reflection in Computer Generated Images.
Advanced Graphics β Whitted 8
An Improved Illumination Model for Shaded Display
In 1980, βState of the Artβ consisted of: βͺ Rasterization βͺ Shading: either diffuse (N Β· L) or specular ((N Β· H)n), both not taking into account fall-off (Phong) βͺ Reflection, using environment maps (Blinn & Newell) βͺ Stencil shadows (Williams) Goal: βͺ Solve reflection and refraction Improved model: βͺ Based on classical ray optics
Advanced Graphics β Whitted 9
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 β Whitted 10
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: βͺ Distance to I βͺ Angle between π and π βͺ Intensity of light source Note that this requires a ray per light source.
Advanced Graphics β Whitted 11
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: βͺ We still modulate transport with the material color βͺ We do not apply π β π βͺ We do not calculate direct illumination
Advanced Graphics β Whitted 12
Reflection
Given a ray direction πΈ and a normalized surface normal π, the reflected vector π = πΈ β 2(πΈ β π)π. Derivation: π = π(πΈ β π) π = πΈ β Τ¦ π€ π = π + (βπ) π = πΈ β π πΈ β π β π(πΈ β π) π = πΈ β 2(πΈ β π)π
π πΈ πΆ π π Advanced Graphics β Whitted 13
Question 1: For direct illumination, we take into account: βͺ Material color βͺ Distance to light source βͺ π β π 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: Prove geometrically that, for normalized vectors πΈ and π, π = πΈ β 2 πΈ β π π yields a normalized vector.
Advanced Graphics β Whitted 14
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( ray( I, reflect( r.πΈ, π ) ) ) + d * DirectIllumination( I, π ) )
Note: this is not efficient. (why not?)
Advanced Graphics β Whitted 15
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 β Whitted 16
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 β Whitted 17
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 β Whitted 18
Dielectrics
A typical dielectric transmits and reflects light.
π πΈ πΆ π Advanced Graphics β Whitted 19
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 cos ππ’ π1πππ‘ππ + π2 cos ππ’
2
+ π1 cos ππ’ β π2 cos ππ π1 cos ππ’ + π2 cos ππ
2 Where: cos ππ’ = 1 β
π1 π2 sin ππ 2
Advanced Graphics β Whitted 20
Reflectance for s-polarized light Reflectance for p-polarized light Reflectance for unpolarized light
Dielectrics
πΊ
π = β―
Based on the law of conservation of energy: πΊπ’ = 1 β πΊ
π
π πΈ πΆ π Advanced Graphics β Whitted 21
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 β Whitted 22
Ray Tree
Using Whitted-style ray tracing, hitting a surface point may spawn: βͺ a shadow ray for each light source; βͺ a reflection ray; βͺ a ray transmitted into the material. 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 β Whitted 23
Question 5: 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 β Whitted 24
Beerβs Law
Advanced Graphics β Whitted 25
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 *= exp( -a.r * d ); I.g *= exp( -a.g * d ); I.b *= exp( -a.b * d );
Advanced Graphics β Whitted 26
Whitted - Summary
A Whitted-style ray tracer implements the following optical phenomena: βͺ Direct illumination of multiple light sources, taking into account
Visibility Distance attenuation A shading model: N dot L for diffuse
βͺ Pure specular reflections, with recursion βͺ Dielectrics, with Fresnel, with recursion βͺ Beerβs Law The ray tracer supports any primitive for which a ray/primitive intersection can be determined. Advanced Graphics β Whitted 27
βͺ Introduction: Appel βͺ Whitted βͺ Cook βͺ Assignment 1
βDistributed Ray Tracingβ
Whitted-style ray tracing does not handle glossy reflections, depth of field, motion blur. Advanced Graphics β Whitted 29
βDistributed Ray Tracingβ
Whitted-style ray tracing does not handle glossy reflections, depth of field, motion blur: Ray tracing is a point sampling process. Cook et al.*: Replace point sampling by integrals: βͺ Perform anti-aliasing by integrating over the pixel βͺ Add motion blur by integrating over time βͺ Calculate depth of field by integrating over the aperture. Advanced Graphics β Whitted 30
* : Cook et al., 1984. Distributed Ray Tracing.
βͺ Introduction: Appel βͺ Whitted βͺ Cook βͺ Assignment 1
Adding a Core to Lighthouse (in 5 minutes)
New: RenderCore_Minimal Advanced Graphics β Whitted 32
Advanced Graphics β Whitted 33
RenderCore_Minimal
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
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
intersection; tri tris ar are for
shading.
Advanced Graphics β Whitted 34
Adding a Core to Lighthouse (in 5 minutes)
New: RenderCore_Minimal float4* vertexData; β for( int y = 0; y < 512; y++ ) for( int x = 0; x < 800; x++ ) Plot( x, y, Trace( ray( origin, direction ) ) ); 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 * ?
βͺ Introduction: Appel βͺ Whitted βͺ Cook βͺ Assignment 1
Jacco Bikker - November 2019 β February 2020
next lecture: βAcceleration Structuresβ