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#include "Renderer/BsIBLUtility.h"
4#include "Math/BsVector2I.h"
5
6namespace bs { namespace ct
7{
8 const UINT32 IBLUtility::REFLECTION_CUBEMAP_SIZE = 256;
9 const UINT32 IBLUtility::IRRADIANCE_CUBEMAP_SIZE = 32;
10
11 /** Returns the size of the texture required to store the provided number of SH coefficients. */
12 Vector2I IBLUtility::getSHCoeffTextureSize(UINT32 numCoeffSets, UINT32 shOrder)
13 {
14 UINT32 coeffsPerSet = shOrder * shOrder;
15
16 // Assuming the texture maximum size is 4096
17 UINT32 maxSetsPerRow = 4096 / coeffsPerSet;
18
19 Vector2I output;
20 output.x = (numCoeffSets > maxSetsPerRow ? maxSetsPerRow : numCoeffSets) * coeffsPerSet;
21 output.y = 1 + numCoeffSets / (maxSetsPerRow + 1);
22
23 return output;
24 }
25
26 /** Determines the position of a set of coefficients in the coefficient texture, depending on the coefficient index. */
27 Vector2I IBLUtility::getSHCoeffXYFromIdx(UINT32 idx, UINT32 shOrder)
28 {
29 UINT32 coeffsPerSet = shOrder * shOrder;
30
31 // Assuming the texture maximum size is 4096
32 UINT32 maxSetsPerRow = 4096 / coeffsPerSet;
33
34 Vector2I output;
35 output.x = (idx % maxSetsPerRow) * coeffsPerSet;
36 output.y = idx / maxSetsPerRow;
37
38 return output;
39 }
40
41 const IBLUtility& gIBLUtility()
42 {
43 return IBLUtility::instance();
44 }
45}}
46