Various BSDF functions available to shader writers. More...
Data Structures | |
struct | AtBSDFLobeInfo |
BSDF lobe information. More... | |
struct | AtBSDFLobeSample |
BSDF lobe sample. More... | |
struct | AtBSDFMethods |
BSDF function table. More... | |
Macros | |
#define | AI_BSDF_EXPORT_METHODS(tag) |
BSDF methods exporter. More... | |
#define | bsdf_init |
Initialize BSDF when before it is used for the first time. More... | |
#define | bsdf_eval |
Evaluate BSDF for the given incoming light direction. More... | |
#define | bsdf_sample |
Sample BSDF for an incoming light direction, and evaluate BSDF. More... | |
#define | bsdf_albedo |
Compute BSDF albedo for AOVs and importance sampling (optional method) More... | |
#define | bsdf_merge |
Merge BSDF with another BSDF of the same type (optional method) More... | |
#define | bsdf_interior |
Return volume closures describing the interior of the object. More... | |
Typedefs | |
typedef uint32_t | AtBSDFLobeMask |
BSDF lobe bitmask. | |
Enumerations | |
enum | AtBSDFLobeFlags { AI_BSDF_LOBE_SINGULAR = 0x01 , AI_BSDF_LOBE_WAVELENGTH_SAMPLE = 0x02 , AI_BSDF_LOBE_EXIT_BACKGROUND = 0x04 , AI_BSDF_LOBE_EXIT_WHITE = 0x08 } |
BSDF Lobe flags. More... | |
Functions | |
AI_DEVICE | AtBSDFLobeSample::AtBSDFLobeSample (AtRGB weight, float reverse_pdf, float pdf) |
AI_DEVICE | AtBSDFLobeSample::AtBSDFLobeSample (AtRGB eval) |
Variables | |
uint8_t | AtBSDFLobeInfo::ray_type |
uint8_t | AtBSDFLobeInfo::flags |
AtString | AtBSDFLobeInfo::label |
AtRGB | AtBSDFLobeSample::weight |
float | AtBSDFLobeSample::reverse_pdf |
float | AtBSDFLobeSample::pdf |
int | AtBSDFMethods::version |
void(* | AtBSDFMethods::Init )(const AtShaderGlobals *sg, AtBSDF *bsdf) |
AtBSDFLobeMask(* | AtBSDFMethods::Eval )(const AtBSDF *bsdf, const AtVector &wi, const AtBSDFLobeMask lobe_mask, const bool need_pdf, AtBSDFLobeSample out_lobes[]) |
AtBSDFLobeMask(* | AtBSDFMethods::Sample )(const AtBSDF *bsdf, const AtVector rnd, const float wavelength, const AtBSDFLobeMask lobe_mask, const bool need_pdf, AtVectorDv &out_wi, int &out_lobe_index, AtBSDFLobeSample out_lobes[]) |
AtRGB(* | AtBSDFMethods::Albedo )(const AtBSDF *bsdf, const AtShaderGlobals *sg, const AtBSDFLobeMask lobe_mask) |
bool(* | AtBSDFMethods::Merge )(AtBSDF *bsdf, const AtBSDF *other_bsdf) |
AtClosureList(* | AtBSDFMethods::Interior )(const AtShaderGlobals *sg, AtBSDF *bsdf) |
Built-in BSDFs | |
enum | AtMetalFresnelMode { GULBRANDSEN , F82_TINT } |
Metal Fresnel mode. | |
AI_API AI_DEVICE AtBSDF * | AiOrenNayarBSDF (const AtShaderGlobals *sg, const AtRGB &weight, const AtVector &N, float r=0.0f, bool transmission=false, const AtString label=AtString()) |
Create Oren-Nayar BSDF. More... | |
AI_API AI_DEVICE AtBSDF * | AiMicrofacetBSDF (const AtShaderGlobals *sg, const AtRGB &weight, int distribution, const AtVector &N, const AtVector *U, float ior, float rx, float ry, uint8_t exit_type=0, int32_t dielectric_priority=0, float thin_walled_transmission=0, const AtString label=AtString()) |
Create microfacet reflection BSDF. More... | |
AI_API AI_DEVICE AtBSDF * | AiMicrofacetRefractionBSDF (const AtShaderGlobals *sg, const AtRGB &weight, int distribution, const AtVector &N, const AtVector *U, float ior, float rx, float ry, float dispersion, bool use_fresnel=true, AtClosureList interior=AtClosureList(), uint8_t exit_type=0, int32_t dielectric_priority=0, const AtString label=AtString()) |
Create microfacet refraction BSDF. More... | |
AI_API AI_DEVICE AtBSDF * | AiMicrofacetThinWallRefractionBSDF (const AtShaderGlobals *sg, const AtRGB &weight, int distribution, const AtVector &N, const AtVector *U, float eta, float rx, float ry, uint8_t exit_type=0, AtString label=AtString()) |
Create thin-walled microfacet refraction BSDF. More... | |
AI_API AI_DEVICE void | AiMicrofacetSetThinFilm (AtBSDF *bsdf, float thickness, float eta) |
Set the thickness and refractive index of a thin film layered on top of a microfacet surface. More... | |
AI_API AI_DEVICE AtBSDF * | AiMetalBSDF (const AtShaderGlobals *sg, const AtRGB &weight, int distribution, const AtVector &N, const AtVector *U, AtMetalFresnelMode fresnel_mode, const AtRGB &fresnel1, const AtRGB &fresnel2, float rx, float ry, const AtString label=AtString()) |
Create microfacet BSDF with conductive Fresnel, for metals. More... | |
AI_API AI_DEVICE AtBSDF * | AidEonBSDF (const AtShaderGlobals *sg, const AtRGB &absorption, const AtRGB weights[3], const AtVector &tangent, const float roughness_longitudinal, const float roughness_azimuthal, const float eta, const float tilt, const AtString label=AtString()) |
Create d'Eon BSDF for hair. More... | |
AI_API AI_DEVICE AtBSDF * | AiZinkeBSDF (const AtShaderGlobals *sg, const AtRGB &weight, const AtVector &tangent, const AtString label=AtString()) |
Create Zinke BSDF for hair with Lambertian reflectance properties. More... | |
AI_API AI_DEVICE AtBSDF * | AiSheenBSDF (const AtShaderGlobals *sg, const AtRGB &weight, const AtVector &N, const float r, const AtString label=AtString()) |
Create Sheen BSDF for cloth-like materials. More... | |
Functions for implementing custom BSDFs | |
AI_API AtBSDF * | AiBSDF (const AtShaderGlobals *sg, const AtRGB &weight, const AtBSDFMethods *methods, size_t data_size) |
Allocate a BSDF and data memory to store parameters. More... | |
AI_API const AtBSDFMethods * | AiBSDFGetMethods (const AtBSDF *bsdf) |
Get BSDF methods. More... | |
AI_API AI_DEVICE void * | AiBSDFGetData (const AtBSDF *bsdf) |
Get BSDF data memory to store BSDF parameters. More... | |
AI_API const AtBSDFLobeInfo * | AiBSDFGetLobes (const AtBSDF *bsdf) |
Get BSDF lobes, available after the BSDF has been initialized. More... | |
AI_API int | AiBSDFGetNumLobes (const AtBSDF *bsdf) |
Get the number of BSDF lobes, available after the BSDF has been initialized. More... | |
AI_API AtRGB | AiBSDFGetWeight (const AtBSDF *bsdf) |
Get the BSDF weight. More... | |
AI_API AI_DEVICE void | AiBSDFSetDirectIndirect (AtBSDF *bsdf, float weight_direct, float weight_indirect) |
Set the BSDF direct and indirect light contribution weights. More... | |
AI_API AI_DEVICE void | AiBSDFGetDirectIndirect (const AtBSDF *bsdf, float &weight_direct, float &weight_indirect) |
Get the BSDF direct and indirect light contribution weights. More... | |
AI_API AI_DEVICE void | AiBSDFInitLobes (AtBSDF *bsdf, const AtBSDFLobeInfo *lobes, int num_lobes) |
Initialize BSDF lobes. More... | |
AI_API AI_DEVICE void | AiBSDFInitNormal (AtBSDF *bsdf, const AtVector &N, bool bounding) |
Initialize BSDF normal. More... | |
AI_API AI_DEVICE float | AiBSDFBumpShadow (const AtVector &Ns, const AtVector &N, const AtVector &Ld) |
Compute BSDF shadow factor to solve shading artifacts with bump mapping. More... | |
AI_API AI_DEVICE float | AiBSDFMinRoughness (const AtShaderGlobals *sg) |
Estimate a minimum roughness for specular BSDFs, to reduce noise from caustics. More... | |
BSDF integration | |
AI_API void | AiBSDFIntegrate (AtShaderGlobals *sg, AtRGB *direct, AtRGB *indirect, AtBSDF *bsdf) |
Returns the direct and indirect radiance reflected by the provided BSDF. More... | |
AI_API AI_DEVICE AtRGB | AiBSDFAlbedo (const AtShaderGlobals *sg, AtBSDF *bsdf) |
Returns BSDF albedo for incident direction sg->Rd, i.e. More... | |
Microfacet distributions | |
#define | AI_MICROFACET_BECKMANN 0x00 |
Beckmann distribution. | |
#define | AI_MICROFACET_GGX 0x01 |
GGX distribution. | |
Various BSDF functions available to shader writers.
#define AI_BSDF_EXPORT_METHODS | ( | tag | ) |
BSDF methods exporter.
#define bsdf_init |
Initialize BSDF when before it is used for the first time.
This method must set the BSDF lobes with AiBSDFInitLobes()
, and may optionally call AiBSDFInitBounds()
. Other typical initializations performed in this method would be ensuring the parameters are withing a valid range, store local geometry data for later evaluation and sampling (geometric normal, outgoing view direction, ..), and precomputing data.
#define bsdf_eval |
Evaluate BSDF for the given incoming light direction.
If the BSDF consists of multiple lobes, lobe_mask describes which lobes must be evaluated. The result of this evaluation for each lobe is:
weight
, defined as BSDF * cos(N.wi) / pdf
. The cosine between the surface normal and the incoming light direction must be included, and the weight must be divided by the probability density. For a BSDF that does perfect importance sampling, this weight would be 1.bsdf_sample
. #define bsdf_sample |
Sample BSDF for an incoming light direction, and evaluate BSDF.
This function returns:
wi
.weight
and pdf
, matching bsdf_eval
for the same incoming light direction. #define bsdf_albedo |
Compute BSDF albedo for AOVs and importance sampling (optional method)
#define bsdf_merge |
Merge BSDF with another BSDF of the same type (optional method)
Before initialization, evaluation and sampling, BSDFs of the same type can be merged if their parameters are equal or close enough that they can be mixed. This can improve rendering performance when mixing shaders.
If this method returns true to indicate the BSDFs can be merged, the weight of the other BSDF is added to this BSDF, and the other BSDF is discarded.
#define bsdf_interior |
Return volume closures describing the interior of the object.
These closures control the volume interior shading after refraction rays enter the object, typically for absorption inside glass.
enum AtBSDFLobeFlags |
BSDF Lobe flags.
AI_API AtBSDF * AiBSDF | ( | const AtShaderGlobals * | sg, |
const AtRGB & | weight, | ||
const AtBSDFMethods * | methods, | ||
size_t | data_size | ||
) |
Allocate a BSDF and data memory to store parameters.
sg | Shading globals |
methods | BSDF methods created with AI_BSDF_EXPORT_METHODS |
data_size | size of BSDF data to allocate, retrieved through AiBSDFGetData() |
AI_API const AtBSDFMethods * AiBSDFGetMethods | ( | const AtBSDF * | bsdf | ) |
Get BSDF methods.
bsdf | BSDF |
AI_API AI_DEVICE void * AiBSDFGetData | ( | const AtBSDF * | bsdf | ) |
Get BSDF data memory to store BSDF parameters.
bsdf | BSDF |
AI_API const AtBSDFLobeInfo * AiBSDFGetLobes | ( | const AtBSDF * | bsdf | ) |
Get BSDF lobes, available after the BSDF has been initialized.
bsdf | BSDF |
AI_API int AiBSDFGetNumLobes | ( | const AtBSDF * | bsdf | ) |
Get the number of BSDF lobes, available after the BSDF has been initialized.
bsdf | BSDF |
AI_API AtRGB AiBSDFGetWeight | ( | const AtBSDF * | bsdf | ) |
Get the BSDF weight.
bsdf | BSDF |
AI_API AI_DEVICE void AiBSDFSetDirectIndirect | ( | AtBSDF * | bsdf, |
float | weight_direct, | ||
float | weight_indirect | ||
) |
Set the BSDF direct and indirect light contribution weights.
For physically correct rendering, these must be set to the default 1.0, however for artistic control the direct and indirect light contributions can be scaled independently.
bsdf | BSDF |
weight_direct | Direct light weight |
weight_indirect | Indirect light weight |
AI_API AI_DEVICE void AiBSDFGetDirectIndirect | ( | const AtBSDF * | bsdf, |
float & | weight_direct, | ||
float & | weight_indirect | ||
) |
Get the BSDF direct and indirect light contribution weights.
For physically correct rendering, these must be set to the default 1.0, however for artistic control the direct and indirect light contributions can be scaled independently.
bsdf | BSDF |
weight_direct | Direct light weight |
weight_indirect | Indirect light weight |
AI_API AI_DEVICE void AiBSDFInitLobes | ( | AtBSDF * | bsdf, |
const AtBSDFLobeInfo * | lobes, | ||
int | num_lobes | ||
) |
Initialize BSDF lobes.
This function must be called from within the bsdf_init
method.
bsdf | BSDF |
lobes | Information about each BSDF lobe |
num_lobes | Number of lobes in the BSDFs |
AI_API AI_DEVICE void AiBSDFInitNormal | ( | AtBSDF * | bsdf, |
const AtVector & | N, | ||
bool | bounding | ||
) |
Initialize BSDF normal.
This normal is used for the builtin N AOV.
If the BSDF only reflects or transmits light within a hemisphere, the normal can also be used to more quickly cull light sources outside the hemisphere around the normal. If the BSDF both reflects and transmits light, no bounds should be set.
This function must be called from within the bsdf_init
method.
bsdf | BSDF |
N | normal |
bounding | true if the normal defines a bounding hemisphere |
AI_API AI_DEVICE float AiBSDFBumpShadow | ( | const AtVector & | Ns, |
const AtVector & | N, | ||
const AtVector & | Ld | ||
) |
Compute BSDF shadow factor to solve shading artifacts with bump mapping.
When a bump map normal is very different from the actual normal, jagged edges can appear. This function returns a factor to add extra shadowing to hide those artifacts.
Ns | Smooth normal without bump, facing the viewer, computed as (sg->Ng == sg->Ngf ) ? sg->Ns : -sg->N ; |
N | Bump mapped normal, facing the viewer (typically sg->Nf ) |
Ld | Direction vector towards the lights |
AtBSDFLobeSample.weight
AI_API AI_DEVICE float AiBSDFMinRoughness | ( | const AtShaderGlobals * | sg | ) |
Estimate a minimum roughness for specular BSDFs, to reduce noise from caustics.
Unidirectional path tracing can't resolve caustics efficiently. To reduce noise the roughness of specular BSDFs behind diffuse and glossy bounces can be artificially increased.
This function can be used in the bsdf_init
method, to clamp roughness to be at least the suggested minimum roughness value.
sg | shader globals context |
AI_API AI_DEVICE AtBSDF * AiOrenNayarBSDF | ( | const AtShaderGlobals * | sg, |
const AtRGB & | weight, | ||
const AtVector & | N, | ||
float | r, | ||
bool | transmission, | ||
const AtString | label | ||
) |
Create Oren-Nayar BSDF.
The returned data is allocated in a pixel pool and does not need to be freed by the caller.
sg | shader globals context |
N | normal vector that defines the hemisphere of incoming radiance |
r | surface roughness, normalized in the [0, 1] range |
transmission | use diffuse transmission instead of reflection |
AI_API AI_DEVICE AtBSDF * AiMicrofacetBSDF | ( | const AtShaderGlobals * | sg, |
const AtRGB & | weight, | ||
int | distribution, | ||
const AtVector & | N, | ||
const AtVector * | U, | ||
float | ior, | ||
float | rx, | ||
float | ry, | ||
uint8_t | exit_type, | ||
int32_t | dielectric_priority, | ||
float | thin_walled_transmission, | ||
const AtString | label | ||
) |
Create microfacet reflection BSDF.
The returned data is allocated in a pixel pool and does not need to be freed by the caller.
sg | shader globals context |
distribution | AI_MICROFACET_BECKMANN or AI_MICROFACET_GGX |
N | normal vector that defines the hemisphere of incoming radiance |
u | surface tangent vector along the U coordinate |
ior | refractive index for Fresnel, use 0 to disable Fresnel |
rx | specular roughness along the U direction |
ry | specular roughness along the V direction |
exit_type | zero, AI_BSDF_LOBE_EXIT_BACKGROUND or AI_BSDF_LOBE_EXIT_WHITE |
dielectric_priority | user-specified signed-integer dielectric priority, for nested dielectrics |
thin_walled_transmission | fraction of the BRDF which represents a thin-walled dielectric (to be used in conjunction with AiMicrofacetThinWallRefractionBSDF) |
AI_API AI_DEVICE AtBSDF * AiMicrofacetRefractionBSDF | ( | const AtShaderGlobals * | sg, |
const AtRGB & | weight, | ||
int | distribution, | ||
const AtVector & | N, | ||
const AtVector * | U, | ||
float | ior, | ||
float | rx, | ||
float | ry, | ||
float | dispersion, | ||
bool | use_fresnel, | ||
AtClosureList | interior, | ||
uint8_t | exit_type, | ||
int32_t | dielectric_priority, | ||
const AtString | label | ||
) |
Create microfacet refraction BSDF.
This BSDF currently only support indirect light, any direct light will be ignored.
The returned data is allocated in a pixel pool and does not need to be freed by the caller.
sg | shader globals context |
distribution | AI_MICROFACET_BECKMANN or AI_MICROFACET_GGX |
N | normal vector that defines the hemisphere of incoming radiance |
U | surface tangent vector along the U coordinate |
ior | refractive index |
rx | specular roughness along the U direction |
ry | specular roughness along the V direction |
dispersion | Cauchy coefficient for dispersion. Zero for no dispersion, higher values give more dispersion |
use_fresnel | set to true to include Fresnel term |
interior | volumetric closure giving the (optional) embedded scattering/absorbing medium of the dielectric |
exit_type | zero, AI_BSDF_LOBE_EXIT_BACKGROUND or AI_BSDF_LOBE_EXIT_WHITE |
dielectric_priority | user-specified signed-integer dielectric priority, for nested dielectrics |
AI_API AI_DEVICE AtBSDF * AiMicrofacetThinWallRefractionBSDF | ( | const AtShaderGlobals * | sg, |
const AtRGB & | weight, | ||
int | distribution, | ||
const AtVector & | N, | ||
const AtVector * | U, | ||
float | ior, | ||
float | rx, | ||
float | ry, | ||
uint8_t | exit_type, | ||
AtString | label | ||
) |
Create thin-walled microfacet refraction BSDF.
The returned data is allocated in a pixel pool and does not need to be freed by the caller.
sg | shader globals context |
distribution | AI_MICROFACET_BECKMANN or AI_MICROFACET_GGX |
N | normal vector that defines the hemisphere of incoming radiance |
U | surface tangent vector along the U coordinate |
ior | refractive index of the interior medium |
rx | specular roughness along the U direction |
ry | specular roughness along the V direction |
exit_type | zero, AI_BSDF_LOBE_EXIT_BACKGROUND or AI_BSDF_LOBE_EXIT_WHITE |
AI_API AI_DEVICE void AiMicrofacetSetThinFilm | ( | AtBSDF * | bsdf, |
float | thickness, | ||
float | ior | ||
) |
Set the thickness and refractive index of a thin film layered on top of a microfacet surface.
This replaces the classic Fresnel term with a new Airy reflectance term, which is applied per microfacet.
bsdf | BSDF |
thickness | Thickness of thin film in nanometers, typically in the 0 to 2000nm range |
ior | Refractive index of thin film |
AI_API AI_DEVICE AtBSDF * AiMetalBSDF | ( | const AtShaderGlobals * | sg, |
const AtRGB & | weight, | ||
int | distribution, | ||
const AtVector & | N, | ||
const AtVector * | U, | ||
AtMetalFresnelMode | fresnel_mode, | ||
const AtRGB & | fresnel1, | ||
const AtRGB & | fresnel2, | ||
float | rx, | ||
float | ry, | ||
const AtString | label | ||
) |
Create microfacet BSDF with conductive Fresnel, for metals.
The returned data is allocated in a pixel pool and does not need to be freed by the caller.
sg | shader globals context |
distribution | AI_MICROFACET_BECKMANN or AI_MICROFACET_GGX |
N | normal vector that defines the hemisphere of incoming radiance |
u | surface tangent vector along the U coordinate |
fresnel_mode | specify which Fresnel model to use for the metal (GULBRANDSEN or F82_TINT) |
fresnel1 | either real part of the complex refractive index for Fresnel (GULBRANDSEN), or F0 reflectance at normal incidence (F82_TINT) |
fresnel2 | either imaginary part of the complex refractive index for Fresnel (GULBRANDSEN), or tint applied at near-grazing (approx. 82 degrees) incidence (F82_TINT) |
rx | specular roughness along the U direction |
ry | specular roughness along the V direction |
AI_API AI_DEVICE AtBSDF * AidEonBSDF | ( | const AtShaderGlobals * | sg, |
const AtRGB & | absorption, | ||
const AtRGB | weights[3], | ||
const AtVector & | tangent, | ||
const float | roughness_longitudinal, | ||
const float | roughness_azimuthal, | ||
const float | eta, | ||
const float | tilt, | ||
const AtString | label | ||
) |
Create d'Eon BSDF for hair.
The returned data is allocated in a pixel pool and does not need to be freed by the caller.
Note: Absorption value is referenced in the linear sRGB color space, as per the paper. (overridden when options.enable_deprecated_hair_absorption = true)
sg | shader globals context |
absorption | absorption inside hair (in linear sRGB color space) |
weights | weights for R, TT, and TRT paths |
tangent | hair tangent vector, pointing from root to tip |
roughness_longitudinal | specular roughness for longitudinal scattering |
roughness_azimuthal | specular roughness for azimuthal scattering |
eta | refractive index of hair fiber |
tilt | scale tilt angle |
AI_API AI_DEVICE AtBSDF * AiZinkeBSDF | ( | const AtShaderGlobals * | sg, |
const AtRGB & | weight, | ||
const AtVector & | tangent, | ||
const AtString | label | ||
) |
Create Zinke BSDF for hair with Lambertian reflectance properties.
The returned data is allocated in a pixel pool and does not need to be freed by the caller.
sg | shader globals context |
tangent | hair tangent vector, pointing from root to tip |
AI_API AI_DEVICE AtBSDF * AiSheenBSDF | ( | const AtShaderGlobals * | sg, |
const AtRGB & | weight, | ||
const AtVector & | N, | ||
const float | r, | ||
const AtString | label | ||
) |
Create Sheen BSDF for cloth-like materials.
The returned data is allocated in a pixel pool and does not need to be freed by the caller.
sg | shader globals context | |
N | normal vector that defines the hemisphere of incoming radiance | |
r | surface roughness, normalized in the [0, 1] range | |
[out] | albedo | albedo in the [0, 1] range, which can be used to layer sheen onto other closures |
AI_API void AiBSDFIntegrate | ( | AtShaderGlobals * | sg, |
AtRGB * | direct, | ||
AtRGB * | indirect, | ||
AtBSDF * | bsdf | ||
) |
Returns the direct and indirect radiance reflected by the provided BSDF.
Applies the importance sampling Monte Carlo integration technique and multiple importance sampling (MIS) to compute light coming from all objects and light sources in the scene.
The eval_pdf
and eval_sample
parameters are a matching pair of functions that describe a sample probability density and its corresponding quantile function, respectively. Any pair of PDF and quantile functions that sample the entire non-zero region of the BSDF should in theory converge upon the same result given enough samples, however sample distributions that are specifically tuned to the provided BSDF should have a much faster rate of convergence.
It is possible to compute only the direct or indirect radiance, however if both are needed it is faster to compute them at the same time.
sg | Shading globals |
bsdf | BSDF |
direct | returned direct radiance, coming from lights sources |
indirect | returned indirect radiance, coming from other objects |
AI_API AI_DEVICE AtRGB AiBSDFAlbedo | ( | const AtShaderGlobals * | sg, |
AtBSDF * | bsdf | ||
) |
Returns BSDF albedo for incident direction sg->Rd, i.e.
the fraction of light not absorbed by it. This can for example be used for weighting a diffuse BSDF below a specular one.
sg | shader globals context |
bsdf | pointer to the AtBSDF |