Implementing a Physically Based Shading without locking yourself in

Over the last few months I have been trying to push my understanding of Physically Based Shading, by actively exploring every corner and turning over every stone, to uncover any area where I lack knowledge. Although this is still an ongoing process and I still have a lot to do, I thought I could already share some of what I have learned in the process.

Last weekend the Easter demoparty event Revision took place, as an online version due to the current pandemic situation. There, I presented a talk on Physically Based Shading, in which I went into electromagnetism, existing models, and an brief overview of a prototype I am working on.

The presentation goes into a lot of detail about interaction of light with matter from a physics point of view, then builds its way up to the Cook-Torrance specular BRDF model. The diffuse BRDF and the Image Based Lighting were skipped due to time constraints. I am considering doing a Part 2 to address those topics, but I haven’t decided anything yet.

In the mean time, please leave a comment or contact me if you notice any mistake or inaccuracy.

Abstract

How do you implement a Physically Based Shading for your demos yet keep the possibility to try something completely different without having to rewrite everything?
In this talk we will first get an intuitive understanding of what makes matter look the way it looks, with as much detail as we can given the time we have. We will then see how this is modeled by a BRDF (Bidirectional Reflectance Distribution Function) and review some of the available models.
We will also see what makes it challenging for design and for real-time implementation. Finally we will discuss a possible implementation that allows to experiment with different models, can work in a variety of cases, and remains compatible with size coding constraints.

Slides

Here are the slides, together with the text of the talk and the link to the references:
Implementing a Physically Based Shading model without locking yourself in.

Video

And finally here is the recording of the talk, including a quick demonstration of the prototype:

Interference shader

Here is the shader used during the presentation to illustrate light interaction at the interface between to media:

Acknowledgements

Thanks again to Alan Wolfe for reviewing the text, Alkama for the motivation and questions upfront and help in the video department, Scoup and the Revision crew for organizing the seminars, Ronny and Siana for the help in the sound department, and everyone who provided feedback on my previous article on Physically Based Shading.

Addendum

Following the publication of this article, Nathan Reed gave several comments on Twitter:

FWIW – I think the model of refraction by the electromagnetic field causing electrons to oscillate is the better one. This explains not only refraction but reflection as well, and even total internal reflection. Feynman does out the wave calculations: https://feynmanlectures.caltech.edu/II_33.html

It also explains better IMO why a light wave keeps its direction in a material. If an atom absorbs and re-emits the photon there is no reason why it should be going in the same direction as before (conservation of momentum is maintained if the atom recoils). Besides which, the lifetime of an excited atomic state is many orders of magnitude longer than the time needed for a light wave to propagate across the diameter of the atom (even at an IOR-reduced speed).

Moreover, in the comments of the shader above, CG researcher Fabrice Neyret mentioned a presentation of his from 2019, which lists interactions of light with matter: Colors of the universe.
Quoting his summarized comment:

In short: the notion of photons (and their speed) in matter is a macroscopic deceiving representation, since it’s about interference between incident and reactive fields (reemitted by the dipoles, at least for dielectrics).


From Maxwell’s equations to Fresnel’s equations

This series of short videos shows how to derive Maxwell’s equations all the way to Fresnel’s equations. Each one is about 10 to 15mn long.

The first four videos show how to use boundary conditions to deduce the relationship between the electromagnetic field on both sides of a surface (or interface between two different media).

The next four videos use the previous results to obtain the Fresnel equations, for S-polarized and P-polarized cases.

The rest of the series then dives into other topics like thin film interference.

The series assumes the viewer to be already familiar with the Maxwell equations, so it can be helpful to first see the explanation by Grant Sanderson of 3Blue1Brown on Maxwell’s equations.

Metal materials study

Texture artist Jarrod Hasenjager posted a page of various metal materials study: aluminum, brass, bronze, chrome, copper, gold, iron, lead and steel, and rusted steel and iron. According to the description, the renders are done in Houdini, and the look is driven by artistic taste and personal experience rather than from physical values.

Fresnel and the Poisson spot

The casting of the following story is remarkable. The year is 1818. On one side, Augustin Fresnel (1788 – 1827) has just handed to the French Academy of Sciences (Académie des Sciences) an essay defending a theory completely opposed to the widely accepted one; on the other side, François Arago (1786 – 1853), Jean-Baptiste Biot (1774 – 1862), Louis Joseph Gay-Lussac (1778 – 1850), Pierre-Simon Laplace (1749 – 1827) and Siméon Denis Poisson (1781 – 1840) are the panel in charge of assessing it. These are all major theorem names. Men who built Science, the giants whose shoulders we stand upon. But the context is peculiar: the scientists are here to fight, as the battle is raging between partisans of the particle theory and partisans of the wave theory.

Augustin Fresnel

It all starts three years earlier, in July of 1815, when Fresnel (then 27) meets the person who would later become his mentor, Arago. The political background is rough: the Hundred Days have ended just a month before with the defeat of Napoleon at the battle of Waterloo, and Fresnel, a royalist, is under police scrutiny and has been dismissed from his title as a state engineer. The scientific background is the status quo: Isaac Newton’s corpuscular theory of light is prevailing and unshakeable.

Pushed forward by Arago who sees great potential in him, Fresnel performs rudimentary experiments with light diffraction at his mother’s home, in a town north of Caen. There, with gear made by a local worker and consisting of wires and drops of honey serving as lenses, he observes and measures hyperbolic fringed patterns that cannot be explained by the particle theory (which should lead to linear patterns). He thus builds upon the wave theory by Hyugens and on October 26th, sends to the French Academy of Sciences a first paper reporting his observations. He will later send more of these papers, prompting strong reactions from the community, especially Laplace.

The competition organized by the Academy and aimed at rewarding the best work on a given topic is seen as the perfect opportunity to put an end to the battle. Proposed on the 17th of March 1817, and ending on the 1st of August of the next year, it focuses on diffraction phenomenons, and while rigorous, it seems to have been written by a supporter of the corpuscular theory. Opponents to the wave theory are hoping to see someone present a work that will put a stop to it.

Arago, originally convinced by the particle theory, sees Fresnel as the one who can best defend the wave theory. He helps him any way he can, and in particular helps him move to Paris to enter the competition. Even André-Marie Ampère (1775 – 1836), although a openly partisan of Newton’s theory (possibly for political reason related to the Academy), gives him full support. Both push him to publish his new results. The three will become close friends in the process.

Finally this essay handed at the last minute (29th of July 1818) is the only one selected out of two submitted. Natura simplex et fecunda is much more thorough than the previous works, and it is nowadays described as a masterpiece. Going beyond the work of Thomas Young (1773 – 1829), the author proposes a model that predicts with precision the position and size of the fringes, and presents the experiment now known as Fresnel double mirror.

Among the jury, Biot, Laplace and Poisson are the most resolutely opposed to wave theory. Poisson in particular, fascinated by Fresnel’s theory, studies it in detail, looking for weaknesses. From it he derives a counter intuitive result beyond Fresnel’s own predictions: by placing a disc at a certain distance between a source of light and a screen, a bright spot should appear in the center of the disc’s shadow. To Poisson, this apparently absurd consequence is a proof that invalidates Fresnel’s work.

But Arago decides to proceed and perform the experiment. To everyone’s surprise, the spot predicted by Poisson is indeed observed. The anecdote, recorded by Arago, would be the strawberry on the shortcake to Fresnel’s success that day. Ironically, although it still didn’t convince Poisson, the experiment is since then often referred to as the Poisson spot.

 


Some references:

Augustin Fresnel’s essay used to be available on the website of the Académie des Sciences, but the link seems to be broken recently.

“Mémoire sur la diffraction de la lumière” on the website of the French Academy of Science (fr, PDF)

André Marie Ampère et Augustin Fresnel (fr)


Final word:

Before opening this space specifically dedicated to light and rendering, I was posting from time to (increasingly distant) time on another blog in French. One post that attracted attention was the story of Augustin Fresnel defending his thesis in front of the Académie des Sciences. Given the impact his ground breaking work has on rendering, I thought it made sense to translate it and post it here.

I have tried my best to bring the pieces together from different sources, but some of them were disagreeing on some details, and unfortunately I haven’t noted all the references so it is possible some part isn’t 100% faithful to the events. Please leave a comment if you have some material on the topic.

A GLSL version of smallpt

smallpt is a bare minimum path tracer written under 100 lines of C++, featuring diffuse, and specular reflection, and refraction. Using the detailed explanation slides by David Cline, I experimented porting it to GLSL on Shadertoy.

This proved to be an interesting experiment that brought a few lessons.

You can see the shader and tweak it here. By default it uses 6 samples per pixel, and 3 bounces, which allows it to run smoothly on average hardware. I found 40 samples per pixel and 5 bounces to give nice results while maintaining interactive framerate.

Path tracing, 40 samples per pixel, 5 bounces

Path tracing, 40 samples per pixel, 5 bounces

Update: since GLSL Sandbox has a feature, reading from the previous frame buffer, that Shadertoy is missing at the moment, I thought it’d be interesting try it to have the image converging over time. A little hacking later, a minute or so worth of rendering got me this kind of result: Given the effort, I am really pleased by the result.

Path tracing, 40 samples per pixel, 5 bounces

Path tracing, unknown number of samples per pixel, 7 bounces

Toward physically based rendering, screenshot after screenshot

Here are the screenshots I made for the talk I previously mentioned. They show how the rendering evolves through the choice of shading. The setup consist of a close yellowish punctual light on the up right, and a distant red-ish punctual light on the back left, as well as a dim blue ambient. The objects only differ by the specular exponent, which jumps by a times two factor from one object to the next one, left to right.

One light, Lambert diffuse only.

Two lights, Lambert diffuse only, with variance shadow map.

Two lights, Lambert diffuse only, with albedo.

Two lights, diffuse and Phong specular. Notice the color on the left.

One light, Phong specular only. Notice the discontinuity on the left.

Two lights, diffuse and Blinn-Phong specular.

One light, Blinn-Phong specular only. Notice the absence of discontinuity.

Two lights, diffuse and normalized Phong specular. Notice the highlight intensity.

Two lights, diffuse and normalized Blinn-Phong specular.

Two lights, diffuse and normalized Blinn-Phong specular, Fresnel term with Schlick

Two lights, Heidrich-Seidel anisotropic specular.

Next steps: getting used to the Fresnel version, experimenting with the exponent as a texture lookup, and normalizing the Heidrich-Seibel specular.

Talking about light at Revision

Over the last months I have been reading various resources on light shading, and shared the most relevant ones on this blog. Along the way I became more and more thrilled by how light interacts with materials and how we can model it to get more convincing rendering.

I found some insights to be really enlightening and very worth sharing. Therefore as a way of challenging my own understanding of this matter and as an opportunity to practice talk, I decided to speak about real-time lighting during a seminar at Revision.

Revision is a big demoparty that will be held during four days over the Easter weekend in Saarbrücken, Germany. If you are coming (which I recommend) and want to hear about shading, specular and Fresnel, come and see me!

Update: the talk is scheduled for Saturday April 7th, 14h – 15h.

“Introduction to light shading for real-time rendering”


Update: see this post for the material.