|
| 1 | +# BSDL library |
| 2 | + |
| 3 | +BSDL is the working title (Bidirectional Scattering Distribution Library) for |
| 4 | +this header only collection of BSDFs. It is self-contained depending only on |
| 5 | +Imath and intended to be used in any renderer. This is a build only dependency. |
| 6 | + |
| 7 | +The basic idea is that you choose a BSDF from it and give it a thin wrapper to |
| 8 | +integrate in your renderer. There is an example of this in OSL's testrender. The |
| 9 | +key features are: |
| 10 | + * BSDFs provide constructor, eval and sample methods. |
| 11 | + * Everything is inlined (split among _decl.h and _imple.h headers) to be GPU friendly. |
| 12 | + * There is a template based autiomatic switch/case virtual dispatch mechanism to be GPU firendly. |
| 13 | + * It works both in RGB or spectral mode (via hero wavelength). |
| 14 | + * It includes the Sony Pictures Imageworks set of BSDFs used for movie production. |
| 15 | + |
| 16 | +## Pseudo virtual methods |
| 17 | + |
| 18 | +The header static_virtual.h provides the ```StaticVirtual<type1, type2, ...>``` |
| 19 | +template. If you inherit from it will implement a dispatch() method to execute |
| 20 | +"virtual" methods covering ```type1, type2, ...``` using switch case statements. |
| 21 | +The idea was borrowed from PBRT but the implementation is different. See the |
| 22 | +use in testrender (shading.h/cpp). |
| 23 | + |
| 24 | +## The ```Power``` type |
| 25 | + |
| 26 | +To support both RGB and spectral render with the same code we use the |
| 27 | +```Power``` type, which is just a float array. It has from RGB construction and |
| 28 | +conversion. But when 'lambda_0', the hero wavelength is zero, these are no-ops |
| 29 | +and pure RGB rendering is assueme. Take into account spectral support in BSDL |
| 30 | +is in very early stages. |
| 31 | + |
| 32 | +## Lookup tables |
| 33 | + |
| 34 | +A bunch of BSDFs use albedo lookup tables. Those are generated at build time |
| 35 | +very quickly and put in headers. You shouldn't have to do anything. |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +Either ```include(bsdl.cmake)``` and call ```add_bsdl_library(my_name)``` to |
| 40 | +create a 'my_name' INTERFACE library that you then link, or |
| 41 | +```add_subdirectory (path_to_libbsdl)``` to get it as 'BSDL'. |
| 42 | + |
| 43 | +For the integration, a config header needs to be defined as you can see in |
| 44 | +testrender's 'bsdl_config.h'. |
| 45 | +```cpp |
| 46 | +#define BSDL_INLINE static inline OSL_HOSTDEVICE |
| 47 | +#define BSDL_INLINE_METHOD inline OSL_HOSTDEVICE |
| 48 | +#define BSDL_DECL OSL_DEVICE |
| 49 | +#define BSDL_UNROLL() // Do nothing |
| 50 | + |
| 51 | +#include <BSDL/config.h> |
| 52 | + |
| 53 | +#include <OpenImageIO/fmath.h> |
| 54 | + |
| 55 | +struct BSDLConfig : public bsdl::BSDLDefaultConfig { |
| 56 | + |
| 57 | + // testrender won't do spectral render, just 3 channels covers RGB |
| 58 | + static constexpr int HERO_WAVELENGTH_CHANNELS = 3; |
| 59 | + |
| 60 | + struct Fast { |
| 61 | + static BSDL_INLINE_METHOD float cosf(float x) { return OIIO::fast_cos(x); } |
| 62 | + static BSDL_INLINE_METHOD float sinf(float x) { return OIIO::fast_sin(x); } |
| 63 | + static BSDL_INLINE_METHOD float asinf(float x) { return OIIO::fast_asin(x); } |
| 64 | + static BSDL_INLINE_METHOD float acosf(float x) { return OIIO::fast_acos(x); } |
| 65 | + static BSDL_INLINE_METHOD float atan2f(float y, float x) { return OIIO::fast_atan2(y, x); } |
| 66 | + static BSDL_INLINE_METHOD void sincosf(float x, float* s, float* c) { return OIIO::fast_sincos(x, s, c); } |
| 67 | + static BSDL_INLINE_METHOD float sinpif(float x) { return OIIO::fast_sinpi(x); } |
| 68 | + static BSDL_INLINE_METHOD float cospif(float x) { return OIIO::fast_cospi(x); } |
| 69 | + static BSDL_INLINE_METHOD float expf(float x) { return OIIO::fast_exp(x); } |
| 70 | + static BSDL_INLINE_METHOD float exp2f(float x) { return OIIO::fast_exp2(x); } |
| 71 | + static BSDL_INLINE_METHOD float logf(float x) { return OIIO::fast_log(x); } |
| 72 | + static BSDL_INLINE_METHOD float log2f(float x) { return OIIO::fast_log2(x); } |
| 73 | + static BSDL_INLINE_METHOD float log1pf(float x) { return OIIO::fast_log1p(x); } |
| 74 | + static BSDL_INLINE_METHOD float powf(float x, float y) { return OIIO::fast_safe_pow(x, y); } |
| 75 | + }; |
| 76 | + |
| 77 | + // Don't care for colorspaces/spectral |
| 78 | + static BSDL_INLINE_METHOD ColorSpaceTag current_color_space() { return ColorSpaceTag::sRGB; } |
| 79 | + static BSDL_INLINE_METHOD const JakobHanikaLut* get_jakobhanika_lut(ColorSpaceTag cs) { return nullptr; } |
| 80 | +}; |
| 81 | +``` |
| 82 | +
|
| 83 | +And this header should be included before you include anything else from BSDL. |
| 84 | +
|
| 85 | +If spectral rendering is desired there is ready to use sRGB upsampling via |
| 86 | +spectral primaries by Mallett and Yuksel. For wide gamut color spaces like |
| 87 | +ACEScg we use Jakob and Hanika approach, but you have to ask for the tables |
| 88 | +in .cpp for from cmake: |
| 89 | +``` |
| 90 | +add_bsdl_library(BSDL SPECTRAL_COLOR_SPACES "ACEScg" "ACES2065") |
| 91 | +``` |
| 92 | +
|
| 93 | +which will bake tables to two cpp files and return them in 'BSDL_LUTS_CPP'. |
| 94 | +Then you need to include that in your sources. |
0 commit comments