Understanding the Rough Dielectric BSDF in Mitsuba
The Rough Dielectric BSDF is a material model representing an important class of real-world objects characterized by rough surfaces. It’s already provided as a default material in Mitsuba, the physically-based (differentiable) renderer.
Here are some notes on important things I learned while studying the theory and implementation. Below is the link to my (simplified) Python implementation. (TODO)
Background: The Microfacet Model
Things would look very fake if it were perfect. By perfect, I mean a surface is smooth no matter how much you zoom in to it. Real-world surfaces are not like this. They have much noisier alignments for whatever reasons: friction, imperfections in manufacturing, etc.
Microfacet theory provides a method to make surfaces look more realistic by making them less perfect.
It assumes that a surface is made of perfectly specular facets on a micro-scale. By accounting for the misalignment of these micro-facets with the macroscopic geometry normal, it aims to achieve a much more realistic appearance.
Of course, explicitly describing the geometry of the micro-facets would be very expensive, in terms of memory and computation. Hence, microfacet theory uses a statistical description of the alignment of normals, using normal distribution functions (NDFs).
The rough dielectric BSDF is an example of a material model based on Microfacet theory.
- Resources on Microfacet Theory
- https://zero-radiance.github.io/post/microfacet-specular/
- Walter, Bruce, et al. “Microfacet Models for Refraction through Rough Surfaces.” Rendering techniques 2007 (2007): 18th.
The Rough Dielectric BSDF
📌 BSDF
A BSDF is a model that describes how the material interacts with light at a specific point.
More specifically, it is a function that describes how light energy is distributed across pairs of directions.
📌 The Rough Dielectric BSDF
is a BSDF for specular reflection/refraction at the surfaces of dielectric materials (as opposed to metallic). It’s used to represent rough surfaces.
📌 The Formula
- The BSDF models two types of light interactions: reflection and refraction. Hence, the BSDF is represented as a sum of the two components and :
-
Derivation. To derive these formulas, we use the fact that a single Monte-Carlo estimate should be equal to the attenuated radiance after considering the Fresnel and masking term of the microfacet model:
The right hand side is the attenuated radiance when assuming the microfacet surfaces are perfect mirrors. Note that the pdf is just the normal distribution function after accounting for change of variables from to :
-
Additional Resources with Derivation
- Reflection component
Roughness Using Microfacet Theory
- Refraction Component
📌 Importance Sampling
The above formula can give us the BSDF value given a pair of incident and outgoing directions. Another important question to answer is:
How do we importance sample from the BSDF?
This is crucial for the actual implementation of a rendering system. With a path tracer, paths are incrementally constructed by determining the direction of the next ray at each bounce.
In other words: the input is and we need to compute .
graph TD
wo --Importance Sampling--> wi
-
[Step 1] Sampling the half-vector first!
Rather than directly computing wi, we can start by sampling the half vector . A widely used method is to sample from the distribution of visible normals. This is used by default in Mitsuba, and it says that using the naive sampling method will lead to poor convergence.
wm = sample_wm(wo,n) pdf_wm = mfDistrb.PDF(wo,n) # evaluate PDF from microfacet distribution -
[Step 2] Determining type of interaction: Reflection vs. Refraction.
Recall that our BSDF has both a reflection and refraction lobe. The type of interaction is determined stochastically.
This is given by the Fresnel term, which gives us the probability of reflection at an interaction point.
pdf_interaction = Fresnel(dot(wo,wm),eta) -
[Step 3] Compute the final
The transformation is different for reflection and refraction.
if reflection: # 🪞 **Reflection |** Based on Law of Specular reflection wi = -wo + 2*dot(wo,wm)*wm pdf_cov = **TODO** else: # 🥛 **Refraction |** Based on Snell's law wi = -wo/eta + (dot(wo,wm)/eta - cos(theta_t))*wm pdf_cov = **TODO** -
[Step 4] Compute the weights
When importance sampling, we also need to provide the contribution of each sample, which is the BSDF evaluation divided by the PDF.
- PDF: We need to multiply the pdf computed in the previous steps: 1) pdf of sampling the half vector , 2) probability of the interaction type, 3) Change of variables
- Evaluation: Use the formula mentioned above.
-
Additional Resources
- Sampling with the Rough Dielectric BSDF
- Original Paper for sampling from the distribution of visible normals
- Heitz, Eric, and Eugene d’Eon. “Importance sampling microfacet‐based BSDFs using the distribution of visible normals.” Computer Graphics Forum. Vol. 33. No. 4. 2014.
Questions I Had
📌 Why do we need the change of variables term?
In Mitsuba and other rendering systems, Monte Carlo estimators assume we sample a local direction when incrementally constructing paths.
In the rough dielectric model, however, we sample the microfacet normal , representing the half-vector between incoming and outgoing directions:
This difference introduces a mismatch between the sampling domain (microfacet normals ) and the target domain (direction to next path vertex )
Hence, we need to account for the relationship between these two domains through a change of variables, which introduces a correction factor. This ensures that the probability density of the sampled microfacet normals is correctly transformed into the probability density of the sampled directions.
📌 Why do we need the Solid Angle Compression term?
When light crosses a medium boundary, it bends according to Snell’s law. The bending also affects the solid angle, which can be thought of as the “field of view” or spread of light rays.
Depending on the relative refractive index of the medium, the spread of the rays varies. For example, when light transitions to a medium with a higher refractive index, it bends more towards the normal. This causes rays to propagate in a more concentrated manner.
Because radiance is defined as the power per unit projected area per unit solid angle, we need to account for the difference in solid angle with a correction term. Since the solid angle scales by , the radiance needs to be scaled by the inverse, which is .
Note that this is needed ONLY when the sampled interaction is a refraction, not a reflection.
📌 Why are there two functions: sample and eval_pdf ?
Two function implementations are needed: sample() and eval_pdf() :
samplegenerates next path vertices for exploring the scene.- It returns 1) the next sample direction and 2) its weight
eval_pdfevaluates the bsdf and pdf given a pair of directions.- It returns the 1) the BSDF evaluation and pdf
At first, I was confused because the sample weight (returned by sample() ) seemed to be exactly the evaluation divided by the pdf . Why maintain redundant functions?
Looking at the implementation of the path integrator, it became clear that these two functions serve a different purpose.
sample: used for recursive path tracing. The weight determines the throughput needed for further recursive bounces.eval_pdf: used for evaluating the contribution of an emitter sampling. The pdf is also needed for MIS.
Closing Thoughts
The implementation was mostly translating the C++ code into python. Still, I learned a lot of important details that I would have missed had I not have looked at the code line by line (e.g. solid angle compression term). I also got to take a deeper look into the path integrator.
Debugging Tips
- Debugging is tricky with drjit. Especially when debugging variables inside the loop. Starting with simpler settings (i.e.
directintegrator,pointemitter) helps.
