Crate bsdf

Source
Expand description

This crate is designed to cover a wide range of materials in a path tracer. Furthermore, methods for importance sampling are provided.

§Design Decisions

NOTE: This crate is pretty much in alpha state. Therefore a lot of the following things may or may not change in the future

The code is geared towards pathtracing. Direct lighting techniques such as image based lighting or polygonal lights are not implemented.

Lighting calculations are done exclusively in f64s. This is because BSDFs can be extremely spiky. Using f64 has helped reducing numerical errors. However, material parameters are stored as f32s for a minimal memory footprint. All materials can be constructed on the fly, since they (currently) do not rely on precomputed data. At some point in the future we might address this with generic implementations over f32 and f64.

BSDFs are computed in a local space. That means, the surface is assumed to be the xy-plane and the z-vector is assumed to be the normal. Therefore incident and exitant vectors must be rotated before or after evaluation of the BSDF.

The |omega_i.dot(n)|, |cos theta_i| or |omega_i.z| are not part of the BSDF. The user is responsible for multiplying them in if necessary (almost always). Pdf’s on the other hand, are meant for high quality importance sampling. Therefore, they try to take this cosine term into account when generating samples.

sample_... functions are deterministic. That means you are responsible for generate f64 in the range of 0.0..1.0. This allows you to control the sampling process and the random generator or low discrepancy sequence in use. These random floats are either passed as a Vec3d or Vec2d

This crate is built on glam for a simple but fast vector math library at the core.

§Examples

The pathtracer example shows you how to integrate this crate into a simple forward pathtracer. The code is kept very close to Raytracing in a Weekend to make it easy to understand.

§References

A lot of pathtracing literature went into this. Here are the most influential papers and other sources I have used:

Modules§

conductive
BSDF that resembles the appearance of metals
disney
BSDF inspired by the Disney BSDF and Blender’s Principled BSDF
emissive
BSDF that emits light but reflects none
ggx
An implementation of the GGX Distribution
lambert
BSDF that can resemble smooth Diffuse surfaces like plastic
mix
BSDF that can blend two arbitrary BSDF’s together
rough_glass
BSDF that resembles the appearance of glass. Roughness can be adjusted

Structs§

SampleEmissionResponse
Contains the Data that is returned by BSDF::sample_emission
SampleIncomingResponse
Contains the Data that is returned by BSDF::sample_incoming
SampleOutgoingResponse
Contains the Data that is returned by BSDF::sample_outgoing

Traits§

BSDF
Bidirectional Scattering Distribution Functions. A trait that describes the surface properties of a material if you will.

Type Aliases§

RgbD
used for colors
RgbF
used for colors
Vec2d
used for direction vectors
Vec3d
used for direction vectors