
I wasn’t planning on doing more work on my path tracer, but when Jakub Boksansky posted a challenging version of the classic Cornell box on LinkedIn, I couldn’t resist the temptation to give it a go.
I already had most of the functionality I needed to render this scene in my BrinckMan path tracer, but I had to make some minor additions and create one largish tool.
What’s new
Shading normals
First, let’s return to Kajiya’s rendering equation, which I mentioned in my first post about my path tracer:
This is a model of light transport fundamentally built on a classical physics view of the world. The equation above assumes the presence of discrete surface interfaces, and the BRDF approximates the qualities of this interface at a macroscopic level. This is still a very reasonable and useful approximation, though.
Where am I going with this, you ask? The answer is shading normals: the concept of a surface element that has a different macroscopic orientation from the surfaces it’s sitting on. This is an inherently nonphysical concept (the previous sentence is a contradiction). Shading normals are a pure rendering hack. For this reason, I’d chosen not to implement them in my renderer, but in order to render Jakub’s scene, I needed to, since it contains both vertex normals (one form of shading normals) and normal mapping (an additional layer).
The shading normals cause the most “trouble” in the function that generates sample directions. The easiest way to handle it is to include the invalid paths – i.e., directions that go into the geometric surface – in the integration but set their contribution to zero. You could theoretically sample a distribution that doesn’t generate any invalid directions to begin with, but it is difficult (near impossible) to calculate the PDF for such a distribution.

I introduced a “shading frame” in my light transport code. This was central enough to the code that I wanted complete control, so I chose to implement most of it without AI.
Tangent and binormal support
This was very straightforward. As I mentioned in my first article, Pixar has stopped publishing the specification for RenderMan. The one I have is version 3.2 from 2000, which doesn’t mention tangents or binormals. I had to get creative and made a minor addition to what’s accepted by the PointsPolygons interface. I tried to use Codex to implement this change (and a few other minor additions to the RIB interface), but it failed miserably (from an aesthetic perspective, not a functional one). More on this in the last section.
glTF PBR material
This was also pretty straightforward. Using Codex worked well here, probably because there was a very clear interface to use and a lot of existing sampling code to reuse. The glTF PBR material is described here.
ACES tone mapping
Up until now, my path tracer has just truncated anything above one before saving as sRGB. When I looked at how the EXR background (which helpfully contained large uniformly colored fields) in Jakub’s render came out, it was clear that I needed something more than a simple exposure adjustment to match his render. I asked Codex to investigate, and it concluded that Jakub’s render was likely using ACES tone mapping. I asked Codex to add this to my output code and also to make sure the error metric I use (see last article ) was adjusted to use the gradient of the ACES tone mapping curve.
Distance attenuation
The PxrLMGlass material I used in the previous render only specifies a fixed refraction modulation constant. To render this new scene, I added a simple exponential extinction coefficient that modulates the contribution of each path segment based on its length. This was easy enough to do that I didn’t bother with Codex.
glTF to RIB conversion
This is where I was fully able to leverage the power of AI. My renderer only accepts RIB files, and I wasn’t that keen on adding a parser for something else since the structure of the code is modelled on the RI C interface. I also had zero appetite for reading up on the glTF format and implementing a converter manually. Codex made extremely short work of this.
Comparing to Jakub’s render
First, some basic facts. Jakub’s image is rendered with forward path tracing without next-event estimation and uses 2,000,000 (!) samples per pixel.
My image is rendered with adaptive bidirectional path tracing and uses between 5,000 and 200,000 samples per pixel. That little recess is a real trap (probably as Jakub intended).

My first reflection is that it’s surprising that Jakub’s image isn’t noisier than it is. The light source is tiny! If you look at this breakdown of my image by sampling strategy, you can see that what at first glance appears to be the lamp is actually only a reflecting surface, and the light source is a small piece of geometry in front of it (the relatively sharp shadows also give this away).

The second thing to notice is that there’s less noise in my render on average, but significantly more in my caustics. I could have raised the sample count, but my renderer is CPU-only and not particularly optimized. I did this render on my home computer and didn’t feel like I could set aside more time than I did. I had resolved to not spend more time on my path tracer, but I’m sorely tempted to implement vertex-merging as well to get higher quality caustics.

The third and last thing is that I haven’t managed to get the glTF PBR iridescence quite right. There should have been more of a hue shift here, but for some reason it’s not working. I had Codex do some focused rendering on just this area and try to figure out what was wrong, but it was unsuccessful, and I didn’t have the stomach to do a deep dive on this myself. Thanks for nothing, clankers!

Mea culpa, mea culpa, mea maxima culpa
My experience so far is that AI is not great for hybrid setups where you need to work together on the same code. The agent typically does too much, ignores human sensibilities, and will often plow on where a human would have stopped and asked “Maybe I need a different approach?”. AI can continue to juggle things through brute force where a human would have given up. If the compiled artifact was all that mattered, this could be okay, but if a human occasionally needs to tweak or fix the code, it is still a problem. Even if humans don’t need to tweak the code, this can be a problem since the abstractions humans build to keep the complexity of their reasoning manageable are helpful to AI as well. Left to its own devices, the AI will build things that are expensive (in time and/or money) to iterate on. Despite all their training they don’t seem to have internalized the idea of a sunken cost fallacy
It is possible to make the problem smaller with good prompting, but my current opinion is that if you’re building something that will last, you need to take the time to guide the AI. From a human perspective, my RIB parser is extremely elegant. I first tried using AI to expand it, but it wreaked havoc. If you only considered the observable behavior, it was fine, but to me, as the person who had to work in the code, it was super offensive. It’s like you’ve invested heavily in your interior decoration, hiding all the cables and having subtle recessed downlights, and you hire someone to add new lighting in a corner of your living room and come home to find a thick extension cord running across the floor, held down with duct tape and connected to a floor floodlight.
“I then compounded that mistake by treating my converter’s output as a requirement your change needed to satisfy, and defending it with a general rule instead of acknowledging the unsupported design choice. The appropriate correction is in the converter, not a demand to expand your parser.”
I know I shouldn’t get angry at an information-processing algorithm, but sometimes it is hard not to. I’m no fan of Bill O’Reilly, but at this point I sympathized with his classic “We’ll do it live!” outburst as I had to manually implement all the necessary parser changes.

As a counter example of a situation where AI works really well, I’ll point to the glTF-to-RIB converter. I don’t really care what this code looks like since I’m not going to fiddle with it. I only care about the results. In this case, Codex was an enormous productivity boost.
Leave a Reply