HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Harmonics.h
Go to the documentation of this file.
1 //
2 // Copyright Contributors to the MaterialX Project
3 // SPDX-License-Identifier: Apache-2.0
4 //
5 
6 #ifndef MATERIALX_HARMONICS_H
7 #define MATERIALX_HARMONICS_H
8 
9 /// @file
10 /// Spherical harmonics functionality
11 
12 #include <MaterialXRender/Export.h>
13 #include <MaterialXRender/Image.h>
14 #include <MaterialXRender/Types.h>
15 
17 
18 /// Class template for a vector of spherical harmonic coefficients.
19 ///
20 /// Template parameter C is the coefficient type (e.g. double, Color3).
21 /// Template parameter B is the number of spherical harmonic bands.
22 template <class C, size_t B> class ShCoeffs
23 {
24  public:
25  static const size_t NUM_BANDS = B;
26  static const size_t NUM_COEFFS = B * B;
27 
28  public:
29  ShCoeffs() = default;
30  explicit ShCoeffs(const std::array<C, NUM_COEFFS>& arr) : _arr(arr) { }
31 
32  /// @name Comparison Operators
33  /// @{
34 
35  /// Return true if the given vector is identical to this one.
36  bool operator==(const ShCoeffs& rhs) const { return _arr == rhs._arr; }
37 
38  /// Return true if the given vector differs from this one.
39  bool operator!=(const ShCoeffs& rhs) const { return _arr != rhs._arr; }
40 
41  /// @}
42  /// @name Indexing Operators
43  /// @{
44 
45  /// Return the coefficient at the given index.
46  C& operator[](size_t i) { return _arr.at(i); }
47 
48  /// Return the const coefficient at the given index.
49  const C& operator[](size_t i) const { return _arr.at(i); }
50 
51  /// @}
52 
53  protected:
54  std::array<C, NUM_COEFFS> _arr;
55 };
56 
57 /// Double-precision scalar coefficients for third-order spherical harmonics.
59 
60 /// Double-precision color coefficients for third-order spherical harmonics.
62 
63 /// Project an environment map to third-order SH, with an optional convolution
64 /// to convert radiance to irradiance.
65 /// @param env An environment map in lat-long format.
66 /// @param irradiance If true, then the returned signal will be convolved
67 /// by a clamped cosine kernel to generate irradiance.
68 /// @return The projection of the environment to third-order SH.
69 MX_RENDER_API Sh3ColorCoeffs projectEnvironment(ConstImagePtr env, bool irradiance = false);
70 
71 /// Normalize an environment to the given radiance.
72 /// @param env An environment map in lat-long format.
73 /// @param envRadiance The radiance to which the environment map should be normalized.
74 /// @param maxTexelRadiance The maximum radiance allowed for any individual texel of the map.
75 /// @return A new normalized environment map, in the same format as the original.
76 MX_RENDER_API ImagePtr normalizeEnvironment(ConstImagePtr env, float envRadiance, float maxTexelRadiance);
77 
78 /// Compute the dominant light direction and color of an environment map.
79 /// @param env An environment map in lat-long format.
80 /// @param lightDir Returns the dominant light direction of the environment.
81 /// @param lightColor Returns the color of the light from the dominant direction.
82 MX_RENDER_API void computeDominantLight(ConstImagePtr env, Vector3& lightDir, Color3& lightColor);
83 
84 /// Render the given spherical harmonic signal to an environment map.
85 /// @param shEnv The color signal of the environment encoded as third-order SH.
86 /// @param width The width of the output environment map.
87 /// @param height The height of the output environment map.
88 /// @return An environment map in the lat-long format.
89 MX_RENDER_API ImagePtr renderEnvironment(const Sh3ColorCoeffs& shEnv, unsigned int width, unsigned int height);
90 
91 /// Render a reference irradiance map from the given environment map,
92 /// using brute-force computations for a slow but accurate result.
93 /// @param env An environment map in lat-long format.
94 /// @param width The width of the output irradiance map.
95 /// @param height The height of the output irradiance map.
96 /// @return An irradiance map in the lat-long format.
98 
100 
101 #endif
#define MATERIALX_NAMESPACE_BEGIN
Definition: Generated.h:25
std::array< C, NUM_COEFFS > _arr
Definition: Harmonics.h:54
MX_RENDER_API ImagePtr renderReferenceIrradiance(ConstImagePtr env, unsigned int width, unsigned int height)
MX_RENDER_API Sh3ColorCoeffs projectEnvironment(ConstImagePtr env, bool irradiance=false)
MX_RENDER_API ImagePtr renderEnvironment(const Sh3ColorCoeffs &shEnv, unsigned int width, unsigned int height)
bool operator==(const ShCoeffs &rhs) const
Return true if the given vector is identical to this one.
Definition: Harmonics.h:36
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
MX_RENDER_API ImagePtr normalizeEnvironment(ConstImagePtr env, float envRadiance, float maxTexelRadiance)
bool operator!=(const ShCoeffs &rhs) const
Return true if the given vector differs from this one.
Definition: Harmonics.h:39
C & operator[](size_t i)
Return the coefficient at the given index.
Definition: Harmonics.h:46
ShCoeffs()=default
static const size_t NUM_BANDS
Definition: Harmonics.h:25
MX_RENDER_API void computeDominantLight(ConstImagePtr env, Vector3 &lightDir, Color3 &lightColor)
ShCoeffs(const std::array< C, NUM_COEFFS > &arr)
Definition: Harmonics.h:30
#define MX_RENDER_API
Definition: Export.h:18
Definition: Types.h:305
GLint GLsizei width
Definition: glcorearb.h:103
const C & operator[](size_t i) const
Return the const coefficient at the given index.
Definition: Harmonics.h:49
#define MATERIALX_NAMESPACE_END
Definition: Generated.h:26
shared_ptr< Image > ImagePtr
A shared pointer to an image.
Definition: Image.h:23
static const size_t NUM_COEFFS
Definition: Harmonics.h:26
shared_ptr< const Image > ConstImagePtr
A shared pointer to a const image.
Definition: Image.h:26