Top Related Projects
Unity Graphics - Including Scriptable Render Pipeline
Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
Physically-Based Rendering in glTF 2.0 using WebGL
Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
Real-Time Rendering Framework
MaterialX is an open standard for the exchange of rich material and look-development content across applications and renderers.
Quick Overview
The wdas/brdf repository is a collection of BRDF (Bidirectional Reflectance Distribution Function) models and measurements. It provides a comprehensive set of tools and data for researchers and developers working on physically-based rendering and material appearance modeling in computer graphics.
Pros
- Extensive collection of BRDF models and measured data
- Well-documented and organized codebase
- Supports multiple programming languages (C++, Python)
- Includes visualization tools for BRDF analysis
Cons
- Limited recent updates to the repository
- Some dependencies may be outdated
- Lack of comprehensive examples for all supported models
- May require advanced knowledge of computer graphics and material modeling
Code Examples
- Loading and evaluating a BRDF model:
#include "brdf/brdf.h"
int main() {
BRDF* brdf = BRDF::load("models/ggx.brdf");
Vec3f wi(0.5, 0.5, 0.5);
Vec3f wo(0.0, 0.0, 1.0);
Vec3f result = brdf->eval(wi, wo);
std::cout << "BRDF value: " << result << std::endl;
delete brdf;
return 0;
}
- Visualizing a BRDF slice:
import brdf
import matplotlib.pyplot as plt
model = brdf.load("models/cook-torrance.brdf")
theta_h = 0.5
phi_d = 0.0
values = model.compute_slice(theta_h, phi_d)
plt.plot(values)
plt.title("BRDF Slice")
plt.xlabel("Phi")
plt.ylabel("BRDF Value")
plt.show()
- Fitting measured data to a BRDF model:
#include "brdf/fitter.h"
int main() {
MeasuredBRDF* measured = MeasuredBRDF::load("data/measured.dat");
BRDFModel* model = new CookTorranceBRDF();
BRDFFitter fitter(measured, model);
fitter.fit();
std::cout << "Fitted parameters: " << model->getParameters() << std::endl;
delete measured;
delete model;
return 0;
}
Getting Started
-
Clone the repository:
git clone https://github.com/wdas/brdf.git cd brdf
-
Build the project:
mkdir build && cd build cmake .. make
-
Run the examples:
./bin/brdf_viewer python examples/plot_brdf.py
-
Include the library in your project:
#include "brdf/brdf.h" // Use BRDF models and utilities in your code
Competitor Comparisons
Unity Graphics - Including Scriptable Render Pipeline
Pros of Graphics
- More comprehensive graphics framework with broader functionality
- Active development and regular updates
- Larger community and ecosystem for support and resources
Cons of Graphics
- Steeper learning curve due to complexity
- Potentially heavier resource requirements
- Tied to Unity engine, less flexible for standalone use
Code Comparison
BRDF (Disney BRDF implementation):
float3 BRDF( float3 L, float3 V, float3 N, float3 X, float3 Y )
{
float NdotL = dot(N, L);
float NdotV = dot(N, V);
if (NdotL < 0 || NdotV < 0) return float3(0,0,0);
// ... (additional calculations)
}
Graphics (Unity's Standard BRDF):
half4 BRDF1_Unity_PBS (half3 diffColor, half3 specColor, half oneMinusReflectivity, half smoothness,
float3 normal, float3 viewDir,
UnityLight light, UnityIndirect gi)
{
float perceptualRoughness = SmoothnessToPerceptualRoughness (smoothness);
float3 halfDir = Unity_SafeNormalize (float3(light.dir) + viewDir);
// ... (additional calculations)
}
Both repositories focus on BRDF implementations, but Graphics offers a more extensive framework for various graphics-related tasks within the Unity ecosystem. BRDF is more specialized and lightweight, focusing specifically on Disney's BRDF model.
Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
Pros of Filament
- More comprehensive rendering engine with broader functionality
- Active development and regular updates
- Extensive documentation and examples
Cons of Filament
- Larger codebase and steeper learning curve
- May be overkill for simple BRDF implementations
- Potentially higher resource requirements
Code Comparison
BRDF:
float D_GGX(float roughness, float NdotH) {
float alpha = roughness * roughness;
float alpha2 = alpha * alpha;
float denom = NdotH * NdotH * (alpha2 - 1.0) + 1.0;
return alpha2 / (M_PI * denom * denom);
}
Filament:
float D_GGX(float NoH, float roughness) {
float a = NoH * roughness;
float k = roughness / (1.0 - NoH * NoH + a * a);
return k * k * (1.0 / PI);
}
Summary
BRDF focuses specifically on Bidirectional Reflectance Distribution Functions, while Filament is a full-featured physically-based rendering engine. BRDF is simpler and more specialized, making it easier to understand and implement for specific BRDF-related tasks. Filament offers a more complete rendering solution but requires more time to learn and integrate. The choice between them depends on the project's scope and requirements.
Physically-Based Rendering in glTF 2.0 using WebGL
Pros of glTF-Sample-Viewer
- Focuses on rendering and visualizing 3D models in glTF format
- Provides a comprehensive viewer with various rendering options and features
- Actively maintained with regular updates and community support
Cons of glTF-Sample-Viewer
- Limited to glTF format, not as versatile for general BRDF analysis
- More complex setup and usage compared to the simpler BRDF viewer
- Larger codebase and dependencies, potentially harder to integrate into other projects
Code Comparison
glTF-Sample-Viewer (JavaScript):
const viewer = new GltfView(canvas, options);
viewer.loadGltf(gltfFile).then(() => {
viewer.renderFrame();
});
BRDF (Python):
brdf = BRDF(theta_h, theta_d, phi_d)
brdf.load_merl(filename)
brdf.plot()
The glTF-Sample-Viewer code demonstrates loading and rendering a 3D model, while the BRDF code shows loading and plotting BRDF data. glTF-Sample-Viewer is more focused on interactive 3D visualization, whereas BRDF is tailored for analyzing and visualizing BRDF data specifically.
Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
Pros of pbrt-v3
- Comprehensive physically-based rendering system with extensive documentation
- Supports a wide range of rendering techniques and algorithms
- Active development and community support
Cons of pbrt-v3
- Steeper learning curve due to its complexity
- Larger codebase, which may be overwhelming for beginners
- Focused on offline rendering, not real-time applications
Code Comparison
BRDF (C++):
vec3 BRDF::eval(const vec3& V, const vec3& L, const vec3& N) const {
vec3 H = normalize(V + L);
float NdotL = max(dot(N, L), 0.0f);
float NdotV = max(dot(N, V), 0.0f);
float NdotH = max(dot(N, H), 0.0f);
return diffuse + specular * (m_a + m_b * pow(NdotH, m_c)) / (NdotL * NdotV);
}
pbrt-v3 (C++):
Spectrum MicrofacetReflection::f(const Vector3f &wo, const Vector3f &wi) const {
float cosThetaO = AbsCosTheta(wo), cosThetaI = AbsCosTheta(wi);
Vector3f wh = wi + wo;
if (cosThetaI == 0 || cosThetaO == 0) return Spectrum(0.);
if (wh.x == 0 && wh.y == 0 && wh.z == 0) return Spectrum(0.);
wh = Normalize(wh);
Spectrum F = fresnel->Evaluate(Dot(wi, wh));
return R * distribution->D(wh) * distribution->G(wo, wi) * F /
(4 * cosThetaI * cosThetaO);
}
Real-Time Rendering Framework
Pros of Falcor
- More comprehensive rendering framework with extensive features
- Active development and regular updates
- Supports modern graphics APIs like DirectX 12 and Vulkan
Cons of Falcor
- Steeper learning curve due to its complexity
- Larger codebase and potentially higher resource requirements
- Primarily focused on real-time rendering, which may not be suitable for all use cases
Code Comparison
BRDF (Python):
def beckmann(m, cos_theta):
cos2 = cos_theta * cos_theta
sin2 = 1.0 - cos2
tan2 = sin2 / cos2
return math.exp(-tan2 / (m * m)) / (math.pi * m * m * cos2 * cos2)
Falcor (C++):
float4 evalBRDF(ShadingData sd, float3 wo, float3 wi)
{
float3 h = normalize(wo + wi);
float NoH = dot(sd.N, h);
float NoV = dot(sd.N, wo);
float NoL = dot(sd.N, wi);
return evalMicrofacetBRDF(sd, NoV, NoL, NoH, h);
}
The BRDF repository focuses on a specific BRDF implementation, while Falcor provides a more comprehensive rendering framework with various BRDF models and additional features. BRDF is simpler and easier to understand, while Falcor offers more flexibility and advanced rendering capabilities at the cost of increased complexity.
MaterialX is an open standard for the exchange of rich material and look-development content across applications and renderers.
Pros of MaterialX
- Broader scope, covering material definitions beyond just BRDF
- More active development and community support
- Designed for cross-platform compatibility and integration with various DCC tools
Cons of MaterialX
- More complex and potentially steeper learning curve
- Larger codebase, which may be overkill for simple BRDF implementations
- Requires more setup and configuration for basic usage
Code Comparison
MaterialX example (defining a simple material):
<?xml version="1.0"?>
<materialx version="1.38">
<standard_surface name="example_material" type="material">
<input name="base_color" type="color3" value="0.8, 0.2, 0.2" />
<input name="specular_roughness" type="float" value="0.3" />
</standard_surface>
</materialx>
BRDF example (using the library):
#include "brdf/brdf.h"
BRDF::Params params;
params.roughness = 0.3f;
params.baseColor = Vec3f(0.8f, 0.2f, 0.2f);
float result = BRDF::eval(params, incomingLight, outgoingLight);
The MaterialX example demonstrates its XML-based material definition, while the BRDF example shows direct C++ usage for BRDF evaluation.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
The Disney BRDF Explorer is an application that allows the development and analysis of bidirectional reflectance distribution functions (BRDFs). It can load and plot analytic BRDF functions (coded as snippets of OpenGL GLSL programs), measured material data from the MERL database, and anisotropic measured material data from MIT CSAIL.
Most of the application should be (hopefully) self explanatory, so the goal here is to document the less obvious bits of usage, as well as providing some useful info.
WHICH BRDF(S) YOU'RE SEEING
In the BRDF Parameters window, each BRDF has a colored background. The plotted values (for the 3D, polar, and cartesian plots) are drawn in the corresponding colors.
In the Image Slice, Lit Object, and Lit Sphere windows, you're seeing the first (topmost in the parameters window) enabled BRDF.
NAVIGATING POLAR/CARTESIAN PLOTS
Use the left mouse button to pan around in the plot. Right dragging will zoom in/out around the centered location. Double-clicking anywhere resets the view to the default zoom and location. For cartesian plots, Control+left drag stretches ONLY the x-axis, while Control+right drag stretches only the y-axis.
NAVIGATING 3D PLOTS
Left-drag spins around the origin (there's no current way to change this). Right drag zooms in and out. Double clicking resets to the default view.
PARAMETER SLIDERS
Parameters sliders (a slider plus a text entry box) are all over the application. To reset one to its default value, Control+Click in the text box.
SOLOING BRDFS
Pressing the "solo" (circle) button for a given BRDF makes ONLY that BRDF visible, hiding all the others. The "Solo this BRDF's color channels" button also hides all the other channels, but shows a separate plot for the red, green, and blue channels (in their respective colors). Click the solo button again to exit solo mode.
LIT SPHERE VIEW
You can drag the left mouse button on the surface of the sphere to change the incident angle. If "Double Theta" is enabled, the specular highlight will track the position of the mouse.
LIT OBJECT VIEW
The lit object view allows an arbitrary object to be viewed under with a directional light from the incident direction (in "No IBL" mode) or under illumination from an arbitrary environment map. Left dragging rotates the object; right dragging zooms the object; Control+left dragging rotates the environment probe.
The combo box lets you choose "No IBL", "IBL: No IS" (quasirandom sampling from the environment map with no importance sampling) and "IBL: IBL IS" (importance sampling from the IBL). Multiple importance sampling is planned but not implemented. The "Keep Sampling" mode, when enabled, progressively refines the image until 4096 samples have been applied.
The buttons allow changing out the object (any OBJ should work) and the environment probe (which must be in ptex format).
ALBEDO VIEW
Albedo computation by brute force sampling proved too expensive to do interactively, so the application can use several different sampling strategies to compute the albedo. Use the combo box on the right to choose between these sampling strategies. The Resample x10 button adds more samples to that view of the graph.
IMAGE SLICE VIEW
An "image slice" is an alternative way of looking at BRDF data that we have found helpful at Disney. Along the x-axis, the half angle is varied from zero to 90 degrees; along the y-axis, the difference angle is varied from 0 to 90 degrees.
BRDF FILES
.brdf files consist of a set of parameters and a BRDF function written in GLSL. At runtime, the application creates UI elements for each parameter, and creates shaders for different views that incorporate the GLSL function.
The BRDF function looks like this (this example is for a lambertian BRDF):
::begin shader vec3 BRDF( vec3 L, vec3 V, vec3 N, vec3 X, vec3 Y ) { return vec3(reflectance / 3.14159265); } ::end shader
Anything valid in GLSL can go between "::begin shader" and "::end shader" as long as it's valid GLSL.
The application allows float, color, and boolean parameters. The float parameters have the form float [name] [min val] [max val] [default val] for example: float reflectance 0.0 1.0 1.0
Boolean parameters have the form bool [name] [default], where default is 0 or 1 (keywords such as true and false aren't recognized) for example: bool hasDiffuse 0
Color parameters have the form color [name] [defaultR] [defaultG] [defaultB], where defaultR/G/B are in [0..1] for example: color diffuseColor 0.5 0.1 1.0
Parameters are passed into the resulting GLSL shaders as uniforms of the same name (so parameter names must be valid GLSL variable names, although the application doesn't enforce this). Float parameters come in as uniform floats, color parameters as vec3s, and boolean parameters as bools. The application declares them when constructing shaders, so your GLSL BRDF functions can refer to them knowing that they'll exist and have the proper values at runtime.
LIGHT PROBE ATTRIBUTION
HDR Light Probe Images Copyright 1998 courtesy of Paul Debevec, www.debevec.org, used with permission.
Please see:
Paul Debevec. Rendering Synthetic Objects Into Real Scenes: Bridging Traditional and
Image-Based Graphics With Global Illumination and High Dynamic Range Photography.
Proceedings of SIGGRAPH 98, Computer Graphics Proceedings, Annual Conference Series,
July 1998, pp. 189-198.
WHERE TO GET MEASURED BRDF DATA
MERL data can be requested here: http://www.merl.com/brdf/
MIT CSAIL data is here: http://people.csail.mit.edu/addy/research/brdf/
BUILD INSTRUCTIONs
To install brdf run:
make install [prefix=<some-directory>]
If you do not specify "prefix=..." then brdf will be installed into the current directory.
Top Related Projects
Unity Graphics - Including Scriptable Render Pipeline
Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
Physically-Based Rendering in glTF 2.0 using WebGL
Source code for pbrt, the renderer described in the third edition of "Physically Based Rendering: From Theory To Implementation", by Matt Pharr, Wenzel Jakob, and Greg Humphreys.
Real-Time Rendering Framework
MaterialX is an open standard for the exchange of rich material and look-development content across applications and renderers.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot