Game Engines 2021W Lecture 19

From Soma-notes
Jump to navigation Jump to search

Resources

Ray tracing

Godot's SDFGI & related tech

Notes

Ray Tracing

Key questions: - how does it work? - why is it so slow? How does light work, really? "Ground truth" for how light works is Quantum Electrodynamics - i.e., quantum mechanics for electromagnetism QED - you have photons, and you have electrons - photons are absorbed by electrons, and then they are emitted by electrons - when absorbed, electrons go to "higher" orbitals (higher energy) - when an electron moves to a lower energy orbital, it emits a photon so, to model light, ultimately we're modeling how electrons and photons interact Where does color come in? - frequency, i.e. energy, of photons - have to be in a specific frequency band to be visible light photons So, for rendering, why does this matter? - how things look is determined by how photons bounce around - their energy, hence their color, changes as they bounce around - brightness is how many photons you get Light is painful to model entirely because - there are LOTS of photons - they bounce EVERYWHERE - and this all affects how things look Perceived color is contextual - you don't know the color of anything until you know what its surroundings look like - human color perception is all about correcting for this physicists will say that photons have specific colors, i.e., their frequency - but actually, we perceive light based on the color of objects Something that is "red" will not emit red light (unless it is a light source). Instead, our brains model the scene and figure out it is red based on context - because different energy (color) photons will be emitted depending on lighting conditions Dim light, different color light (indoor vs sunlight), all affect the "energy" of photons but we can tell the difference, we see the same color. So even a pure physics-based model isn't enough, have to take into account human perception This is all to say that ray tracing has its benefits, but is far from a completely general solution - we'll discuss this more Ray tracing, we start with a received "photon", and we trace back its path to a light source - optimization, as we don't care about light that can't be perceived rays won't follow a direct path - interesting lighting effects come from how the rays bounce around - have to account for much (but not all) of this bouncing Part of the complexity is the recursive nature of the ray tracing algorithm The other part is how rays interact with surfaces - they are diffracted and reflected Earlier CGI tends to focus on reflections - think Terminator 2 - a fully reflective surface is "easiest", i.e., liquid metal - because we just have to model the surface as rays bouncing off at angles defined by the surface The real world is filled with surfaces that "capture" photons - they bounce around inside the object before releasing the photons Movies use ray tracing with complex material models But then, how are we doing "real time" ray tracing? - we're fast enough to do a lot of this recursion and support non-trivial surface models Regular lighting algorithms are not recursive at all - We at most consider one bounce - we often model surfaces as "self lighting" Godot does not support ray tracing currently - but this isn't that much of a disadvantage now, since it is rarely used in practice, and only in limited ways