Moments in Graphics
A blog by Christoph Peters

# Finding Real Polynomial Roots on GPUs

Published 2023-10-31

A recent paper of mine performs an intersection test in a ray tracing shader. To this end, I had to compute all real roots of a polynomial of moderately high degree (10 to 26). Overall, computing polynomial roots is an extremely well-studied problem where many highly accurate and reliable methods are available [Press2007]. However, implementations of such methods on GPUs are rarely found. After experimenting a bit with different options, I ended up implementing a recent polynomial solver proposed by Cem Yuksel [Yuksel2022]. I wrote my implementation from scratch in GLSL. A naive implementation has many nested loops or recursions and accesses arrays using loop counters. That is a recipe for register spilling, which is devastating to the performance of the shader. After a bit of puzzling, I ended up with an implementation that avoids this problem entirely. You can take a look at my implementation on Shadertoy and read on to learn more about how it works, why register spilling is an issue and how I resolved it. Read more...

# Path tracing workshop

Published 2022-12-20

Now that GPUs have ray tracing units, real-time path tracing is coming into reach. Applications beyond movie rendering and baking embrace it, and therefore more people need to know about it. At Intel, I recently offered a path tracing workshop to educate a broad audience of engineers on basics of the topic. I am happy to announce that we decided to make this workshop publicly available. If you know a few math and programming basics, you can watch 76 minutes of videos and solve some exercises on ShaderToy as you go. In the end, you will have written your own ray tracer and a path tracer on top of it! I simplified things as much as possible, but you will really write all key aspects of the path tracer and understand why they work. Read more...

# My toy renderer, part 5: Animations

Published 2022-06-01

I was not planning to have a fifth part in this series about my toy renderer but there were some interesting changes for our paper on vertex-blend attribute compression. The renderer now supports animations with linear vertex-blend animation (also known as skinning). That means there is a skeleton consisting of animated bones and those influence the mesh. I had to export these animations from Blender to my renderer and I wanted to keep it simple. Thus, the Blender exporter just dumps all bone transforms for each frame into one big texture that vertex shaders read directly. And as for other parts of the file format, there is some reasonable compression. Read more...

# fma: A faster, more accurate instruction

Published 2021-12-01

When people look at my shader code, one of the most frequently asked questions is why I use the GLSL fma instruction (or its HLSL equivalent mad) so frequently. In spite of the punny title of this post, fma actually stands for fused multiply-add, i.e. it implements the formula fma(a,b,c)=a*b+c. It is faster than separate multiplication and addition because on most CPUs and GPUs it counts as one instruction. It also introduces less rounding error. The real question is whether you should rely on the compiler to use it as appropriate or not. This post explains why I don't and shows a few neat numerical tricks that benefit from fma. Read more...

# Matplotlib slides

Published 2021-08-07

I used to make my slides in Powerpoint. For my presentations at SIGGRAPH 2021 and HPG 2021, I tried something different. The whole slide deck is one big interactive matplotlib plot. Every bit is scripted in Python. They feature lots of animated and interactive plots. I am satisfied with how this experiment worked out. Lazily hacking together slides works better with Powerpoint but if you want a high-quality presentation with the best possible illustrations of mathematical concepts, this approach makes sense. This blog post provides some details about how I did it. Read more...

Published 2021-07-28

In the past winter term at Karlsruhe Institute of Technology, I had the pleasure of supervising Bastian Urbach's bachelor thesis. His topic has been the generalization of methods for shading with polygonal lights to polyhedral lights. He has been highly motivated and creative. The result is an efficient method for GPU-accelerated real-time shading with convex or non-convex polyhedral lights (see Figure 1). Shading itself works either through linearly transformed cosines [Heitz2016] or through Monte Carlo integration. And it's implemented in Unity. Both the bachelor thesis and the implementation are now freely available on Bastian's blog. If that sounds interesting, go ahead and read his short blog post or the whole thesis. It's much like a concurrent work published recently at EGSR [Aakash2021] but there are pros and cons for both techniques. The blog post discusses those as well. Read more...

# My toy renderer, part 4: Ray tracing

Published 2021-07-25

Part 4 of this series about my toy renderer is all about ray traced shadows. In particular, I discuss direct lighting with polygonal and linear lights for diffuse and specular surfaces. I have described the corresponding methods in two recent research papers but this post is written with a broader audience in mind. While the papers focus on the mathematical derivation of the algorithms, this post starts with some basics of physically-based rendering and explains in detail why there is a need for these algorithms and how they can be used in a renderer. Read more...

# My toy renderer, part 3: Rendering basics

Published 2021-07-16

Part 3 of this series about my toy renderer covers some basic techniques for rendering. My renderer does nothing fundamentally new on this front but some choices are a bit exotic. It is ultimately about real-time ray tracing, so everything should play nicely with that. Besides I want it to be slick and fast. Disregarding dear ImGui, the whole thing only makes two draw calls per frame. It uses a visibility buffer [Burns2013] and the same reflectance model for all surfaces [Lagarde2015]. A 3D table of linearly transformed cosines [Heitz2016] approximates this reflectance model when needed. It almost has a Shadertoy vibe since the bulk of all work happens in a single fragment shader for the shading pass. To get stratified random numbers, it uses a recent work [Ahmed2020] for 2D polygonal lights and my blue noise textures for 1D linear lights. Read more...

# My toy renderer, part 2: Scene management

Published 2021-07-02

Part 2 of this series about my toy renderer is all about scene data. The requirements are fairly lax, since I only care about static triangle meshes. For the most part, I want to be able to render the ORCA assets and a couple of scenes from Blendswap. However, I emphasized how much long compile times harm productivity in the previous post. All of that applies equally to load times since they interrupt work in a similar way. I want to be able to load huge scenes within seconds and I want to render them quickly. Besides results must be reproducible. Read more...

# My toy renderer, part 1: Keep it simple

Published 2021-06-25

Part 1 of this series about my toy renderer covers the most fundamental design decisions. Over the years, I have written many renderers and for a long time their complexity kept growing. This time, I took the opposite route. I wanted to maximize the fraction of code that implements crucial functionality rather than wasting my time on bloaty infrastructure. The code that I wrote (excluding shaders) has 7575 lines at 345 kB. Not exactly a 4k intro but much smaller than any other real-time renderer I have used before. It takes ca. one second to compile and link and startup is also quick. Read more...

# My toy renderer: Overview

Published 2021-06-24, updated 2022-06-01

Alongside my latest papers I released the underlying renderer as open source. It is a real-time deferred renderer with ray traced shadows based on Vulkan and written in C. As I wrote it, I had the liberty to try some unconventional designs and techniques. So I did, because that is an excellent way to learn new things. It also became the basis for our work on vertex-blend attribute compression. Read more...

# Linearly Transformed Spherical Harmonics Expansions

Published 2020-12-02

In my job at the Karlsruhe Institute of Technology, I usually supervise two bachelor or master theses per term (four per year). By handing out topics that have a sufficiently narrow scope but tap directly into current rendering research, I try to pass on my passion for this subject. Read more...

# Using LyX to write ACM and Eurographics articles

Published 2019-11-11

If you are familiar with my work, you may be surprised to hear that I barely ever write documents in LaTeX. All of my first author papers, as well as my bachelor, master and PhD thesis are written entirely in LyX. LyX is a text editor that generates LaTeX code for you. I appreciate it because it helps me get through the creative process of writing without distraction and aids my mathematical research through its excellent formula editor. Read more...

# Redesign of the blog

Published 2019-08-27

Over the past year, I have gotten dissatisfied with the setup of my blog. Discoverability of posts was not particularly good, maintenance work began to outgrow the work for new content and I grew tired of the Wordpress layout. Rather than fixing each issue individually, I decided to turn the whole thing into a static HTML page generated by my own set of Python scripts. The resulting redesign will hopefully make it easier for you to find the posts you care about and to read them without distraction and for me to create them. The following post discusses the changes in more detail. Read more...

# Sampling projected spherical caps with multiple importance sampling

Published 2019-06-10

This blog post answers a question that Tomáš Davidovič from Weta Digital had about the recently published projected solid angle sampling for spherical caps. In Monte Carlo rendering, it is very common to combine several sampling techniques through multiple importance sampling. In this case, any of the sampling techniques may produce a sample and then you need to compute the probability density for producing this sample with each of the other techniques. Read more...

# A brief postscript on moment-based order-independent transparency

Published 2018-08-23

Back in May, we published moment-based order-independent transparency (MBOIT) at the Symposium on Interactive 3D Graphics and Games 2018. This brief post follows up on two things; a similar but independent work and some missing code. Read more...

# My dissertation is available now

Published 2017-12-31

My dissertation has been published digitially and is now available in its entirety as a free download. Most results have been published before through my papers at i3D 2015, SIGGRAPH Asia 2015 and JCGT. Though, there is some entirely new material. Since I spent a lot of time writing it, there better be somebody to read parts of it. Below I'll try to wet your appetite. Read more...

# Demo with non-linearly quantized moment shadow maps and more

Published 2017-09-05

My recent paper on non-linearly quantized moment shadow maps promises an executable demo. Preparing that took a little longer than expected but to make up for the delay, the demo has plenty of new features. Most notably it now uses dear imgui and includes the applications of blue noise I blogged about earlier. Rather than showing off the new technique only, this demo is an extension of earlier demos, so it also features soft shadows, single scattering and shadows for translucent occluders. Read more...

# JCGT extension out now

Published 2017-03-30, updated 2017-09-04

The invited extension of our i3D 2016 paper is now published in the Journal of Computer Graphics Techniques. It discusses techniques for real-time soft shadows, single scattering and shadows for translucent occluders with some novel improvements. All of these techniques are based on moment shadow mapping and the paper also introduces improvements to moment shadow mapping itself. Read more...

# The problem with 3D blue noise

Published 2017-01-31, updated 2017-02-10

After the previous blog post several readers (namely Morgan McGuire, Mikkel Gjoel and Bart Wronski) expressed interest in 3D blue noise. Thus, this blog post provides a database of such blue noise textures. It also explains why you might not want to use it. The post relies on concepts introduced in the previous post so you should read this one first. Read more...

# Free blue noise textures

Published 2016-12-22, updated 2016-12-23, 2017-01-31

Dithering is almost as old as computer graphics but recently it has received quite a lot of attention among game developers. To name two examples out of many, Mikkel Gjoel spoke about its use in Inside at GDC 2016 and Bart Wronski wrote a blog post series about it. This attention is well-deserved. Read more...

# New shadow demo with documented HLSL code

Published 2016-09-25, updated 2016-09-29

It's time to deliver on a recent promise. Moment shadow mapping and its applications have seen quite a few minor but useful improvements lately. The GDCE 2016 lecture covered some of them but only marginally. This post provides a brand-new release of my shadow mapping demo with documented shader code including all these improvements. Read more...

# How to solve a cubic equation, revisited

Published 2016-09-10

This post covers a little gem worth sharing: The fastest solution to cubic equations with three real roots that I am aware of. It is also fairly robust and I implemented it in HLSL. It is based on the work by Jim Blinn [Blinn07b] but tweaked for double speed. Read more...

# Using Markdeep for a WordPress blog

Published 2016-08-20, updated 2016-12-23

In response to Morgan McGuire's request this post will explain how I set up this blog using his handy Markdeep, MathJax and Wordpress. The blog is hosted on my rented server and when you request a page it usually won't make connections to any other hosts to keep you from being tracked. Most of this post is specific to Markdeep, so you may also find it useful if you have no plans to use Wordpress. Read more...

# Of posts to come

Published 2016-08-11

I've got a blog now and you're reading its first post. This is not the place to tell you what the blog is all about or to ramble about past publications (though, you can download all of them here, including code and demos). I'd rather look into the future and tell you what to expect. Read more...