ai_shader_bsdf.h
Go to the documentation of this file.
1// Copyright 2021 Autodesk, Inc. All rights reserved.
2//
3// Use of this software is subject to the terms of the Autodesk license
4// agreement provided at the time of installation or download, or which
5// otherwise accompanies this software in either electronic or hard copy form.
6
12#pragma once
13#include "ai_color.h"
14#include "ai_ray.h"
15#include "ai_vector.h"
16#include "ai_shaderglobals.h"
17#include "ai_shader_closure.h"
18
27struct AtBSDF;
28
35};
36
37
40 uint8_t ray_type;
41 uint8_t flags;
42 AtString label;
43};
44
45
47typedef uint32_t AtBSDFLobeMask;
48static const AtBSDFLobeMask AI_BSDF_LOBE_MASK_NONE = 0x0;
49
50
53 AI_DEVICE AtBSDFLobeSample(AtRGB weight, float reverse_pdf, float pdf)
54 : weight(weight), reverse_pdf(reverse_pdf), pdf(pdf) { }
55
56 AI_DEVICE AtBSDFLobeSample(AtRGB eval)
57 : weight(eval), reverse_pdf(1.0f), pdf(1.0f) { }
58
59 AtBSDFLobeSample() = default;
60
61 AtRGB weight;
62 float reverse_pdf;
63 float pdf;
64};
65
66
74#ifdef AI_CPU_COMPILER
76{
77 int version;
78 void (*Init)(const AtShaderGlobals* sg,
79 AtBSDF* bsdf);
80 AtBSDFLobeMask (*Eval)(const AtBSDF* bsdf,
81 const AtVector& wi,
82 const AtBSDFLobeMask lobe_mask,
83 const bool need_pdf,
84 AtBSDFLobeSample out_lobes[]);
85 AtBSDFLobeMask (*Sample)(const AtBSDF* bsdf,
86 const AtVector rnd,
87 const float wavelength,
88 const AtBSDFLobeMask lobe_mask,
89 const bool need_pdf,
90 AtVectorDv& out_wi,
91 int& out_lobe_index,
92 AtBSDFLobeSample out_lobes[]);
93 AtRGB (*Albedo)(const AtBSDF* bsdf,
94 const AtShaderGlobals* sg,
95 const AtBSDFLobeMask lobe_mask);
96 bool (*Merge)(AtBSDF* bsdf,
97 const AtBSDF* other_bsdf);
98 AtClosureList (*Interior)(const AtShaderGlobals* sg,
99 AtBSDF* bsdf);
100};
101#endif // AI_CPU_COMPILER
102
104#define AI_BSDF_EXPORT_METHODS(tag) \
105bsdf_init; \
106bsdf_eval; \
107bsdf_sample; \
108static AtBSDFMethods ai_bsdf_methods = { \
109 0, \
110 Init, \
111 Eval, \
112 Sample, \
113 NULL, \
114 NULL, \
115 NULL, \
116}; \
117AtBSDFMethods* tag = &ai_bsdf_methods;
118
128#define bsdf_init \
129static void Init(const AtShaderGlobals* sg, \
130 AtBSDF* bsdf)
131
144#define bsdf_eval \
145static AtBSDFLobeMask Eval(const AtBSDF* bsdf, \
146 const AtVector& wi, \
147 const AtBSDFLobeMask lobe_mask, \
148 const bool need_pdf, \
149 AtBSDFLobeSample out_lobes[])
150
160#define bsdf_sample \
161static AtBSDFLobeMask Sample(const AtBSDF* bsdf, \
162 const AtVector rnd, \
163 const float wavelength, \
164 const AtBSDFLobeMask lobe_mask, \
165 const bool need_pdf, \
166 AtVectorDv& out_wi, \
167 int& out_lobe_index, \
168 AtBSDFLobeSample out_lobes[])
169
173#define bsdf_albedo \
174static AtRGB Albedo(const AtBSDF* bsdf, const AtShaderGlobals* sg, const AtBSDFLobeMask lobe_mask); \
175AI_OPTIONAL_METHOD_INSTALL(ai_bsdf_methods, Albedo) \
176static AtRGB Albedo(const AtBSDF* bsdf, const AtShaderGlobals* sg, const AtBSDFLobeMask lobe_mask)
177
188#define bsdf_merge \
189static bool Merge(AtBSDF* bsdf, const AtBSDF* other_bsdf); \
190AI_OPTIONAL_METHOD_INSTALL(ai_bsdf_methods, Merge) \
191static bool Merge(AtBSDF* bsdf, const AtBSDF* other_bsdf)
192
199#define bsdf_interior \
200static AtClosureList Interior(const AtShaderGlobals* sg, AtBSDF* bsdf); \
201AI_OPTIONAL_METHOD_INSTALL(ai_bsdf_methods, Interior) \
202static AtClosureList Interior(const AtShaderGlobals* sg, AtBSDF* bsdf)
203
204
208#ifdef AI_CPU_COMPILER
209AI_API AtBSDF* AiBSDF(const AtShaderGlobals* sg, const AtRGB& weight, const AtBSDFMethods* methods, size_t data_size);
210
211AI_API const AtBSDFMethods* AiBSDFGetMethods (const AtBSDF* bsdf);
212#endif // AI_CPU_COMPILER
213AI_API AI_DEVICE void* AiBSDFGetData (const AtBSDF* bsdf);
214AI_API const AtBSDFLobeInfo* AiBSDFGetLobes (const AtBSDF* bsdf);
215AI_API int AiBSDFGetNumLobes(const AtBSDF* bsdf);
216AI_API AI_DEVICE AtRGB AiBSDFGetWeight (const AtBSDF* bsdf);
217
218AI_API AI_DEVICE void AiBSDFSetDirectIndirect(AtBSDF* bsdf, float weight_direct, float weight_indirect);
219AI_API AI_DEVICE void AiBSDFGetDirectIndirect(const AtBSDF* bsdf, float& weight_direct, float& weight_indirect);
220
221AI_API AI_DEVICE void AiBSDFInitLobes (AtBSDF* bsdf, const AtBSDFLobeInfo* lobes, int num_lobes);
222AI_API AI_DEVICE void AiBSDFInitNormal(AtBSDF* bsdf, const AtVector& N, bool bounding);
223
224AI_API AI_DEVICE float AiBSDFBumpShadow (const AtVector& Ns, const AtVector& N, const AtVector& Ld);
225AI_API AI_DEVICE float AiBSDFMinRoughness(const AtShaderGlobals* sg);
226/*\}*/
227
228
235
243enum AtOrenNayarModel : unsigned char
244{
245 QUALITATIVE, // classic "qualitative" Oren-Nayar model (QON)
246 ENERGY_PRESERVING // energy preserving Oren-Nayar model (EON)
247};
248
249AI_API AI_DEVICE
250AtBSDF* AiOrenNayarBSDF(const AtShaderGlobals* sg, const AtRGB& weight, const AtVector& N,
251 AtOrenNayarModel model = AtOrenNayarModel::ENERGY_PRESERVING,
252 float r = 0.0f, bool transmission = false,
253 const AtString label = AtString());
254
255/* \}*/ // Diffuse BRDF
256
257
259
262AI_API AI_DEVICE
263AtBSDF* AiMicrofacetBSDF(const AtShaderGlobals* sg, const AtRGB& weight,
264 int distribution, const AtVector& N, const AtVector *U,
265 float ior, float rx, float ry,
266 uint8_t exit_type = 0,
267 int32_t dielectric_priority = 0,
268 float thin_walled_transmission = 0,
269 const AtString label = AtString());
270
271AI_API AI_DEVICE AtBSDF*
272AiMicrofacetRefractionBSDF(const AtShaderGlobals* sg, const AtRGB& weight,
273 int distribution, const AtVector& N, const AtVector *U,
274 float ior, float rx, float ry, float dispersion,
275 bool use_fresnel = true, AtClosureList interior_volume = AtClosureList(),
276 uint8_t exit_type = 0,
277 int32_t dielectric_priority = 0,
278 const AtString label = AtString());
279
280AI_API AI_DEVICE AtBSDF*
282 int distribution, const AtVector& N, const AtVector *U,
283 float eta, float rx, float ry,
284 uint8_t exit_type = 0,
285 AtString label = AtString());
286
290#define AI_MICROFACET_BECKMANN 0x00
291#define AI_MICROFACET_GGX 0x01
292/*\}*/
293
294/* \}*/ // Microfacet BSDFs
295
296
298
301AI_API AI_DEVICE
302void AiMicrofacetSetThinFilm(AtBSDF* bsdf, float weight, float thickness, float ior);
303/* \}*/ // Thin-film modifier
304
305
307
315{
316 GULBRANDSEN, // based on "Artist Friendly Metallic Fresnel", Gulbrandsen, JCGT (2014)
317 F82_TINT // based on the F82-tint model, from "Novel aspects of the Adobe Standard Material", Kutz et. al (2021)
318};
319
320AI_API AI_DEVICE AtBSDF* AiMetalBSDF(const AtShaderGlobals* sg, const AtRGB& weight,
321 int distribution, const AtVector& N, const AtVector *U,
322 AtMetalFresnelMode fresnel_mode,
323 const AtRGB& fresnel1, const AtRGB& fresnel2, float fresnel_weight,
324 float rx, float ry,
325 const AtString label = AtString());
326
327/* \}*/ // Metal BRDF
328
329
331
334AI_API AI_DEVICE AtBSDF* AidEonBSDF(const AtShaderGlobals* sg, const AtRGB& absorption, const AtRGB weights[3],
335 const AtVector& tangent,
336 const float roughness_longitudinal, const float roughness_azimuthal,
337 const float eta, const float tilt, const AtString label = AtString());
338
339AI_API AI_DEVICE AtBSDF* AiZinkeBSDF(const AtShaderGlobals* sg, const AtRGB &weight, const AtVector& tangent,
340 const AtString label = AtString());
341
342/* \}*/ // Hair BSDFs
343
344
346
349AI_API AI_DEVICE AtBSDF* AiSheenBSDF(const AtShaderGlobals* sg, const AtRGB &weight, const AtVector& N,
350 const float r, const AtString label = AtString());
351
352AI_API AI_DEVICE AtBSDF* AiFuzzBSDF(const AtShaderGlobals* sg, const AtRGB &weight, const AtVector& N,
353 const float r, const AtString label = AtString());
354
355
356/* \}*/ // Sheen/Fuzz BRDF
357
358/* \}*/ // Built-in BSDFs
359
360
361
365AI_API void AiBSDFIntegrate(AtShaderGlobals* sg, AtRGB* direct, AtRGB* indirect, AtBSDF* bsdf);
366
367AI_API AI_DEVICE AtRGB AiBSDFAlbedo(const AtShaderGlobals* sg, AtBSDF* bsdf);
368/* \}*/
369
370/*\}*/
Color types and utilities.
Ray struct and various trace functions.
Shader closures.
Shader globals struct, methods and macros.
Vector math types, operators and utilities.
Arnold String allows for fast string comparisons.
Definition: ai_string.h:54
AtMetalFresnelMode
Metal Fresnel mode.
Definition: ai_shader_bsdf.h:315
AtBSDFLobeFlags
BSDF Lobe flags.
Definition: ai_shader_bsdf.h:30
AtOrenNayarModel
Oren-Nayar mode.
Definition: ai_shader_bsdf.h:244
AI_API AI_DEVICE void AiBSDFGetDirectIndirect(const AtBSDF *bsdf, float &weight_direct, float &weight_indirect)
Get the BSDF direct and indirect light contribution weights.
Definition: ai_shader_bsdf.cpp:807
AI_API const AtBSDFLobeInfo * AiBSDFGetLobes(const AtBSDF *bsdf)
Get BSDF lobes, available after the BSDF has been initialized.
Definition: ai_shader_bsdf.cpp:762
AI_API AI_DEVICE AtBSDF * AiFuzzBSDF(const AtShaderGlobals *sg, const AtRGB &weight, const AtVector &N, const float r, const AtString label=AtString())
Create Fuzz BSDF for dusty/fuzzy/textile materials.
Definition: ai_shader_bsdf.cpp:610
AI_API AI_DEVICE AtBSDF * AiOrenNayarBSDF(const AtShaderGlobals *sg, const AtRGB &weight, const AtVector &N, AtOrenNayarModel model=AtOrenNayarModel::ENERGY_PRESERVING, float r=0.0f, bool transmission=false, const AtString label=AtString())
Create Oren-Nayar BSDF.
Definition: ai_shader_bsdf.cpp:172
AI_API void AiBSDFIntegrate(AtShaderGlobals *sg, AtRGB *direct, AtRGB *indirect, AtBSDF *bsdf)
Returns the direct and indirect radiance reflected by the provided BSDF.
Definition: ai_shader_bsdf.cpp:661
AI_API AI_DEVICE AtRGB AiBSDFAlbedo(const AtShaderGlobals *sg, AtBSDF *bsdf)
Returns BSDF albedo for incident direction sg->Rd, i.e.
Definition: ai_shader_bsdf.cpp:206
AI_API const AtBSDFMethods * AiBSDFGetMethods(const AtBSDF *bsdf)
Get BSDF methods.
Definition: ai_shader_bsdf.cpp:727
AI_API AI_DEVICE void AiBSDFInitNormal(AtBSDF *bsdf, const AtVector &N, bool bounding)
Initialize BSDF normal.
Definition: ai_shader_bsdf.cpp:715
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.
Definition: ai_shader_bsdf.cpp:571
AI_API AI_DEVICE void AiBSDFInitLobes(AtBSDF *bsdf, const AtBSDFLobeInfo *lobes, int num_lobes)
Initialize BSDF lobes.
Definition: ai_shader_bsdf.cpp:694
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.
Definition: ai_shader_bsdf.cpp:846
AI_API AI_DEVICE void AiMicrofacetSetThinFilm(AtBSDF *bsdf, float weight, float thickness, float ior)
Set the thickness and refractive index of a thin film layered on top of a microfacet surface.
Definition: ai_shader_bsdf.cpp:825
uint32_t AtBSDFLobeMask
BSDF lobe bitmask.
Definition: ai_shader_bsdf.h:47
AI_API int AiBSDFGetNumLobes(const AtBSDF *bsdf)
Get the number of BSDF lobes, available after the BSDF has been initialized.
Definition: ai_shader_bsdf.cpp:773
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_volume=AtClosureList(), uint8_t exit_type=0, int32_t dielectric_priority=0, const AtString label=AtString())
Create microfacet refraction BSDF.
Definition: ai_shader_bsdf.cpp:314
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.
Definition: ai_shader_bsdf.cpp:495
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.
Definition: ai_shader_bsdf.cpp:128
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 fresnel_weight, float rx, float ry, const AtString label=AtString())
Create microfacet BSDF with conductive Fresnel, for metals.
Definition: ai_shader_bsdf.cpp:431
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.
Definition: ai_shader_bsdf.cpp:539
AI_API AI_DEVICE void AiBSDFSetDirectIndirect(AtBSDF *bsdf, float weight_direct, float weight_indirect)
Set the BSDF direct and indirect light contribution weights.
Definition: ai_shader_bsdf.cpp:791
AI_API AI_DEVICE AtRGB AiBSDFGetWeight(const AtBSDF *bsdf)
Get the BSDF weight.
Definition: ai_shader_bsdf.cpp:750
AI_API AI_DEVICE void * AiBSDFGetData(const AtBSDF *bsdf)
Get BSDF data memory to store BSDF parameters.
Definition: ai_shader_bsdf.cpp:739
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.
Definition: ai_shader_bsdf.cpp:249
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.
Definition: ai_shader_bsdf.cpp:378
AI_API AI_DEVICE float AiBSDFMinRoughness(const AtShaderGlobals *sg)
Estimate a minimum roughness for specular BSDFs, to reduce noise from caustics.
Definition: ai_shader_bsdf.cpp:895
@ AI_BSDF_LOBE_WAVELENGTH_SAMPLE
Sampling the BSDF lobe requires a wavelength
Definition: ai_shader_bsdf.h:32
@ AI_BSDF_LOBE_SINGULAR
Sampling the BSDF always returns the same direction.
Definition: ai_shader_bsdf.h:31
@ AI_BSDF_LOBE_EXIT_WHITE
If ray depth exceeded, use white color
Definition: ai_shader_bsdf.h:34
@ AI_BSDF_LOBE_EXIT_BACKGROUND
If ray depth exceeded, use background color
Definition: ai_shader_bsdf.h:33
BSDF lobe information.
Definition: ai_shader_bsdf.h:39
BSDF lobe sample.
Definition: ai_shader_bsdf.h:52
BSDF function table.
Definition: ai_shader_bsdf.h:76
Definition: ai_closure.h:85
RGB color.
Definition: ai_color.h:32
Shader globals data structure.
Definition: ai_shaderglobals.h:45
Vector with differentials.
Definition: ai_vector.h:515
3D point (single precision)
Definition: ai_vector.h:30

© 2023 Autodesk, Inc. · All rights reserved · www.arnoldrenderer.com