Lecture 08: Lighting and shadows

Computer graphics in Game development

Ivan Belyavtsev

10.06.2022

Current result vs rasterizer

Raytracing result Rasterizer result

Rendering equation

\[\scriptsize{L_o(X, \vec{\omega_o}) = L_e(X, \vec{\omega_o}) + \int_S L_i(X, \vec{\omega_i}) f_{X,\vec{n}}(\vec{\omega_i}, \vec{\omega_o}) |\vec{\omega_i} \cdot \vec{n} | d{\omega_i}} \]

where \(X\) is a position on the object or surface,

\(\vec{\omega_o}\) is a direction toward the eye or camera,

\(L_o(X, \vec{\omega_o})\) is all outgoing light from the position,

\(L_e(X, \vec{\omega_o})\) is emitted light [1]

Rendering equation

\[\scriptsize{L_o(X, \vec{\omega_o}) = L_e(X, \vec{\omega_o}) + \int_S L_i(X, \vec{\omega_i}) f_{X,\vec{n}}(\vec{\omega_i}, \vec{\omega_o}) |\vec{\omega_i} \cdot \vec{n} | d{\omega_i}} \]

where \(\vec{n}\) is normal to surface at \(X\) position,

\(S\) is a unit hemisphere among \(\vec{n}\) with center in \(X\),

\(L_i(X, \vec{\omega_i})\) is a light coming from \(\vec{\omega_i}\) direction,

\(f_{X,\vec{n}}(\vec{\omega_i}, \vec{\omega_o})\) is the bidirectional reflectance distribution function (BRDF) [1]

Bidirectional reflectance distribution function

From: [2]

Phong shading

\[\small{L(\vec{P}) = Ka + \sum_{lights}{[Kd\vec{N} \cdot \vec{L} + Ks(\vec{V} \cdot \vec{R})^{Ns}]}}\]

where \(\small{\vec{R} = 2(\vec{N} \cdot \vec{L})\vec{N}−\vec{L}}\) [3]

From: https://upload.wikimedia.org/wikipedia/commons/6/6b/Phong_components_version_4.png

Lambertian shading

\[L_d = k_dI\max(0, \vec{n}\cdot\vec{l})\]

where \(L_d\) - diffusely reflected light,

\(k_d\) - material’s diffuse coefficient,

\(\vec{n}\) - surface normal,

\(\vec{l}\) - direction toward the light [4]

Lab: 2.03 Lambertian shading

  1. Add light information to lights array of ray_tracing_renderer
  2. Adjust closest_hit_shader of raytracer to implement Lambertian shading model

Shadow rays idea

Before adding the light source to the final point on the point \(X\), we should cast a ray from the point \(X\) towards the light source. If any object occludes the shadow ray, the point \(X\) is on shadow and the light should not be added the light source

Shadow rays

From: https://www.researchgate.net/figure/1-This-figure-demonstrates-the-concept-of-ray-tracing-A-ray-is-cast-from-the-camera_fig1_236342499

Shadow rays tips

  • Intersection with any geometry farther than light source doesn’t occlude the light source. To skip such object cast the ray with \(t_{max}\) less than distance from \(X\) to the light source
  • To avoid self-intersection with the triangle owning \(X\), use \(t_{min}\) more than 0
  • One intersection is enough to find an occlusion - use an AnyHit shader

Lab: 2.04 Shadow rays

  1. Adjust trace_ray method of raytracer to use any_hit_shader
  2. Initialize shadow_raytracer in ray_tracing_renderer
  3. Define any_hit_shader and miss_shader for shadow_raytracer
  4. Adjust closest_hit_shader of raytracer to cast shadows rays and to ignore occluded lights

References

1.
Kajiya J.T. The rendering equation // SIGGRAPH Comput. Graph. New York, NY, USA: Association for Computing Machinery, 1986. Vol. 20, № 4. P. 143–150.
2.
Fernando R. GPU gems: Programming techniques, tips and tricks for real-time graphics. Pearson Higher Education, 2004.
3.
Phong B.T. Illumination for computer generated pictures // Commun. ACM. New York, NY, USA: Association for Computing Machinery, 1975. Vol. 18, № 6. P. 311–317.
4.
McGuire M. The graphics codex. 2.14 ed. Casual Effects, 2018.
// reveal.js plugins