ai_shader_bsdf.h
Go to the documentation of this file.
1 // Copyright 2020 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 
26 struct AtBSDF;
27 
34 };
35 
36 
39  uint8_t ray_type;
40  uint8_t flags;
41  AtString label;
42 };
43 
44 
46 typedef uint32_t AtBSDFLobeMask;
47 static const AtBSDFLobeMask AI_BSDF_LOBE_MASK_NONE = 0x0;
48 
49 
52  AI_DEVICE AtBSDFLobeSample(AtRGB weight, float reverse_pdf, float pdf)
53  : weight(weight), reverse_pdf(reverse_pdf), pdf(pdf) { }
54 
55  AI_DEVICE AtBSDFLobeSample(AtRGB eval)
56  : weight(eval), reverse_pdf(1.0f), pdf(1.0f) { }
57 
58  AtBSDFLobeSample() = default;
59 
60  AtRGB weight;
61  float reverse_pdf;
62  float pdf;
63 };
64 
65 
74 {
75  int version;
76  void (*Init)(const AtShaderGlobals* sg,
77  AtBSDF* bsdf);
78  AtBSDFLobeMask (*Eval)(const AtBSDF* bsdf,
79  const AtVector& wi,
80  const AtBSDFLobeMask lobe_mask,
81  const bool need_pdf,
82  AtBSDFLobeSample out_lobes[]);
83  AtBSDFLobeMask (*Sample)(const AtBSDF* bsdf,
84  const AtVector rnd,
85  const float wavelength,
86  const AtBSDFLobeMask lobe_mask,
87  const bool need_pdf,
88  AtVectorDv& out_wi,
89  int& out_lobe_index,
90  AtBSDFLobeSample out_lobes[]);
91  AtRGB (*Albedo)(const AtBSDF* bsdf,
92  const AtShaderGlobals* sg,
93  const AtBSDFLobeMask lobe_mask);
94  bool (*Merge)(AtBSDF* bsdf,
95  const AtBSDF* other_bsdf);
96  AtClosureList (*Interior)(const AtShaderGlobals* sg,
97  AtBSDF* bsdf);
98 };
99 
101 #define AI_BSDF_EXPORT_METHODS(tag) \
102 bsdf_init; \
103 bsdf_eval; \
104 bsdf_sample; \
105 static AtBSDFMethods ai_bsdf_methods = { \
106  0, \
107  Init, \
108  Eval, \
109  Sample, \
110  NULL, \
111  NULL, \
112  NULL, \
113 }; \
114 AtBSDFMethods* tag = &ai_bsdf_methods;
115 
125 #define bsdf_init \
126 static void Init(const AtShaderGlobals* sg, \
127  AtBSDF* bsdf)
128 
141 #define bsdf_eval \
142 static AtBSDFLobeMask Eval(const AtBSDF* bsdf, \
143  const AtVector& wi, \
144  const AtBSDFLobeMask lobe_mask, \
145  const bool need_pdf, \
146  AtBSDFLobeSample out_lobes[])
147 
157 #define bsdf_sample \
158 static AtBSDFLobeMask Sample(const AtBSDF* bsdf, \
159  const AtVector rnd, \
160  const float wavelength, \
161  const AtBSDFLobeMask lobe_mask, \
162  const bool need_pdf, \
163  AtVectorDv& out_wi, \
164  int& out_lobe_index, \
165  AtBSDFLobeSample out_lobes[])
166 
170 #define bsdf_albedo \
171 static AtRGB Albedo(const AtBSDF* bsdf, const AtShaderGlobals* sg, const AtBSDFLobeMask lobe_mask); \
172 AI_OPTIONAL_METHOD_INSTALL(ai_bsdf_methods, Albedo) \
173 static AtRGB Albedo(const AtBSDF* bsdf, const AtShaderGlobals* sg, const AtBSDFLobeMask lobe_mask)
174 
185 #define bsdf_merge \
186 static bool Merge(AtBSDF* bsdf, const AtBSDF* other_bsdf); \
187 AI_OPTIONAL_METHOD_INSTALL(ai_bsdf_methods, Merge) \
188 static bool Merge(AtBSDF* bsdf, const AtBSDF* other_bsdf)
189 
196 #define bsdf_interior \
197 static AtClosureList Interior(const AtShaderGlobals* sg, AtBSDF* bsdf); \
198 AI_OPTIONAL_METHOD_INSTALL(ai_bsdf_methods, Interior) \
199 static AtClosureList Interior(const AtShaderGlobals* sg, AtBSDF* bsdf)
200 
201 
205 AI_API AtBSDF* AiBSDF(const AtShaderGlobals* sg, const AtRGB& weight, const AtBSDFMethods* methods, size_t data_size);
206 
207 AI_API const AtBSDFMethods* AiBSDFGetMethods (const AtBSDF* bsdf);
208 AI_API AI_DEVICE void* AiBSDFGetData (const AtBSDF* bsdf);
209 AI_API const AtBSDFLobeInfo* AiBSDFGetLobes (const AtBSDF* bsdf);
210 AI_API int AiBSDFGetNumLobes(const AtBSDF* bsdf);
211 AI_API AtRGB AiBSDFGetWeight (const AtBSDF* bsdf);
212 
213 AI_API AI_DEVICE void AiBSDFSetDirectIndirect(AtBSDF* bsdf, float weight_direct, float weight_indirect);
214 AI_API AI_DEVICE void AiBSDFGetDirectIndirect(const AtBSDF* bsdf, float& weight_direct, float& weight_indirect);
215 
216 AI_API AI_DEVICE void AiBSDFInitLobes (AtBSDF* bsdf, const AtBSDFLobeInfo* lobes, int num_lobes);
217 AI_API AI_DEVICE void AiBSDFInitNormal(AtBSDF* bsdf, const AtVector& N, bool bounding);
218 
219 AI_API AI_DEVICE float AiBSDFBumpShadow (const AtVector& Ns, const AtVector& N, const AtVector& Ld);
220 AI_API AI_DEVICE float AiBSDFMinRoughness(const AtShaderGlobals* sg);
221 /*\}*/
222 
223 
227 AI_API AI_DEVICE AtBSDF* AiOrenNayarBSDF(const AtShaderGlobals* sg, const AtRGB& weight,
228  const AtVector& N, float r = 0.0f, bool transmission = false,
229  const AtString label = AtString());
230 
231 AI_API AI_DEVICE AtBSDF* AiMicrofacetBSDF(const AtShaderGlobals* sg, const AtRGB& weight,
232  int distribution, const AtVector& N, const AtVector *U,
233  float eta, float rx, float ry, uint8_t exit_type = 0,
234  const AtString label = AtString());
235 
236 AI_API AI_DEVICE
237 AtBSDF* AiMicrofacetBSDF_private(const AtShaderGlobals* sg, const AtRGB& weight,
238  int distribution, const AtVector& N, const AtVector *U,
239  float ior, float rx, float ry, uint8_t exit_type,
240  const AtString label,
241  int32_t dielectric_importance);
242 
243 AI_API AI_DEVICE AtBSDF* AiMicrofacetRefractionBSDF(const AtShaderGlobals* sg, const AtRGB& weight,
244  int distribution, const AtVector& N, const AtVector *U,
245  float ior, float rx, float ry, float dispersion,
246  bool use_fresnel = true, AtClosureList interior = NULL,
247  uint8_t exit_type = 0, const AtString label = AtString());
248 
249 AI_API AI_DEVICE AtBSDF* AiMicrofacetRefractionBSDF_private(const AtShaderGlobals* sg, const AtRGB& weight,
250  int distribution, const AtVector& N, const AtVector *U,
251  float ior, float rx, float ry, float dispersion,
252  bool use_fresnel, AtClosureList interior,
253  uint8_t exit_type, const AtString label,
254  int32_t dielectric_importance);
255 
256 AI_API AI_DEVICE AtBSDF* AiMicrofacetThinWallRefractionBSDF(const AtShaderGlobals* sg, const AtRGB& weight,
257  int distribution, const AtVector& N, const AtVector *U,
258  float eta, float rx, float ry,
259  uint8_t exit_type = 0, AtString label = AtString());
260 
261 AI_API AI_DEVICE void AiMicrofacetSetThinFilm(AtBSDF* bsdf, float thickness, float eta);
262 
263 AI_API AI_DEVICE AtBSDF* AiMetalBSDF(const AtShaderGlobals* sg, const AtRGB& weight,
264  int distribution, const AtVector& N, const AtVector *U,
265  const AtRGB& n, const AtRGB& k, float rx, float ry,
266  const AtString label = AtString());
267 
268 AI_API AI_DEVICE AtBSDF* AidEonBSDF(const AtShaderGlobals* sg, const AtRGB& absorption, const AtRGB weights[3],
269  const AtVector& tangent, const float roughness, const float eta,
270  const float tilt, const AtString label = AtString());
271 
272 AI_API AI_DEVICE AtBSDF* AiZinkeBSDF(const AtShaderGlobals* sg, const AtRGB &weight, const AtVector& tangent,
273  const AtString label = AtString());
274 
275 AI_API AI_DEVICE AtBSDF* AiSheenBSDF(const AtShaderGlobals* sg, const AtRGB &weight, const AtVector& N,
276  const float r, const AtString label = AtString());
277 
278 /* \}*/
279 
283 #define AI_MICROFACET_BECKMANN 0x00
284 #define AI_MICROFACET_GGX 0x01
285 /*\}*/
286 
287 
291 AI_API void AiBSDFIntegrate(AtShaderGlobals* sg, AtRGB* direct, AtRGB* indirect, AtBSDF* bsdf);
292 
293 AI_API AI_DEVICE AtRGB AiBSDFAlbedo(const AtShaderGlobals* sg, AtBSDF* bsdf);
294 /* \}*/
295 
296 
297 /*\}*/
Ray struct and various trace functions.
RGB color.
Definition: ai_color.h:31
AI_API const AtBSDFLobeInfo * AiBSDFGetLobes(const AtBSDF *bsdf)
Get BSDF lobes, available after the BSDF has been initialized.
Definition: ai_shader_bsdf.cpp:721
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=NULL, uint8_t exit_type=0, const AtString label=AtString())
Create microfacet refraction BSDF.
Definition: ai_shader_bsdf.cpp:363
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:164
AI_API AI_DEVICE void AiBSDFInitNormal(AtBSDF *bsdf, const AtVector &N, bool bounding)
Initialize BSDF normal.
Definition: ai_shader_bsdf.cpp:685
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:776
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:390
If ray depth exceeded, use white color.
Definition: ai_shader_bsdf.h:33
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:732
AI_API AI_DEVICE AtBSDF * AiMicrofacetRefractionBSDF_private(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, const AtString label, int32_t dielectric_importance)
Create microfacet refraction BSDF.
Definition: ai_shader_bsdf.cpp:294
AI_API AI_DEVICE void * AiBSDFGetData(const AtBSDF *bsdf)
Get BSDF data memory to store BSDF parameters.
Definition: ai_shader_bsdf.cpp:709
BSDF function table.
Definition: ai_shader_bsdf.h:73
Vector math types, operators and utilities.
AI_API AI_DEVICE void AiBSDFInitLobes(AtBSDF *bsdf, const AtBSDFLobeInfo *lobes, int num_lobes)
Initialize BSDF lobes.
Definition: ai_shader_bsdf.cpp:664
Sampling the BSDF lobe requires a wavelength.
Definition: ai_shader_bsdf.h:31
Shader globals struct, methods and macros.
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:863
AI_API AtRGB AiBSDFGetWeight(const AtBSDF *bsdf)
Get the BSDF weight.
Definition: ai_shader_bsdf.cpp:744
Arnold String allows for fast string comparisons.
Definition: ai_string.h:46
3D point (single precision)
Definition: ai_vector.h:29
AI_API AI_DEVICE AtBSDF * AiMetalBSDF(const AtShaderGlobals *sg, const AtRGB &weight, int distribution, const AtVector &N, const AtVector *U, const AtRGB &n, const AtRGB &k, float rx, float ry, const AtString label=AtString())
Create microfacet BSDF with conductive Fresnel, for metals.
Definition: ai_shader_bsdf.cpp:435
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...
Definition: ai_shader_bsdf.cpp:794
Color types and utilities.
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:558
AI_API AI_DEVICE AtBSDF * AiMicrofacetBSDF(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, const AtString label=AtString())
Create microfacet reflection BSDF.
Definition: ai_shader_bsdf.cpp:259
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:527
If ray depth exceeded, use background color.
Definition: ai_shader_bsdf.h:32
Shader globals data structure.
Definition: ai_shaderglobals.h:45
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:760
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:606
AI_API AI_DEVICE AtBSDF * AiMicrofacetBSDF_private(const AtShaderGlobals *sg, const AtRGB &weight, int distribution, const AtVector &N, const AtVector *U, float ior, float rx, float ry, uint8_t exit_type, const AtString label, int32_t dielectric_importance)
Create microfacet reflection BSDF.
Definition: ai_shader_bsdf.cpp:207
AI_API const AtBSDFMethods * AiBSDFGetMethods(const AtBSDF *bsdf)
Get BSDF methods.
Definition: ai_shader_bsdf.cpp:697
uint32_t AtBSDFLobeMask
BSDF lobe bitmask.
Definition: ai_shader_bsdf.h:46
AI_API AI_DEVICE AtBSDF * AidEonBSDF(const AtShaderGlobals *sg, const AtRGB &absorption, const AtRGB weights[3], const AtVector &tangent, const float roughness, const float eta, const float tilt, const AtString label=AtString())
Create d'Eon BSDF for hair.
Definition: ai_shader_bsdf.cpp:484
Definition: ai_closure.h:84
BSDF lobe sample.
Definition: ai_shader_bsdf.h:51
AtBSDFLobeFlags
BSDF Lobe flags.
Definition: ai_shader_bsdf.h:29
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:814
BSDF lobe information.
Definition: ai_shader_bsdf.h:38
Vector with differentials.
Definition: ai_vector.h:515
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:637
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.
Definition: ai_shader_bsdf.cpp:133
Sampling the BSDF always returns the same direction.
Definition: ai_shader_bsdf.h:30

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