GGX GTR conversion

Ā 

Step-by-Step Breakdown of Term Transformation

In the anisotropic GGX distribution formula: \[ \] we focus on the denominator inside the parentheses, which contains the anisotropic roughness terms \( \alpha_x \) and \( \alpha_y \). This is where the anisotropy is defined and where we see how the GGX formula can be related to GTR.

Rewriting the GGX Term with Trigonometric Components

  1. Understanding the Anisotropy Terms: In GGX, anisotropy is expressed by separating the contributions of the roughness along the tangent and bitangent directions: \[ \] Here:
      • \( \phi_m \) is the azimuthal angle of the halfway vector \( \omega_m \).
      • \( \alpha_x \) and \( \alpha_y \) represent the roughness parameters along the tangent (\( x \)-axis) and bitangent (\( y \)-axis) directions, respectively.
  1. Relation to Tangent and Bitangent Vectors: In the GTR form, rather than using trigonometric components, we use the actual dot products of the halfway vector \( h \) with the tangent \( t \) and bitangent \( b \): \[ \left(\frac{t \cdot h}{\alpha_t}\right)^2 + \left(\frac{b \cdot h}{\alpha_b}\right)^2 \] where:
      • \( \alpha_t \) and \( \alpha_b \) are the GTR roughness parameters (analogous to \( \alpha_x \) and \( \alpha_y \) in GGX).
      • \( t \cdot h \) and \( b \cdot h \) represent the projections of \( h \) onto the tangent and bitangent directions, respectively.
  1. Substitution via Trigonometric Identities: In GGX, the expressions involving \( \cos^2 \phi_m \) and \( \sin^2 \phi_m \) essentially correspond to projecting the roughness along the tangent and bitangent directions. We can rewrite these as: \[ \cos \phi_m = \frac{t \cdot h}{\| t \| \| h \|} \quad \text{and} \quad \sin \phi_m = \frac{b \cdot h}{\| b \| \| h \|} \] Assuming \( t \) and \( b \) are unit vectors, we get: \[ \cos^2 \phi_m = (t \cdot h)^2 \quad \text{and} \quad \sin^2 \phi_m = (b \cdot h)^2 \]
  1. Replacing the Trigonometric Formulation with Dot Products: Substituting back into the GGX expression, we can rewrite: \[ \frac{\cos^2 \phi_m}{\alpha_x^2} + \frac{\sin^2 \phi_m}{\alpha_y^2} \approx \frac{(t \cdot h)^2}{\alpha_t^2} + \frac{(b \cdot h)^2}{\alpha_b^2} \] This matches the form used in GTR, where anisotropy is defined directly in terms of the dot products with tangent and bitangent vectors.

Summary

The transformation from GGX to GTR anisotropy terms essentially involves moving from a trigonometric representation in terms of \( \cos^2 \phi_m \) and \( \sin^2 \phi_m \) to a geometric projection in terms of \( t \cdot h \) and \( b \cdot h \). Both approaches model anisotropy, but GTR's dot product form provides a more direct geometric interpretation, making it easier to define anisotropic roughness along arbitrary directions.
So, in summary:
  • GGX Anisotropic uses trigonometric functions of azimuthal angles.
  • GTR Anisotropic reinterprets these in terms of direct dot products with tangent and bitangent vectors, making it effectively a more generalized form.
This is the core transformation that allows GGX to be expressed in the GTR form.
Ā 
Ā 
Ā 
Letā€™s go over the components in the GGX and GTR models using \( \omega_m \) as the microfacet normal vector, and clarify each angle and term.

Terms and Angles in GGX and GTR Models

  1. Surface Normal \( N \):
      • Definition: The normal of the macroscopic surface at the point where reflection or refraction is being calculated.
      • Use: Serves as a reference direction for other vectors, particularly \( \omega_m \), \( V \), and \( L \).
      • Source: Standard in physically-based rendering; both GGX and GTR models rely on \( N \) to define the angles of incidence and reflection.
  1. Microfacet Normal \( \omega_m \):
      • Definition: The normal vector for individual microfacets, which may differ from the surface normal \( N \).
      • Use: In both GGX and GTR models, \( \omega_m \) is central to the distribution function, as it defines the orientation of each microfacet relative to light and view directions.
      • Source: From Cook-Torrance microfacet theory; Walter et al. (2007) introduced the GGX model with \( \omega_m \) as the microfacet normal.
  1. Halfway Vector \( h \) (sometimes used in other contexts, but not here):
      • Definition: The normalized vector halfway between the light vector \( L \) and view vector \( V \): \[ h = \frac{L + V}{\| L + V \|} \]
      • Use: In microfacet theory, the halfway vector represents the orientation of a facet that would ideally reflect light toward the viewer. However, in these equations, we stick to \( \omega_m \) as the microfacet normal without additional halfway vector notation.
      • Source: Common in physically-based rendering but less emphasized in GTR since we focus on \( \omega_m \).
  1. View Vector \( V \) and Light Vector \( L \):
      • Definition: \( V \) is the direction vector from the surface point to the camera (or observer), while \( L \) is the direction from the surface point to the light source.
      • Use: Essential for calculating the angles between \( \omega_m \), \( V \), and \( L \), which are used in defining shadowing and masking functions.
      • Source: Widely used in physically-based shading models.
  1. Tangent \( T \) and Bitangent \( B \):
      • Definition: \( T \) and \( B \) are orthogonal vectors defining the surface's tangent space, where \( T \) typically aligns with the primary anisotropic direction.
      • Use: Both GGX and GTR use \( T \) and \( B \) to model anisotropic roughness by defining roughness parameters \( \alpha_x \) and \( \alpha_y \) (or \( \alpha_t \) and \( \alpha_b \) in GTR) along these axes.
      • Source: Anisotropic extensions introduced in Burley (2012)'s work on anisotropic GGX.
  1. Azimuthal Angle \( \phi_m \) (associated with \( \omega_m \)):
      • Definition: The angle between the projection of \( \omega_m \) onto the \( T \)-\( B \) plane and the tangent vector \( T \).
      • Use: In GGX, anisotropic roughness is often expressed in terms of \( \cos \phi_m \) and \( \sin \phi_m \), as they determine the orientation of \( \omega_m \) relative to \( T \) and \( B \).
      • Source: Standard in anisotropic GGX; Burley (2012) uses \( \phi_m \) to account for directional roughness.
  1. Inclination Angle \( \theta_m \) (associated with \( \omega_m \)):
      • Definition: The angle between \( \omega_m \) (the microfacet normal) and the surface normal \( N \).
      • Use: In both GGX and GTR models, \( \theta_m \) determines the "tilt" of \( \omega_m \) relative to the surface normal, affecting the probability of a facet reflecting light in a particular direction.
      • Source: Integral in microfacet theory, where \( \theta_m \) defines the steepness of microfacet orientations.

Conversion Between GGX and GTR Anisotropic Models

In GGX, anisotropic roughness is defined along the tangent and bitangent directions with separate roughness parameters \( \alpha_x \) and \( \alpha_y \), which control how stretched or circular the microfacet distribution is. These directions correspond to the surfaceā€™s tangent (\( T \)) and bitangent (\( B \)).
In the GTR model, anisotropic roughness terms are often labeled \( \alpha_t \) and \( \alpha_b \), but they work similarly to GGX's \( \alpha_x \) and \( \alpha_y \). The GTR anisotropic distribution function is often represented as: \[ D_{\text{aniso}}(\omega_m, \alpha) = \frac{1}{\pi \alpha_t \alpha_b} \frac{1}{\left( \left(\frac{T \cdot \omega_m}{\alpha_t}\right)^2 + \left(\frac{B \cdot \omega_m}{\alpha_b}\right)^2 + (N \cdot \omega_m)^2 \right)^2} \] where:
  • \( T \cdot \omega_m \) and \( B \cdot \omega_m \) are the projections of the microfacet normal \( \omega_m \) onto the tangent and bitangent directions.
  • \( N \cdot \omega_m \) is the projection onto the surface normal direction, representing the alignment of \( \omega_m \) with \( N \).

Key Differences in Calculation

  • In GGX, the inclination angle \( \theta_m \) is used to calculate the roughness, while the azimuthal angle \( \phi_m \) controls anisotropy by introducing \( \cos \phi_m \) and \( \sin \phi_m \) terms for tangent-bitangent alignment.
  • In GTR, the anisotropy is instead represented by the direct projections \( T \cdot \omega_m \) and \( B \cdot \omega_m \), which simplifies the calculations by avoiding explicit trigonometric functions like \( \cos \phi_m \) and \( \sin \phi_m \).

Summary Table of Terms

Term
GGX Definition
GTR Definition
Surface Normal \( N \)
Global surface normal
Same as GGX
Microfacet Normal \( \omega_m \)
Normal of each microfacet
Same as GGX
Tangent \( T \)
Primary direction of anisotropy
Primary direction of anisotropy
Bitangent \( B \)
Perpendicular to tangent
Perpendicular to tangent
\( \alpha_x, \alpha_y \)
Roughness parameters along \( T, B \)
Roughness parameters \( \alpha_t, \alpha_b \)
Inclination Angle \( \theta_m \)
Between \( \omega_m \) and \( N \)
Between \( \omega_m \) and \( N \), projected onto \( T, B \)
Azimuthal Angle \( \phi_m \)
Angle around \( N \) relative to \( T, B \)
Converted to dot products \( T \cdot \omega_m, B \cdot \omega_m \)

Sources

  • Walter et al. (2007): Introduced GGX with isotropic roughness in microfacet theory, defining \( \omega_m \) as the microfacet normal.
  • Burley (2012): Developed anisotropic GGX, which leverages \( T \) and \( B \) for modeling anisotropic roughness through \( \alpha_x \) and \( \alpha_y \).
  • GTR: Generalized from GGX to handle a wider range of roughness distributions, simplifying anisotropic terms by relying on direct dot products with tangent and bitangent.
This framework should clarify each component and term in the GGX and GTR models, and highlight the GTR modelā€™s approach to anisotropy by directly using projections onto the tangent and bitangent vectors, making the derivation from GGX to GTR more intuitive.
Ā 
Ā 
Ā 

GGX quadratic form

To integrate the matrix form of roughness into the anisotropic GGX \( D \)-term, we need to understand how the matrix representation relates to the surface normal distribution function (NDF) of the anisotropic GGX model. The \( D \)-term for the GGX model describes the distribution of microfacets with respect to the half-vector \( \omega_h \) and the surface normal \( n \).

Recap of the Anisotropic GGX Distribution Function

For an anisotropic GGX distribution, the \( D \)-term is typically expressed as: \[ \] where:
  • \( \alpha_t \) and \( \alpha_b \) are the roughness parameters along the tangent and bitangent directions, respectively.
  • \( \theta_h \) and \( \phi_h \) are the polar and azimuthal angles of the half-vector \( \omega_h \) in the tangent-bitangent-normal (TBN) frame.
In a matrix representation, the roughness is no longer isotropic along fixed \( \alpha_t \) and \( \alpha_b \) values but is represented by a matrix \( A \) that varies based on the orientation. This allows us to define the roughness anisotropically in a rotated frame.

Using the Roughness Matrix in the GGX \( D \)-Term

With the roughness represented by a matrix \( A \), we can replace the scalar roughness terms \( \alpha_t \) and \( \alpha_b \) in the GGX formula with an elliptical quadratic form. In particular, we replace the term: \[ \] with a matrix expression that involves the roughness matrix \( A \).
Given the roughness matrix \( A \): \[ \] we can use this matrix to model the anisotropic distribution by computing a quadratic form.

Quadratic Form with Matrix \( A \)

To incorporate the matrix \( A \) into the \( D \)-term, you can express the anisotropy as a quadratic form that describes the ellipse shape of the microfacet distribution. This is done by computing: \[ \] where represents the projection of the half-vector in the tangent-bitangent plane. The \( D \)-term then becomes: \[ \]

Steps to Compute the Anisotropic GGX \( D \)-Term with Matrix Representation

  1. Compute the Roughness Matrix \( A \):
      • This gives \( \).
  1. Invert the Matrix \( A \):
      • Calculate \( A^{-1} \) since it is needed in the quadratic form. For a 2x2 matrix \( A = \begin{pmatrix} a & c \\ c & b \end{pmatrix} \), the inverse is: \[ \]
  1. Project \( \omega_h \) into the Tangent-Bitangent Plane:
      • Let \( \) be the projection of the half-vector in the tangent-bitangent plane.
  1. Compute the Quadratic Form:
      • Evaluate \( \), which expands to: \[ \]
  1. Compute the Anisotropic GGX \( D \)-Term:
      • Substitute this expression into the GGX \( D \)-term formula: \[ \]
      • Here, \( \), and \( \) represents the elliptical distribution shape, controlled by the rotated roughness values \( \alpha_t \) and \( \alpha_b \) through the matrix \( A \).

Summary

The matrix \( A \) enables a more flexible representation of the anisotropic GGX distribution by aligning the roughness parameters with the rotated microfacet frame. By using the quadratic form \( \omega_h^T A^{-1} \omega_h \) in the \( D \)-term formula, we can accurately represent anisotropic roughness that is oriented according to \( R_\gamma \), effectively modeling the directional distribution of microfacets on the surface. This approach allows the GGX model to capture a wider range of surface anisotropy.

Matrix Form to Expanded Formula

The code snippet provided directly implements the anisotropic GGX \( D \)-term using the roughness parameters \( a^2 \), \( b^2 \), and \( c^2 \), corresponding to the squared elements in the roughness matrix. Here are the key components and differences between the mathematical form I described and this code implementation:
  1. Quadratic Form Expansion:
      • The code uses a breakdown of the quadratic form using the tangent (\( T \)) and bitangent (\( B \)) components of the half-vector \( \omega_h \).
      • In the formula I provided, the quadratic form is written as \( \omega_h^T A^{-1} \omega_h \), which corresponds to the expression: \[ \frac{a_sqr \cdot ToH^2 + 2 \cdot c_sqr \cdot ToH \cdot BoH + b_sqr \cdot BoH^2}{det_2} \] where \( ToH = \omega_h \cdot T \) and \( BoH = \omega_h \cdot B \).
  1. Determinant Calculation:
      • The code snippet computes \( \text{det}_2 = a_sqr \cdot b_sqr - c_sqr \cdot c_sqr \) to ensure that \( A^{-1} \) exists by avoiding a zero determinant. The value is clamped at a small positive minimum to avoid division by zero. This clamping step isnā€™t explicitly mentioned in the mathematical formula but is essential in practical implementations to maintain numerical stability.
  1. Denominator Computation:
      • The denominator in the code is a direct translation of the GGX \( D \)-term formula: \[ \text{denom} = \sqrt{\text{det}_2} \cdot \left( \frac{a_sqr \cdot ToH^2 + 2 \cdot c_sqr \cdot ToH \cdot BoH + b_sqr \cdot BoH^2}{\text{det}_2} + NdotH^2 \right)^2 \]
      • This form closely matches the denominator structure in the GGX \( D \)-term formula, where the expression inside the parentheses represents the anisotropic distribution along the \( T \)- and \( B \)-axes.
      • The code includes a clamping operation for the denominator (torch.clamp(denom, min=Renderer.min_ndf_denom)) to avoid extremely small values, which isnā€™t in the mathematical form but is a common numerical safeguard in rendering code.
  1. Normalization Factor:
      • The formula ends with a division by Renderer.oneOverPi (a constant for \( 1/\pi \)), which normalizes the distribution as per GGX.

Summary of Differences

  • Quadratic Form: The code expands the quadratic form directly using \( a^2 \), \( b^2 \), and \( c^2 \) and components of the half-vector \( \omega_h \) along \( T \) and \( B \).
  • Numerical Stability: The code includes clamping for both the determinant and denominator, which is crucial for practical implementations.
  • Normalization: The code includes normalization with \( 1/\pi \), which matches the GGX distribution requirements.
Essentially, the code directly implements the expanded quadratic form of the anisotropic GGX distribution, carefully handling edge cases like small determinants to ensure numerical stability.

omega_h^T

The quadratic form used here, \( \omega_h^Tomega_h^T A^{-1} \omega_h \), often appears in the context of anisotropic microfacet BRDFs and can be traced back to the formulation of the anisotropic GGX \( D \)-term. This term models the distribution of microfacet orientations on a surface for anisotropic materials. One well-known paper introducing this approach is:
  • "Microfacet Models for Refraction through Rough Surfaces" by Walter et al. (2007), which expanded microfacet models, including GGX, and introduced anisotropic terms.
I'll walk through the equivalence in each step between the matrix form and the code, showing how they represent the same anisotropic GGX \( D \)-term.

Step-by-Step Derivation of Equivalence

  1. Matrix Form of the Roughness: In anisotropic GGX, the microfacet normal distribution function (NDF) is defined by using a roughness matrix \( A \) that controls the distribution across the tangent (\( T \)) and bitangent (\( B \)) directions.
    1. We start by defining the roughness matrix \( A \) in the principal directions: \[ A = R_\gamma \begin{pmatrix} \alpha_t^2 & 0 \\ 0 & \alpha_b^2 \end{pmatrix} R_\gamma^T \] where:
      • \( \alpha_t \) and \( \alpha_b \) represent the roughness parameters in the tangent and bitangent directions.
      • \( R_\gamma \) is a rotation matrix aligning \( A \) with the local frame.
  1. Quadratic Form for \( D \)-Term: The GGX \( D \)-term is derived by measuring the alignment between the half-vector \( \omega_h \) and the microfacet distribution's principal directions. This alignment is expressed as: \[ \omega_h^T A^{-1} \omega_h \] Here, \( A^{-1} \) is the inverse of the roughness matrix \( A \), and this quadratic form represents the ellipsoidal distribution in the anisotropic GGX model. Expanding this with the components of \( A^{-1} \), we get: \[ \omega_h^T A^{-1} \omega_h = \frac{a^2 \cdot ToH^2 + 2 \cdot c^2 \cdot ToH \cdot BoH + b^2 \cdot BoH^2}{a^2 b^2 - c^4} \] where:
      • \( ToH = \omega_h \cdot T \) (dot product with tangent),
      • \( BoH = \omega_h \cdot B \) (dot product with bitangent),
      • \( a^2, b^2, \) and \( c^2 \) are elements derived from the roughness parameters in \( A \).
  1. Code Derivation: Now, let's break down the code step-by-step to show it matches the matrix form.
    1. det_2 = torch.clamp(a_sqr * b_sqr - c_sqr * c_sqr, min=1e-15)
      This line computes \( \text{det}_2 = a^2 b^2 - c^4 \), which corresponds to the determinant of the roughness matrix \( A \).
      denom = torch.sqrt(det_2) * torch.pow( (a_sqr * ToH * ToH / det_2 + 2 * c_sqr * ToH * BoH / det_2 + b_sqr * BoH * BoH / det_2) + NdotH * NdotH, 2.0)
      • a_sqr * ToH * ToH / det_2: Matches \( \frac{a^2 \cdot ToH^2}{a^2 b^2 - c^4} \).
      • 2 * c_sqr * ToH * BoH / det_2: Matches \( \frac{2 \cdot c^2 \cdot ToH \cdot BoH}{a^2 b^2 - c^4} \).
      • b_sqr * BoH * BoH / det_2: Matches \( \frac{b^2 \cdot BoH^2}{a^2 b^2 - c^4} \).
      These terms correspond exactly to the matrix form expansion, showing that the code snippet implements the quadratic form of \( \omega_h^T A^{-1} \omega_h \) explicitly.
  1. Normalization: Finally, the normalization by Renderer.oneOverPi ensures the distribution function integrates to one, completing the anisotropic GGX \( D \)-term.

Reference for Further Details

To explore the mathematical background in detail, you might consult the anisotropic GGX model described in Walter et al. (2007), as they go through microfacet-based BRDF models with anisotropic terms.
This comparison shows that the matrix form and the code are indeed equivalent, implementing the anisotropic GGX \( D \)-term for BRDF models with anisotropic roughness.
Ā 

Microfacet normal

Yes, exactly! The microfacet normal is more of a conceptual tool than an actual map or texture. Itā€™s an imaginary normal that exists to help approximate the roughness and fine-grained detail of the surface.
Hereā€™s a quick rundown:
  1. Roughness Map Role:
      • The roughness map provides the surface roughness value at each pixel, controlling the spread or ā€œdistributionā€ of microfacet normals. Higher roughness values make the microfacet normals more varied and widely distributed, leading to more diffuse (scattered) reflections.
      • This map essentially drives the shape of the distribution of microfacet normals, like the GGX or Beckmann distributions.
  1. Microfacet Normal as a Computed Concept:
      • The microfacet normal \(\omega_h\) is indeed calculated on the fly during rendering for each pixel and for each incoming light direction. Itā€™s typically set as the halfway vector between the incoming light direction and the view direction (\(\omega_h = \frac{\omega_i + \omega_o}{\|\omega_i + \omega_o\|}\)).
      • This imaginary normal lets the shading model simulate how these tiny, ā€œimaginaryā€ microfacets reflect light based on the roughness.
  1. Distribution-Based Calculation:
      • The BRDF then calculates a distribution function (like GGX or Beckmann) around \(\omega_h\) based on the roughness map. This function gives the probability of finding microfacet normals oriented towards \(\omega_h\), creating the look of roughness or smoothness at render time.
In practice, this approach provides the fine detail we see in glossy and rough reflections, controlled by the roughness map and the dynamic computation of \(\omega_h\). This balance between roughness and the microfacet normal distribution is what allows surfaces to look realistically rough or smooth under various lighting conditions.
Ā