← Blog

Understanding the Rough Dielectric BSDF in Mitsuba

· updated July 29, 2025 · Mitsuba, Rendering

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.

Link to C++ src

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.

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 fRf_R and fTf_T:
fR(ωi,ωo)=D(ωm) G(ωm) F(ωm⋅ωo)4πcos⁡θiθof_R(\omega_i, \omega_o) = \frac{D(\omega_m)\ G(\omega_m)\ F(\omega_m\cdot\omega_o)}{4\pi\cos\theta_i\theta_o} fT(ωi,ωo)=D(ωm) G(ωm) (1−F(ωm⋅ωo))((ωi⋅ωm)+(ωo⋅ωm)/η)2∣ωi⋅ωm∣∣ωo⋅ωm∣∣cosθi∣∣cos⁡θo∣f_T(\omega_i, \omega_o) = \frac{D(\omega_m)\ G(\omega_m)\ (1-F(\omega_m\cdot\omega_o))}{((\omega_i\cdot\omega_m) + (\omega_o\cdot\omega_m)/\eta)^2}\frac{|\omega_i\cdot\omega_m||\omega_o\cdot\omega_m|}{|cos\theta_i||\cos\theta_o|}
  • 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:

    fR(ωo,ωi) Li(ωi) ∣cos⁡θi∣p(ωi)=F(ωm⋅ωo) G(ωi) Li(ωi)\frac{f_R(\omega_o,\omega_i) \ L_i(\omega_i)\ |\cos\theta_i|}{p(\omega_i)} = F(\omega_m\cdot\omega_o)\ G(\omega_i)\ L_i(\omega_i)

    The right hand side is the attenuated radiance when assuming the microfacet surfaces are perfect mirrors. Note that the pdf p(ωi)p(\omega_i) is just the normal distribution function after accounting for change of variables from ωm\omega_m to ωi\omega_i:

    p(ωi)=Dωo(ωm)dωmdωip(\omega_i) = D_{\omega_o}(\omega_m) \frac{d\omega_m}{d\omega_i}
  • Additional Resources with Derivation

    • Reflection component

    Roughness Using Microfacet Theory

    • Refraction Component

    Rough Dielectric BSDF

📌 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 ωo\omega_o and we need to compute ωi\omega_i.

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 ωm\omega_m. 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 ωi\omega_i

    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 ωm\omega_m , 2) probability of the interaction type, 3) Change of variables
    • Evaluation: Use the formula mentioned above.
  • Additional Resources

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 ωi\omega_i when incrementally constructing paths.

In the rough dielectric model, however, we sample the microfacet normal ωh\omega_h, representing the half-vector between incoming and outgoing directions:

ωh=ωi+ωo∣∣ωi+ωo∣∣\omega_h = \frac{\omega_i + \omega_o}{||\omega_i + \omega_o||}

This difference introduces a mismatch between the sampling domain (microfacet normals ωh\omega_h) and the target domain (direction to next path vertex ωi\omega_i )

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 1η2\frac{1}{\eta^2}, the radiance needs to be scaled by the inverse, which is η2\eta^2.

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() :

  • sample generates next path vertices for exploring the scene.
    • It returns 1) the next sample direction ωi\omega_i and 2) its weight fs(ωi,ωo)p(ωi)\frac{f_s(\omega_i,\omega_o)}{p(\omega_i)}
  • eval_pdf evaluates the bsdf and pdf given a pair of directions.
    • It returns the 1) the BSDF evaluation fs(ωi,ωo)f_s(\omega_i,\omega_o) and pdf p(ωi)p(\omega_i)

At first, I was confused because the sample weight (returned by sample() ) seemed to be exactly the evaluation fs(ωi,ωo)f_s(\omega_i,\omega_o) divided by the pdf p(ωi)p(\omega_i). 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. direct integrator, point emitter) helps.