1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
3 | #pragma once |
4 | |
5 | #include "BsCorePrerequisites.h" |
6 | #include "Utility/BsModule.h" |
7 | |
8 | namespace bs { namespace ct |
9 | { |
10 | /** @addtogroup Renderer-Internal |
11 | * @{ |
12 | */ |
13 | |
14 | /** Helper class that handles generation and processing of textures used for image based lighting. */ |
15 | class BS_CORE_EXPORT IBLUtility : public Module<IBLUtility> |
16 | { |
17 | public: |
18 | /** |
19 | * Performs filtering on the cubemap, populating its mip-maps with filtered values that can be used for |
20 | * evaluating specular reflections. |
21 | * |
22 | * @param[in, out] cubemap Cubemap to filter. Its mip level 0 will be read, filtered and written into |
23 | * other mip levels. |
24 | * @param[in] scratch Temporary cubemap texture to use for the filtering process. Must match the size of |
25 | * the source cubemap. Provide null to automatically create a scratch cubemap. |
26 | */ |
27 | virtual void filterCubemapForSpecular(const SPtr<Texture>& cubemap, const SPtr<Texture>& scratch) const = 0; |
28 | |
29 | /** |
30 | * Performs filtering on the cubemap, populating the output cubemap with values that can be used for evaluating |
31 | * irradiance for use in diffuse lighting. Uses order-5 SH (25 coefficients) and outputs the values in the form of |
32 | * a cubemap. |
33 | * |
34 | * @param[in] cubemap Cubemap to filter. Its mip level 0 will be used as source. |
35 | * @param[in] output Output cubemap to store the irradiance data in. |
36 | */ |
37 | virtual void filterCubemapForIrradiance(const SPtr<Texture>& cubemap, const SPtr<Texture>& output) const = 0; |
38 | |
39 | /** |
40 | * Performs filtering on the cubemap, populating the output texture with values that can be used for evaluating |
41 | * irradiance for use in diffuse lighting. Uses order-3 SH (9 coefficients) and outputs the values in the form of |
42 | * SH coefficients. |
43 | * |
44 | * @param[in] cubemap Cubemap to filter. Its mip level 0 will be used as source. |
45 | * @param[in] output Output texture in which to place the results. Must be allocated using |
46 | * IrradianceReduceMat::createOutputTexture(); |
47 | * @param[in] outputIdx Index in the output buffer at which to write the output coefficients to. |
48 | */ |
49 | virtual void filterCubemapForIrradiance(const SPtr<Texture>& cubemap, const SPtr<Texture>& output, |
50 | UINT32 outputIdx) const = 0; |
51 | |
52 | /** |
53 | * Scales a cubemap and outputs it in the destination texture, using hardware acceleration. If both textures are the |
54 | * same size, performs a copy instead. |
55 | * |
56 | * @param[in] src Source cubemap to scale. |
57 | * @param[in] srcMip Determines which mip level of the source texture to scale. |
58 | * @param[in] dst Desination texture to output the scaled data to. Must be usable as a render target. |
59 | * @param[in] dstMip Determines which mip level of the destination texture to scale. |
60 | */ |
61 | virtual void scaleCubemap(const SPtr<Texture>& src, UINT32 srcMip, const SPtr<Texture>& dst, UINT32 dstMip) const = 0; |
62 | |
63 | |
64 | /** Returns the size of the texture required to store the provided number of SH coefficient sets. */ |
65 | static Vector2I getSHCoeffTextureSize(UINT32 numCoeffSets, UINT32 shOrder); |
66 | |
67 | /** |
68 | * Determines the position of a set of coefficients in the coefficient texture, depending on the coefficient index. |
69 | */ |
70 | static Vector2I getSHCoeffXYFromIdx(UINT32 idx, UINT32 shOrder); |
71 | |
72 | static const UINT32 REFLECTION_CUBEMAP_SIZE; |
73 | static const UINT32 IRRADIANCE_CUBEMAP_SIZE; |
74 | }; |
75 | |
76 | /** Provides easy access to IBLUtility. */ |
77 | BS_CORE_EXPORT const IBLUtility& gIBLUtility(); |
78 | |
79 | /** @} */ |
80 | }} |
81 | |