35 return -0.488602512f * v.y;
39 return 0.488602512f * v.z;
43 return -0.488602512f * v.x;
48 return 1.092548431f * (v.x * v.y);
52 return -1.092548431f * (v.y * v.z);
56 return 0.315391565f * (3.0f * v.z * v.z - 1.0f);
60 return -1.092548431f * (v.x * v.z);
64 return 0.546274215f * (v.x * v.x - v.y * v.y);
69 return -0.590043589f * v.y * (3.0f * v.x * v.x - v.y * v.y);
73 return 2.890611442f * (v.y * v.x * v.z);
77 return -0.457045799f * v.y * (-1.0f + 5.0f * v.z * v.z);
81 return 0.373176332f * v.z * (5.0f * v.z * v.z - 3.0f);
85 return -0.457045799f * v.x * (-1.0f + 5.0f * v.z * v.z);
89 return 1.445305721f * v.z * (v.x * v.x - v.y * v.y);
93 return -0.5900435899f * v.x * (v.x * v.x - 3.0f * v.y * v.y);
112 result.M0 = a.
M0 *
b + c.
M0;
119 result.M0 = a.
M0 *
b;
126 result.M0 = a.
M0 *
b;
133 result.M0 = a.
M0 +
b.M0;
157 result.Mn1 = a.
Mn1 *
b + c.
Mn1;
158 result.M0 = a.
M0 *
b + c.
M0;
159 result.Mp1 = a.
Mp1 *
b + c.
Mp1;
166 result.Mn1 = a.
Mn1 *
b;
167 result.M0 = a.
M0 *
b;
168 result.Mp1 = a.
Mp1 *
b;
175 result.Mn1 = a.
Mn1 *
b;
176 result.M0 = a.
M0 *
b;
177 result.Mp1 = a.
Mp1 *
b;
184 result.Mn1 = a.
Mn1 +
b.Mn1;
185 result.M0 = a.
M0 +
b.M0;
186 result.Mp1 = a.
Mp1 +
b.Mp1;
213 result.Mn2 = a.
Mn2 *
b + c.
Mn2;
214 result.Mn1 = a.
Mn1 *
b + c.
Mn1;
215 result.M0 = a.
M0 *
b + c.
M0;
216 result.Mp1 = a.
Mp1 *
b + c.
Mp1;
217 result.Mp2 = a.
Mp2 *
b + c.
Mp2;
224 result.Mn2 = a.
Mn2 *
b;
225 result.Mn1 = a.
Mn1 *
b;
226 result.M0 = a.
M0 *
b;
227 result.Mp1 = a.
Mp1 *
b;
228 result.Mp2 = a.
Mp2 *
b;
235 result.Mn2 = a.
Mn2 +
b.Mn2;
236 result.Mn1 = a.
Mn1 +
b.Mn1;
237 result.M0 = a.
M0 +
b.M0;
238 result.Mp1 = a.
Mp1 +
b.Mp1;
239 result.Mp2 = a.
Mp2 +
b.Mp2;
269 result.Mn3 = a.
Mn3 *
b + c.
Mn3;
270 result.Mn2 = a.
Mn2 *
b + c.
Mn2;
271 result.Mn1 = a.
Mn1 *
b + c.
Mn1;
272 result.M0 = a.
M0 *
b + c.
M0;
273 result.Mp1 = a.
Mp1 *
b + c.
Mp1;
274 result.Mp2 = a.
Mp2 *
b + c.
Mp2;
275 result.Mp3 = a.
Mp3 *
b + c.
Mp3;
282 result.Mn3 = a.
Mn3 *
b;
283 result.Mn2 = a.
Mn2 *
b;
284 result.Mn1 = a.
Mn1 *
b;
285 result.M0 = a.
M0 *
b;
286 result.Mp1 = a.
Mp1 *
b;
287 result.Mp2 = a.
Mp2 *
b;
288 result.Mp3 = a.
Mp3 *
b;
295 result.Mn3 = a.
Mn3 +
b.Mn3;
296 result.Mn2 = a.
Mn2 +
b.Mn2;
297 result.Mn1 = a.
Mn1 +
b.Mn1;
298 result.M0 = a.
M0 +
b.M0;
299 result.Mp1 = a.
Mp1 +
b.Mp1;
300 result.Mp2 = a.
Mp2 +
b.Mp2;
301 result.Mp3 = a.
Mp3 +
b.Mp3;
306template struct BandL0<float>;
307template struct BandL0<float3>;
308template struct BandL0<float4>;
309template struct BandL1<float>;
310template struct BandL1<float3>;
311template struct BandL1<float4>;
312template struct BandL2<float>;
313template struct BandL2<float3>;
314template struct BandL2<float4>;
315template struct BandL3<float>;
316template struct BandL3<float3>;
317template struct BandL3<float4>;
337 return max(
T(0.0f), eval);
349 return max(
T(0.0f), radiance);
361 evaluate_non_linear(
N, L0.
M0.g, R1_g),
362 evaluate_non_linear(
N, L0.
M0.b, R1_b));
364 return radiance /
M_PI;
373 static float evaluate_non_linear(
float3 N,
float R0,
float3 R1)
382 float q = (1.0f +
dot(R1_dir,
N)) / 2.0f;
383 float p = 1.0f + 2.0f * R1_len * rcp_R0;
384 float a = (1.0f - R1_len * rcp_R0) *
safe_rcp(1.0f + R1_len * rcp_R0);
386 return R0 * (a + (1.0f - a) * (p + 1.0f) *
pow(q, p));
410 sh.
L0.M0.xyz = L0_L1_a.xyz;
411 sh.
L1.Mn1.xyz = L0_L1_b.xyz;
412 sh.
L1.M0.xyz = L0_L1_c.xyz;
413 sh.
L1.Mp1.xyz =
float3(L0_L1_a.
w, L0_L1_b.
w, L0_L1_c.
w);
414 sh.
L0.M0.w = L0_L1_vis.
x;
415 sh.
L1.Mn1.w = L0_L1_vis.
y;
416 sh.
L1.M0.w = L0_L1_vis.
z;
417 sh.
L1.Mp1.w = L0_L1_vis.
w;
427 L0_L1_a.xyz = sh.
L0.M0.xyz;
428 L0_L1_b.xyz = sh.
L1.Mn1.xyz;
429 L0_L1_c.xyz = sh.
L1.M0.xyz;
430 L0_L1_a.
w = sh.
L1.Mp1.x;
431 L0_L1_b.
w = sh.
L1.Mp1.y;
432 L0_L1_c.
w = sh.
L1.Mp1.z;
433 L0_L1_vis =
float4(sh.
L0.M0.w, sh.
L1.Mn1.w, sh.
L1.M0.w, sh.
L1.Mp1.w);
450 sh.
L0.M0 = a.
L0.M0 *
b.L0.M0;
451 sh.
L0.M0 += a.
L1.Mn1 *
b.L1.Mn1;
452 sh.
L0.M0 += a.
L1.M0 *
b.L1.M0;
453 sh.
L0.M0 += a.
L1.Mp1 *
b.L1.Mp1;
508 per_channel[0] = rotation * per_channel[0];
509 per_channel[1] = rotation * per_channel[1];
510 per_channel[2] = rotation * per_channel[2];
511 per_channel[3] = rotation * per_channel[3];
515 sh.
L1.Mn1 = per_coef[1];
516 sh.
L1.M0 = -per_coef[2];
517 sh.
L1.Mp1 = per_coef[0];
535 result[0] =
::dot(a_mat[0], b_mat[0]);
536 result[1] =
::dot(a_mat[1], b_mat[1]);
537 result[2] =
::dot(a_mat[2], b_mat[2]);
538 result[3] =
::dot(a_mat[3], b_mat[3]);
555 result.L1.Mn1 = (sh.
L1.Mn1 * fac) * 0.5f + 0.5f;
556 result.L1.M0 = (sh.
L1.M0 * fac) * 0.5f + 0.5f;
557 result.L1.Mp1 = (sh.
L1.Mp1 * fac) * 0.5f + 0.5f;
566 result.L1.Mn1 = (sh.
L1.Mn1 * 2.0f - 1.0f) * fac;
567 result.L1.M0 = (sh.
L1.M0 * 2.0f - 1.0f) * fac;
568 result.L1.Mp1 = (sh.
L1.Mp1 * 2.0f - 1.0f) * fac;
582 float L0_weight = 0.282094792f;
583 float L1_weight = 0.488602512f;
585 L1_weight *= (2.0f / 3.0f);
597 float fac_r = m[0].x /
max(1e-8f,
length(m[0].yzw) * L1_weight);
598 float fac_g = m[1].x /
max(1e-8f,
length(m[1].yzw) * L1_weight);
599 float fac_b = m[2].x /
max(1e-8f,
length(m[2].yzw) * L1_weight);
623 mag_L1.r =
length(per_channel[0].yzw);
624 mag_L1.g =
length(per_channel[1].yzw);
625 mag_L1.b =
length(per_channel[2].yzw);
627 float3 max_sh =
abs(sh.
L0.M0.rgb) * 0.282094792f + mag_L1 * 0.488602512f;
float dot(VecOp< float, D >, VecOp< float, D >) RET
MatBase< R, C > transpose(MatBase< C, R >) RET
float length(VecOp< float, D >) RET
void clamp_value(float value, float min, float max, float &result)
VecT normalize_and_get_length(VecT vector, float &out_length)
float reduce_min(float2 a)
float reduce_max(float2 a)
MatBase< float, 4, 4 > float4x4
MatBase< float, 3, 4 > float3x4
VecBase< float, 3 > float3
SphericalHarmonicL1< float4 > add(SphericalHarmonicL1< float4 > a, SphericalHarmonicL1< float4 > b)
float L2_Mp1_coef(float3 v)
void pack(SphericalHarmonicL1< float4 > sh, float4 &L0_L1_a, float4 &L0_L1_b, float4 &L0_L1_c, float4 &L0_L1_vis)
float L3_M0_coef(float3 v)
SphericalHarmonicL1< float4 > unpack(float4 L0_L1_a, float4 L0_L1_b, float4 L0_L1_c, float4 L0_L1_vis)
SphericalHarmonicL1< float4 > mul(SphericalHarmonicL1< float4 > a, float b)
float L2_Mn1_coef(float3 v)
SphericalHarmonicL1< float4 > clamp_energy(SphericalHarmonicL1< float4 > sh, float clamp_value)
float L3_Mp3_coef(float3 v)
float L2_Mp2_coef(float3 v)
SphericalHarmonicL1< float4 > rotate(float3x3 rotation, SphericalHarmonicL1< float4 > sh)
SphericalHarmonicL1< float4 > compress(SphericalHarmonicL1< float4 > sh)
float L3_Mp2_coef(float3 v)
float L3_Mn2_coef(float3 v)
float L1_M0_coef(float3 v)
float L3_Mn1_coef(float3 v)
SphericalHarmonicL1< float4 > triple_product(SphericalHarmonicL1< float4 > a, SphericalHarmonicL1< float4 > b)
float L2_M0_coef(float3 v)
float L1_Mn1_coef(float3 v)
float L3_Mp1_coef(float3 v)
SphericalHarmonicL1< float4 > madd(SphericalHarmonicL1< float4 > a, float b, SphericalHarmonicL1< float4 > c)
float L3_Mn3_coef(float3 v)
SphericalHarmonicL1< float4 > dering(SphericalHarmonicL1< float4 > sh)
float L1_Mp1_coef(float3 v)
float4 dot(SphericalHarmonicL1< float4 > a, SphericalHarmonicL1< float4 > b)
SphericalHarmonicL1< float4 > decompress(SphericalHarmonicL1< float4 > sh)
float L2_Mn2_coef(float3 v)
T evaluate_lambert(float3 N) const
spherical_harmonics::BandL1< T > L1
spherical_harmonics::BandL0< T > L0
void encode_signal_sample(float3 direction, T amplitude)
T evaluate(float3 direction) const
static BandL0< T > add(BandL0< T > a, BandL0< T > b)
static BandL0< T > mul(BandL0< T > a, T b)
static BandL0< T > madd(BandL0< T > a, float b, BandL0< T > c)
static BandL0< T > mul_scalar(BandL0< T > a, float b)
void encode_signal_sample(float3 direction, T amplitude)
T evaluate(float3 direction) const
static BandL1< T > add(BandL1< T > a, BandL1< T > b)
static BandL1< T > mul(BandL1< T > a, T b)
static BandL1< T > madd(BandL1< T > a, float b, BandL1< T > c)
void encode_signal_sample(float3 direction, T amplitude)
T evaluate(float3 direction) const
static BandL1< T > mul_scalar(BandL1< T > a, float b)
void encode_signal_sample(float3 direction, T amplitude)
static BandL2 madd(BandL2 a, float b, BandL2 c)
T evaluate(float3 direction) const
static BandL2 add(BandL2 a, BandL2 b)
static BandL2 mul(BandL2 a, float b)
static BandL3 madd(BandL3 a, float b, BandL3 c)
static BandL3 add(BandL3 a, BandL3 b)
T evaluate(float3 direction) const
void encode_signal_sample(float3 direction, T amplitude)
static BandL3 mul(BandL3 a, float b)