36 template <
typename ZHVector,
typename SHVector,
typename Vector3>
37 CUGAR_HOST_DEVICE
void rotate_ZH(
const int32 L,
const ZHVector& zh_coeff,
const Vector3& d, SHVector& sh_coeff)
39 for (int32 l = 0; l < L; ++l)
40 for (int32 m = -l; m <= l; ++m)
41 sh_coeff[ l*l + m+l ] = sqrtf( 4.0f*M_PIf /
float(2*l + 1) ) * zh_coeff[l] *
sh( l, m, d );
49 template <
int32 l,
int32 m,
typename Vector3>
50 CUGAR_HOST_DEVICE
float rotate_ZH(
const float zh_l,
const Vector3& d)
52 return sqrtf( 4.0f*M_PIf /
float(2*l + 1) ) * zh_l *
sh( l, m, d );
61 template <
typename ZHVector,
typename SHVector,
typename Vector3>
62 CUGAR_HOST_DEVICE
static void eval(
const ZHVector& zh_coeff,
const Vector3& d, SHVector& sh_coeff)
64 sh_coeff[ l*l + m+l ] = sqrtf( 4.0f*M_PIf /
float(2*l + 1) ) * zh_coeff[l] * sh<l,m>( d );
71 template <
typename ZHVector,
typename SHVector,
typename Vector3>
72 CUGAR_HOST_DEVICE
static void eval(
const ZHVector& zh_coeff,
const Vector3& d, SHVector& sh_coeff)
74 sh_coeff[ l*l + l+l ] = sqrtf( 4.0f*M_PIf /
float(2*l + 1) ) * zh_coeff[l] * sh<l,l>( d );
78 template <
typename ZHVector,
typename SHVector,
typename Vector3>
79 CUGAR_HOST_DEVICE
static void eval(
const ZHVector& zh_coeff,
const Vector3& d, SHVector& sh_coeff)
89 template <
typename ZHVector,
typename SHVector,
typename Vector3>
90 CUGAR_HOST_DEVICE
static void eval(
const ZHVector& zh_coeff,
const Vector3& d, SHVector& sh_coeff)
92 sh_coeff[0] = sqrtf( 4.0f*M_PIf ) * zh_coeff[0] * sh<0,0>( d );
102 template <
int32 L,
typename ZHVector,
typename SHVector,
typename Vector3>
103 CUGAR_HOST_DEVICE
void rotate_ZH(
const ZHVector& zh_coeff,
const Vector3& d, SHVector& sh_coeff)
113 template <
typename Vector3>
114 CUGAR_HOST_DEVICE
float sh(
const int32 l,
const int32 m,
const Vector3& v)
120 return 0.488603f * (m == -1 ? v[0] : (m == 0 ? v[2] : v[1]));
124 return 0.315392f * (3*v[2]*v[2] - 1.0f);
126 return 0.546274f * (v[0]*v[0] - v[1]*v[1]);
128 return 1.092548f * v[0]*v[2];
130 return 1.092548f * v[1]*v[2];
132 return 1.092548f * v[0]*v[1];
135 const float X = v[0];
136 const float Y = v[1];
137 const float Z = v[2];
139 const float m_15_over_4sqrtPI = 0.54627419f;
140 const float m_15_over_2sqrtPI = 1.09254837f;
141 const float m_5_over_4sqrtPI = 0.31539154f;
142 const float m_sqrt2sqrt35_over_8sqrtPI = 0.59004354f;
144 const float m_sqrt7_over_4sqrtPI = 0.37317631f;
145 const float m_sqrt2sqrt21_over_8sqrtPI = 0.45704576f;
146 const float m_sqrt105_over_4sqrtPI = 1.44530571f;
147 const float m_sqrt105_over_2sqrtPI = 2.89061141f;
152 return 0.488603f * (m == -1 ? -Y : (m == 0 ? Z : -X));
156 return m_5_over_4sqrtPI * (3*Z*Z - 1.0f);
158 return -m_15_over_2sqrtPI * X*Z;
160 return m_15_over_4sqrtPI * (X*X - Y*Y);
162 return -m_15_over_2sqrtPI * Y*Z;
164 return m_15_over_2sqrtPI * X*Y;
169 return m_sqrt7_over_4sqrtPI * Z * (5*Z*Z - 3);
171 return -m_sqrt2sqrt21_over_8sqrtPI * X * (5*Z*Z - 1);
173 return m_sqrt105_over_4sqrtPI * (X*X - Y*Y) * Z;
175 return -m_sqrt2sqrt35_over_8sqrtPI * (X*X - 3*Y*Y)*X;
177 return -m_sqrt2sqrt21_over_8sqrtPI * Y * (5*Z*Z - 1);
179 return m_sqrt105_over_2sqrtPI * X*Y*Z;
181 return -m_sqrt2sqrt35_over_8sqrtPI * (3*X*X - Y*Y)*Y;
190 template <
int32 l,
int32 m,
typename Vector3>
191 CUGAR_HOST_DEVICE
float sh(
const Vector3& v)
193 const float X = v[0];
194 const float Y = v[1];
195 const float Z = v[2];
197 const float m_15_over_4sqrtPI = 0.54627419f;
198 const float m_15_over_2sqrtPI = 1.09254837f;
199 const float m_5_over_4sqrtPI = 0.31539154f;
200 const float m_sqrt2sqrt35_over_8sqrtPI = 0.59004354f;
202 const float m_sqrt7_over_4sqrtPI = 0.37317631f;
203 const float m_sqrt2sqrt21_over_8sqrtPI = 0.45704576f;
204 const float m_sqrt105_over_4sqrtPI = 1.44530571f;
205 const float m_sqrt105_over_2sqrtPI = 2.89061141f;
210 return 0.488603f * (m == -1 ? -Y : (m == 0 ? Z : -X));
214 return m_5_over_4sqrtPI * (3*Z*Z - 1.0f);
216 return -m_15_over_2sqrtPI * X*Z;
218 return m_15_over_4sqrtPI * (X*X - Y*Y);
220 return -m_15_over_2sqrtPI * Y*Z;
222 return m_15_over_2sqrtPI * X*Y;
227 return m_sqrt7_over_4sqrtPI * Z * (5*Z*Z - 3);
229 return -m_sqrt2sqrt21_over_8sqrtPI * X * (5*Z*Z - 1);
231 return m_sqrt105_over_4sqrtPI * (X*X - Y*Y) * Z;
233 return -m_sqrt2sqrt35_over_8sqrtPI * (X*X - 3*Y*Y)*X;
235 return -m_sqrt2sqrt21_over_8sqrtPI * Y * (5*Z*Z - 1);
237 return m_sqrt105_over_2sqrtPI * X*Y*Z;
239 return -m_sqrt2sqrt35_over_8sqrtPI * (3*X*X - Y*Y)*Y;
249 template <
int32 l,
typename Vector3>
250 CUGAR_HOST_DEVICE
float sh(
const int32 m,
const Vector3& v)
257 return sh<1,-1>( v );
272 return sh<2,-1>( v );
274 return sh<2,-2>( v );
287 return sh<3,-1>( v );
289 return sh<3,-2>( v );
291 return sh<3,-3>( v );
301 template <
typename Vector3>
305 return sh<0>( 0, d );
307 return sh<1>( i - 2, d );
309 return sh<2>( i - 6, d );
311 return sh<3>( i - 12, d );
323 const float zh[4] = {
330 rotate_ZH<L>( zh, normal,
sh );
332 for (uint32 i = 0; i < COEFFS; ++i)
333 coeffs[i] += sh[i] * w;
343 coeffs[0] = k * 2.0f*sqrtf(M_PIf);
344 for (int32 i = 1; i < COEFFS; ++i)
350 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
365 return 0.5f * (3 * x*x - 1);
374 return 0.5f * x * (5 * x*x - 3);
376 return -3.0f / 2.0f * (5 * x*x - 1) * y;
378 return 15.0f * x * y*y;
380 return -15.0f * y*y*y;
391 template <
typename OutputIterator>
395 const float y = sqrtf(1.0f - x*x);
404 r[1 * n + 0] = x * 0.5f;
405 r[1 * n + 1] = 0.5f * (x * sqrtf(1 - x*x) + asin(x));
407 for (uint32 l = 2; l < n; ++l)
409 for (uint32 m = 0; m < l - 1; ++m)
413 r[l * n + m] = ((l - 2)*(l - 1 + m) * r[(l - 2)*n + m] - g_x) / float( (l+1)*(l-m) );
420 r[l * n + l] = 1 / float(l + 1) * (l*(2*l - 3)*(2*l - 1) * r[(l - 2)*n + l - 2] + x *
sh_legendre_polynomial( 1, 1, x ));
436 return 1 / float(m) * (m >= 0 ? sin(m*phi) : cos(m*phi));
CUGAR_HOST_DEVICE float sh(const int32 l, const int32 m, const Vector3 &v)
Definition: sh_inline.h:114
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE float sh_legendre_polynomial(const uint32 l, const uint32 m, const float x, const float y)
Definition: sh_inline.h:351
static CUGAR_HOST_DEVICE float eval(const int32 i, const Vector3 &d)
Definition: sh_inline.h:302
CUGAR_HOST_DEVICE void rotate_ZH(const int32 L, const ZHVector &zh_coeff, const Vector3 &d, SHVector &sh_coeff)
Definition: sh_inline.h:37
Definition: sh_inline.h:59
CUGAR_HOST_DEVICE float sh_polar_integral(const int32 m, const float phi)
Definition: sh_inline.h:434
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
Definition: sh_inline.h:56
static CUGAR_HOST_DEVICE void clamped_cosine(const Vector3f &normal, const float w, float *coeffs)
Definition: sh_inline.h:321
static CUGAR_HOST_DEVICE void constant(float k, float *coeffs)
Definition: sh_inline.h:341
CUGAR_HOST_DEVICE void sh_legendre_integrals(const uint32 n, const float x, OutputIterator r)
Definition: sh_inline.h:393