forked from microsoft/DirectXMath
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDirectXSH.cpp
4907 lines (4274 loc) · 209 KB
/
DirectXSH.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----------------------------------------------------------------------------------
// DirectXSH.cpp -- C++ Spherical Harmonics Math Library
//
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
//
// http://go.microsoft.com/fwlink/p/?LinkId=262885
//-------------------------------------------------------------------------------------
#ifdef _MSC_VER
#pragma warning( disable : 4619 4456 )
// C4619 #pragma warning warnings
// C4456 declaration hides previous local declaration
#endif
#ifdef __clang__
#pragma clang diagnostic ignored "-Wold-style-cast"
#pragma clang diagnostic ignored "-Wshadow"
#pragma clang diagnostic ignored "-Wunused-const-variable"
#pragma clang diagnostic ignored "-Wunused-function"
#endif
#include "DirectXSH.h"
#include <cassert>
using namespace DirectX;
namespace
{
#ifdef _PREFAST_
#pragma prefast(disable:246, "generated code by maple (nested const variable definitions)")
#endif
const float fExtraNormFac[XM_SH_MAXORDER] = { 2.0f*sqrtf(XM_PI), 2.0f / 3.0f*sqrtf(3.0f*XM_PI), 2.0f / 5.0f*sqrtf(5.0f*XM_PI), 2.0f / 7.0f*sqrtf(7.0f*XM_PI), 2.0f / 3.0f*sqrtf(XM_PI), 2.0f / 11.0f*sqrtf(11.0f*XM_PI) };
// computes the integral of a constant function over a solid angular
// extent. No error checking - only used internaly. This function
// only returns the Yl0 coefficients, since the rest are zero for
// circularly symmetric functions.
const float ComputeCapInt_t1 = sqrtf(0.3141593E1f);
const float ComputeCapInt_t5 = sqrtf(3.0f);
const float ComputeCapInt_t11 = sqrtf(5.0f);
const float ComputeCapInt_t18 = sqrtf(7.0f);
const float ComputeCapInt_t32 = sqrtf(11.0f);
inline void ComputeCapInt(const size_t order, float angle, float *pR)
{
const float t2 = cosf(angle);
const float t3 = ComputeCapInt_t1*t2;
const float t7 = sinf(angle);
const float t8 = t7*t7;
pR[0] = -t3 + ComputeCapInt_t1;
pR[1] = ComputeCapInt_t5*ComputeCapInt_t1*t8 / 2.0f;
if (order > 2)
{
const float t13 = t2*t2;
pR[2] = -ComputeCapInt_t11*ComputeCapInt_t1*t2*(t13 - 1.0f) / 2.0f;
if (order > 3)
{
const float t19 = ComputeCapInt_t18*ComputeCapInt_t1;
const float t20 = t13*t13;
pR[3] = -5.0f / 8.0f*t19*t20 + 3.0f / 4.0f*t19*t13 - t19 / 8.0f;
if (order > 4)
{
pR[4] = -3.0f / 8.0f*t3*(7.0f*t20 - 10.0f*t13 + 3.0f);
if (order > 5)
{
const float t33 = ComputeCapInt_t32*ComputeCapInt_t1;
pR[5] = -21.0f / 16.0f*t33*t20*t13 + 35.0f / 16.0f*t33*t20 - 15.0f / 16.0f*t33*t13 + t33 / 16.0f;
}
}
}
}
}
// input pF only consists of Yl0 values, normalizes coefficients for directional
// lights.
inline float CosWtInt(const size_t order)
{
const float fCW0 = 0.25f;
const float fCW1 = 0.5f;
const float fCW2 = 5.0f / 16.0f;
//const float fCW3 = 0.0f;
const float fCW4 = -3.0f / 32.0f;
//const float fCW5 = 0.0f;
// order has to be at least linear...
float fRet = fCW0 + fCW1;
if (order > 2) fRet += fCW2;
if (order > 4) fRet += fCW4;
// odd degrees >= 3 evaluate to zero integrated against cosine...
return fRet;
}
const float SHEvalHemisphereLight_fSqrtPi = sqrtf(XM_PI);
const float SHEvalHemisphereLight_fSqrtPi3 = sqrtf(XM_PI / 3.0f);
using REAL = float;
#define CONSTANT(x) (x ## f)
// routine generated programmatically for evaluating SH basis for degree 1
// inputs (x,y,z) are a point on the sphere (i.e., must be unit length)
// output is vector b with SH basis evaluated at (x,y,z).
//
inline void sh_eval_basis_1(REAL x, REAL y, REAL z, REAL b[4])
{
/* m=0 */
// l=0
const REAL p_0_0 = CONSTANT(0.282094791773878140);
b[0] = p_0_0; // l=0,m=0
// l=1
const REAL p_1_0 = CONSTANT(0.488602511902919920)*z;
b[2] = p_1_0; // l=1,m=0
/* m=1 */
const REAL s1 = y;
const REAL c1 = x;
// l=1
const REAL p_1_1 = CONSTANT(-0.488602511902919920);
b[1] = p_1_1*s1; // l=1,m=-1
b[3] = p_1_1*c1; // l=1,m=+1
}
// routine generated programmatically for evaluating SH basis for degree 2
// inputs (x,y,z) are a point on the sphere (i.e., must be unit length)
// output is vector b with SH basis evaluated at (x,y,z).
//
inline void sh_eval_basis_2(REAL x, REAL y, REAL z, REAL b[9])
{
const REAL z2 = z*z;
/* m=0 */
// l=0
const REAL p_0_0 = CONSTANT(0.282094791773878140);
b[0] = p_0_0; // l=0,m=0
// l=1
const REAL p_1_0 = CONSTANT(0.488602511902919920)*z;
b[2] = p_1_0; // l=1,m=0
// l=2
const REAL p_2_0 = CONSTANT(0.946174695757560080)*z2 + CONSTANT(-0.315391565252520050);
b[6] = p_2_0; // l=2,m=0
/* m=1 */
const REAL s1 = y;
const REAL c1 = x;
// l=1
const REAL p_1_1 = CONSTANT(-0.488602511902919920);
b[1] = p_1_1*s1; // l=1,m=-1
b[3] = p_1_1*c1; // l=1,m=+1
// l=2
const REAL p_2_1 = CONSTANT(-1.092548430592079200)*z;
b[5] = p_2_1*s1; // l=2,m=-1
b[7] = p_2_1*c1; // l=2,m=+1
/* m=2 */
const REAL s2 = x*s1 + y*c1;
const REAL c2 = x*c1 - y*s1;
// l=2
const REAL p_2_2 = CONSTANT(0.546274215296039590);
b[4] = p_2_2*s2; // l=2,m=-2
b[8] = p_2_2*c2; // l=2,m=+2
}
// routine generated programmatically for evaluating SH basis for degree 3
// inputs (x,y,z) are a point on the sphere (i.e., must be unit length)
// output is vector b with SH basis evaluated at (x,y,z).
//
void sh_eval_basis_3(REAL x, REAL y, REAL z, REAL b[16])
{
const REAL z2 = z*z;
/* m=0 */
// l=0
const REAL p_0_0 = CONSTANT(0.282094791773878140);
b[0] = p_0_0; // l=0,m=0
// l=1
const REAL p_1_0 = CONSTANT(0.488602511902919920)*z;
b[2] = p_1_0; // l=1,m=0
// l=2
const REAL p_2_0 = CONSTANT(0.946174695757560080)*z2 + CONSTANT(-0.315391565252520050);
b[6] = p_2_0; // l=2,m=0
// l=3
const REAL p_3_0 = z*(CONSTANT(1.865881662950577000)*z2 + CONSTANT(-1.119528997770346200));
b[12] = p_3_0; // l=3,m=0
/* m=1 */
const REAL s1 = y;
const REAL c1 = x;
// l=1
const REAL p_1_1 = CONSTANT(-0.488602511902919920);
b[1] = p_1_1*s1; // l=1,m=-1
b[3] = p_1_1*c1; // l=1,m=+1
// l=2
const REAL p_2_1 = CONSTANT(-1.092548430592079200)*z;
b[5] = p_2_1*s1; // l=2,m=-1
b[7] = p_2_1*c1; // l=2,m=+1
// l=3
const REAL p_3_1 = CONSTANT(-2.285228997322328800)*z2 + CONSTANT(0.457045799464465770);
b[11] = p_3_1*s1; // l=3,m=-1
b[13] = p_3_1*c1; // l=3,m=+1
/* m=2 */
const REAL s2 = x*s1 + y*c1;
const REAL c2 = x*c1 - y*s1;
// l=2
const REAL p_2_2 = CONSTANT(0.546274215296039590);
b[4] = p_2_2*s2; // l=2,m=-2
b[8] = p_2_2*c2; // l=2,m=+2
// l=3
const REAL p_3_2 = CONSTANT(1.445305721320277100)*z;
b[10] = p_3_2*s2; // l=3,m=-2
b[14] = p_3_2*c2; // l=3,m=+2
/* m=3 */
const REAL s3 = x*s2 + y*c2;
const REAL c3 = x*c2 - y*s2;
// l=3
const REAL p_3_3 = CONSTANT(-0.590043589926643520);
b[9] = p_3_3*s3; // l=3,m=-3
b[15] = p_3_3*c3; // l=3,m=+3
}
// routine generated programmatically for evaluating SH basis for degree 4
// inputs (x,y,z) are a point on the sphere (i.e., must be unit length)
// output is vector b with SH basis evaluated at (x,y,z).
//
void sh_eval_basis_4(REAL x, REAL y, REAL z, REAL b[25])
{
const REAL z2 = z*z;
/* m=0 */
// l=0
const REAL p_0_0 = CONSTANT(0.282094791773878140);
b[0] = p_0_0; // l=0,m=0
// l=1
const REAL p_1_0 = CONSTANT(0.488602511902919920)*z;
b[2] = p_1_0; // l=1,m=0
// l=2
const REAL p_2_0 = CONSTANT(0.946174695757560080)*z2 + CONSTANT(-0.315391565252520050);
b[6] = p_2_0; // l=2,m=0
// l=3
const REAL p_3_0 = z*(CONSTANT(1.865881662950577000)*z2 + CONSTANT(-1.119528997770346200));
b[12] = p_3_0; // l=3,m=0
// l=4
const REAL p_4_0 = CONSTANT(1.984313483298443000)*z*p_3_0 + CONSTANT(-1.006230589874905300)*p_2_0;
b[20] = p_4_0; // l=4,m=0
/* m=1 */
const REAL s1 = y;
const REAL c1 = x;
// l=1
const REAL p_1_1 = CONSTANT(-0.488602511902919920);
b[1] = p_1_1*s1; // l=1,m=-1
b[3] = p_1_1*c1; // l=1,m=+1
// l=2
const REAL p_2_1 = CONSTANT(-1.092548430592079200)*z;
b[5] = p_2_1*s1; // l=2,m=-1
b[7] = p_2_1*c1; // l=2,m=+1
// l=3
const REAL p_3_1 = CONSTANT(-2.285228997322328800)*z2 + CONSTANT(0.457045799464465770);
b[11] = p_3_1*s1; // l=3,m=-1
b[13] = p_3_1*c1; // l=3,m=+1
// l=4
const REAL p_4_1 = z*(CONSTANT(-4.683325804901024000)*z2 + CONSTANT(2.007139630671867200));
b[19] = p_4_1*s1; // l=4,m=-1
b[21] = p_4_1*c1; // l=4,m=+1
/* m=2 */
const REAL s2 = x*s1 + y*c1;
const REAL c2 = x*c1 - y*s1;
// l=2
const REAL p_2_2 = CONSTANT(0.546274215296039590);
b[4] = p_2_2*s2; // l=2,m=-2
b[8] = p_2_2*c2; // l=2,m=+2
// l=3
const REAL p_3_2 = CONSTANT(1.445305721320277100)*z;
b[10] = p_3_2*s2; // l=3,m=-2
b[14] = p_3_2*c2; // l=3,m=+2
// l=4
const REAL p_4_2 = CONSTANT(3.311611435151459800)*z2 + CONSTANT(-0.473087347878779980);
b[18] = p_4_2*s2; // l=4,m=-2
b[22] = p_4_2*c2; // l=4,m=+2
/* m=3 */
const REAL s3 = x*s2 + y*c2;
const REAL c3 = x*c2 - y*s2;
// l=3
const REAL p_3_3 = CONSTANT(-0.590043589926643520);
b[9] = p_3_3*s3; // l=3,m=-3
b[15] = p_3_3*c3; // l=3,m=+3
// l=4
const REAL p_4_3 = CONSTANT(-1.770130769779930200)*z;
b[17] = p_4_3*s3; // l=4,m=-3
b[23] = p_4_3*c3; // l=4,m=+3
/* m=4 */
const REAL s4 = x*s3 + y*c3;
const REAL c4 = x*c3 - y*s3;
// l=4
const REAL p_4_4 = CONSTANT(0.625835735449176030);
b[16] = p_4_4*s4; // l=4,m=-4
b[24] = p_4_4*c4; // l=4,m=+4
}
// routine generated programmatically for evaluating SH basis for degree 5
// inputs (x,y,z) are a point on the sphere (i.e., must be unit length)
// output is vector b with SH basis evaluated at (x,y,z).
//
void sh_eval_basis_5(REAL x, REAL y, REAL z, REAL b[36])
{
const REAL z2 = z*z;
/* m=0 */
// l=0
const REAL p_0_0 = CONSTANT(0.282094791773878140);
b[0] = p_0_0; // l=0,m=0
// l=1
const REAL p_1_0 = CONSTANT(0.488602511902919920)*z;
b[2] = p_1_0; // l=1,m=0
// l=2
const REAL p_2_0 = CONSTANT(0.946174695757560080)*z2 + CONSTANT(-0.315391565252520050);
b[6] = p_2_0; // l=2,m=0
// l=3
const REAL p_3_0 = z*(CONSTANT(1.865881662950577000)*z2 + CONSTANT(-1.119528997770346200));
b[12] = p_3_0; // l=3,m=0
// l=4
const REAL p_4_0 = CONSTANT(1.984313483298443000)*z*p_3_0 + CONSTANT(-1.006230589874905300)*p_2_0;
b[20] = p_4_0; // l=4,m=0
// l=5
const REAL p_5_0 = CONSTANT(1.989974874213239700)*z*p_4_0 + CONSTANT(-1.002853072844814000)*p_3_0;
b[30] = p_5_0; // l=5,m=0
/* m=1 */
const REAL s1 = y;
const REAL c1 = x;
// l=1
const REAL p_1_1 = CONSTANT(-0.488602511902919920);
b[1] = p_1_1*s1; // l=1,m=-1
b[3] = p_1_1*c1; // l=1,m=+1
// l=2
const REAL p_2_1 = CONSTANT(-1.092548430592079200)*z;
b[5] = p_2_1*s1; // l=2,m=-1
b[7] = p_2_1*c1; // l=2,m=+1
// l=3
const REAL p_3_1 = CONSTANT(-2.285228997322328800)*z2 + CONSTANT(0.457045799464465770);
b[11] = p_3_1*s1; // l=3,m=-1
b[13] = p_3_1*c1; // l=3,m=+1
// l=4
const REAL p_4_1 = z*(CONSTANT(-4.683325804901024000)*z2 + CONSTANT(2.007139630671867200));
b[19] = p_4_1*s1; // l=4,m=-1
b[21] = p_4_1*c1; // l=4,m=+1
// l=5
const REAL p_5_1 = CONSTANT(2.031009601158990200)*z*p_4_1 + CONSTANT(-0.991031208965114650)*p_3_1;
b[29] = p_5_1*s1; // l=5,m=-1
b[31] = p_5_1*c1; // l=5,m=+1
/* m=2 */
const REAL s2 = x*s1 + y*c1;
const REAL c2 = x*c1 - y*s1;
// l=2
const REAL p_2_2 = CONSTANT(0.546274215296039590);
b[4] = p_2_2*s2; // l=2,m=-2
b[8] = p_2_2*c2; // l=2,m=+2
// l=3
const REAL p_3_2 = CONSTANT(1.445305721320277100)*z;
b[10] = p_3_2*s2; // l=3,m=-2
b[14] = p_3_2*c2; // l=3,m=+2
// l=4
const REAL p_4_2 = CONSTANT(3.311611435151459800)*z2 + CONSTANT(-0.473087347878779980);
b[18] = p_4_2*s2; // l=4,m=-2
b[22] = p_4_2*c2; // l=4,m=+2
// l=5
const REAL p_5_2 = z*(CONSTANT(7.190305177459987500)*z2 + CONSTANT(-2.396768392486662100));
b[28] = p_5_2*s2; // l=5,m=-2
b[32] = p_5_2*c2; // l=5,m=+2
/* m=3 */
const REAL s3 = x*s2 + y*c2;
const REAL c3 = x*c2 - y*s2;
// l=3
const REAL p_3_3 = CONSTANT(-0.590043589926643520);
b[9] = p_3_3*s3; // l=3,m=-3
b[15] = p_3_3*c3; // l=3,m=+3
// l=4
const REAL p_4_3 = CONSTANT(-1.770130769779930200)*z;
b[17] = p_4_3*s3; // l=4,m=-3
b[23] = p_4_3*c3; // l=4,m=+3
// l=5
const REAL p_5_3 = CONSTANT(-4.403144694917253700)*z2 + CONSTANT(0.489238299435250430);
b[27] = p_5_3*s3; // l=5,m=-3
b[33] = p_5_3*c3; // l=5,m=+3
/* m=4 */
const REAL s4 = x*s3 + y*c3;
const REAL c4 = x*c3 - y*s3;
// l=4
const REAL p_4_4 = CONSTANT(0.625835735449176030);
b[16] = p_4_4*s4; // l=4,m=-4
b[24] = p_4_4*c4; // l=4,m=+4
// l=5
const REAL p_5_4 = CONSTANT(2.075662314881041100)*z;
b[26] = p_5_4*s4; // l=5,m=-4
b[34] = p_5_4*c4; // l=5,m=+4
/* m=5 */
const REAL s5 = x*s4 + y*c4;
const REAL c5 = x*c4 - y*s4;
// l=5
const REAL p_5_5 = CONSTANT(-0.656382056840170150);
b[25] = p_5_5*s5; // l=5,m=-5
b[35] = p_5_5*c5; // l=5,m=+5
}
const REAL M_PIjs = (REAL)(4.0*atan(1.0));
const REAL maxang = (REAL)(M_PIjs / 2);
const int NSH0 = 1;
const int NSH1 = 4;
const int NSH2 = 9;
const int NSH3 = 16;
const int NSH4 = 25;
const int NSH5 = 36;
const int NSH6 = 49;
const int NSH7 = 64;
const int NSH8 = 81;
const int NSH9 = 100;
const int NL0 = 1;
const int NL1 = 3;
const int NL2 = 5;
const int NL3 = 7;
const int NL4 = 9;
const int NL5 = 11;
const int NL6 = 13;
const int NL7 = 15;
const int NL8 = 17;
const int NL9 = 19;
inline void rot(REAL ct, REAL st, REAL x, REAL y, REAL &xout, REAL &yout)
{
xout = x*ct - y*st;
yout = y*ct + x*st;
}
inline void rot_inv(REAL ct, REAL st, REAL x, REAL y, REAL &xout, REAL &yout)
{
xout = x*ct + y*st;
yout = y*ct - x*st;
}
inline void rot_1(REAL ct, REAL st, REAL ctm[1], REAL stm[1])
{
ctm[0] = ct;
stm[0] = st;
}
inline void rot_2(REAL ct, REAL st, REAL ctm[2], REAL stm[2])
{
REAL ct2 = CONSTANT(2.0)*ct;
ctm[0] = ct;
stm[0] = st;
ctm[1] = ct2*ct - CONSTANT(1.0);
stm[1] = ct2*st;
}
inline void rot_3(REAL ct, REAL st, REAL ctm[3], REAL stm[3])
{
REAL ct2 = CONSTANT(2.0)*ct;
ctm[0] = ct;
stm[0] = st;
ctm[1] = ct2*ct - CONSTANT(1.0);
stm[1] = ct2*st;
ctm[2] = ct2*ctm[1] - ct;
stm[2] = ct2*stm[1] - st;
}
inline void rot_4(REAL ct, REAL st, REAL ctm[4], REAL stm[4])
{
REAL ct2 = CONSTANT(2.0)*ct;
ctm[0] = ct;
stm[0] = st;
ctm[1] = ct2*ct - CONSTANT(1.0);
stm[1] = ct2*st;
ctm[2] = ct2*ctm[1] - ct;
stm[2] = ct2*stm[1] - st;
ctm[3] = ct2*ctm[2] - ctm[1];
stm[3] = ct2*stm[2] - stm[1];
}
inline void rot_5(REAL ct, REAL st, REAL ctm[5], REAL stm[5])
{
REAL ct2 = CONSTANT(2.0)*ct;
ctm[0] = ct;
stm[0] = st;
ctm[1] = ct2*ct - CONSTANT(1.0);
stm[1] = ct2*st;
ctm[2] = ct2*ctm[1] - ct;
stm[2] = ct2*stm[1] - st;
ctm[3] = ct2*ctm[2] - ctm[1];
stm[3] = ct2*stm[2] - stm[1];
ctm[4] = ct2*ctm[3] - ctm[2];
stm[4] = ct2*stm[3] - stm[2];
}
inline void sh_rotz_1(REAL ctm[1], REAL stm[1], REAL y[NL1], REAL yr[NL1])
{
yr[1] = y[1];
rot_inv(ctm[0], stm[0], y[0], y[2], yr[0], yr[2]);
}
inline void sh_rotz_2(REAL ctm[2], REAL stm[2], REAL y[NL2], REAL yr[NL2])
{
yr[2] = y[2];
rot_inv(ctm[0], stm[0], y[1], y[3], yr[1], yr[3]);
rot_inv(ctm[1], stm[1], y[0], y[4], yr[0], yr[4]);
}
inline void sh_rotz_3(REAL ctm[3], REAL stm[3], REAL y[NL3], REAL yr[NL3])
{
yr[3] = y[3];
rot_inv(ctm[0], stm[0], y[2], y[4], yr[2], yr[4]);
rot_inv(ctm[1], stm[1], y[1], y[5], yr[1], yr[5]);
rot_inv(ctm[2], stm[2], y[0], y[6], yr[0], yr[6]);
}
inline void sh_rotz_4(REAL ctm[4], REAL stm[4], REAL y[NL4], REAL yr[NL4])
{
yr[4] = y[4];
rot_inv(ctm[0], stm[0], y[3], y[5], yr[3], yr[5]);
rot_inv(ctm[1], stm[1], y[2], y[6], yr[2], yr[6]);
rot_inv(ctm[2], stm[2], y[1], y[7], yr[1], yr[7]);
rot_inv(ctm[3], stm[3], y[0], y[8], yr[0], yr[8]);
}
inline void sh_rotz_5(REAL ctm[5], REAL stm[5], REAL y[NL5], REAL yr[NL5])
{
yr[5] = y[5];
rot_inv(ctm[0], stm[0], y[4], y[6], yr[4], yr[6]);
rot_inv(ctm[1], stm[1], y[3], y[7], yr[3], yr[7]);
rot_inv(ctm[2], stm[2], y[2], y[8], yr[2], yr[8]);
rot_inv(ctm[3], stm[3], y[1], y[9], yr[1], yr[9]);
rot_inv(ctm[4], stm[4], y[0], y[10], yr[0], yr[10]);
}
// rotation code generated programmatically by rotatex (2000x4000 samples, eps=1e-008)
const REAL fx_1_001 = (REAL)(sqrt(1.0) / 1.0); // 1
const REAL fx_1_002 = (REAL)(-sqrt(1.0) / 1.0); // -1.00000030843
inline void sh_rotx90_1(REAL y[], REAL yr[])
{
yr[0] = fx_1_001*y[1];
yr[1] = fx_1_002*y[0];
yr[2] = fx_1_001*y[2];
};
inline void sh_rotx90_inv_1(REAL y[], REAL yr[])
{
yr[0] = fx_1_002*y[1];
yr[1] = fx_1_001*y[0];
yr[2] = fx_1_001*y[2];
}
const REAL fx_2_001 = (REAL)(sqrt(4.0) / 2.0); // 1
const REAL fx_2_002 = (REAL)(-sqrt(4.0) / 2.0); // -1
const REAL fx_2_003 = (REAL)(-sqrt(1.0) / 2.0); // -0.500000257021
const REAL fx_2_004 = (REAL)(-sqrt(3.0) / 2.0); // -0.866025848959
const REAL fx_2_005 = (REAL)(sqrt(1.0) / 2.0); // 0.5
inline void sh_rotx90_2(REAL y[], REAL yr[])
{
yr[0] = fx_2_001*y[3];
yr[1] = fx_2_002*y[1];
yr[2] = fx_2_003*y[2] + fx_2_004*y[4];
yr[3] = fx_2_002*y[0];
yr[4] = fx_2_004*y[2] + fx_2_005*y[4];
};
inline void sh_rotx90_inv_2(REAL y[], REAL yr[])
{
yr[0] = fx_2_002*y[3];
yr[1] = fx_2_002*y[1];
yr[2] = fx_2_003*y[2] + fx_2_004*y[4];
yr[3] = fx_2_001*y[0];
yr[4] = fx_2_004*y[2] + fx_2_005*y[4];
}
const REAL fx_3_001 = (REAL)(-sqrt(10.0) / 4.0); // -0.790569415042
const REAL fx_3_002 = (REAL)(sqrt(6.0) / 4.0); // 0.612372435696
const REAL fx_3_003 = (REAL)(-sqrt(16.0) / 4.0); // -1
const REAL fx_3_004 = (REAL)(-sqrt(6.0) / 4.0); // -0.612372435695
const REAL fx_3_005 = (REAL)(-sqrt(1.0) / 4.0); // -0.25
const REAL fx_3_006 = (REAL)(-sqrt(15.0) / 4.0); // -0.968245836551
const REAL fx_3_007 = (REAL)(sqrt(1.0) / 4.0); // 0.25
const REAL fx_3_008 = (REAL)(sqrt(10.0) / 4.0); // 0.790569983984
inline void sh_rotx90_3(REAL y[], REAL yr[])
{
yr[0] = fx_3_001*y[3] + fx_3_002*y[5];
yr[1] = fx_3_003*y[1];
yr[2] = fx_3_004*y[3] + fx_3_001*y[5];
yr[3] = fx_3_008*y[0] + fx_3_002*y[2];
yr[4] = fx_3_005*y[4] + fx_3_006*y[6];
yr[5] = fx_3_004*y[0] - fx_3_001*y[2];
yr[6] = fx_3_006*y[4] + fx_3_007*y[6];
};
inline void sh_rotx90_inv_3(REAL y[], REAL yr[])
{
yr[0] = fx_3_008*y[3] + fx_3_004*y[5];
yr[1] = fx_3_003*y[1];
yr[2] = fx_3_002*y[3] - fx_3_001*y[5];
yr[3] = fx_3_001*y[0] + fx_3_004*y[2];
yr[4] = fx_3_005*y[4] + fx_3_006*y[6];
yr[5] = fx_3_002*y[0] + fx_3_001*y[2];
yr[6] = fx_3_006*y[4] + fx_3_007*y[6];
}
const REAL fx_4_001 = (REAL)(-sqrt(56.0) / 8.0); // -0.935414346694
const REAL fx_4_002 = (REAL)(sqrt(8.0) / 8.0); // 0.353553390593
const REAL fx_4_003 = (REAL)(-sqrt(36.0) / 8.0); // -0.75
const REAL fx_4_004 = (REAL)(sqrt(28.0) / 8.0); // 0.661437827766
const REAL fx_4_005 = (REAL)(-sqrt(8.0) / 8.0); // -0.353553390593
const REAL fx_4_006 = (REAL)(sqrt(36.0) / 8.0); // 0.749999999999
const REAL fx_4_007 = (REAL)(sqrt(9.0) / 8.0); // 0.37500034698
const REAL fx_4_008 = (REAL)(sqrt(20.0) / 8.0); // 0.559017511622
const REAL fx_4_009 = (REAL)(sqrt(35.0) / 8.0); // 0.739510657141
const REAL fx_4_010 = (REAL)(sqrt(16.0) / 8.0); // 0.5
const REAL fx_4_011 = (REAL)(-sqrt(28.0) / 8.0); // -0.661437827766
const REAL fx_4_012 = (REAL)(sqrt(1.0) / 8.0); // 0.125
const REAL fx_4_013 = (REAL)(sqrt(56.0) / 8.0); // 0.935414346692
inline void sh_rotx90_4(REAL y[], REAL yr[])
{
yr[0] = fx_4_001*y[5] + fx_4_002*y[7];
yr[1] = fx_4_003*y[1] + fx_4_004*y[3];
yr[2] = fx_4_005*y[5] + fx_4_001*y[7];
yr[3] = fx_4_004*y[1] + fx_4_006*y[3];
yr[4] = fx_4_007*y[4] + fx_4_008*y[6] + fx_4_009*y[8];
yr[5] = fx_4_013*y[0] + fx_4_002*y[2];
yr[6] = fx_4_008*y[4] + fx_4_010*y[6] + fx_4_011*y[8];
yr[7] = fx_4_005*y[0] - fx_4_001*y[2];
yr[8] = fx_4_009*y[4] + fx_4_011*y[6] + fx_4_012*y[8];
};
inline void sh_rotx90_inv_4(REAL y[], REAL yr[])
{
yr[0] = fx_4_013*y[5] + fx_4_005*y[7];
yr[1] = fx_4_003*y[1] + fx_4_004*y[3];
yr[2] = fx_4_002*y[5] - fx_4_001*y[7];
yr[3] = fx_4_004*y[1] + fx_4_006*y[3];
yr[4] = fx_4_007*y[4] + fx_4_008*y[6] + fx_4_009*y[8];
yr[5] = fx_4_001*y[0] + fx_4_005*y[2];
yr[6] = fx_4_008*y[4] + fx_4_010*y[6] + fx_4_011*y[8];
yr[7] = fx_4_002*y[0] + fx_4_001*y[2];
yr[8] = fx_4_009*y[4] + fx_4_011*y[6] + fx_4_012*y[8];
}
const REAL fx_5_001 = (REAL)(sqrt(126.0) / 16.0); // 0.70156076002
const REAL fx_5_002 = (REAL)(-sqrt(120.0) / 16.0); // -0.684653196882
const REAL fx_5_003 = (REAL)(sqrt(10.0) / 16.0); // 0.197642353761
const REAL fx_5_004 = (REAL)(-sqrt(64.0) / 16.0); // -0.5
const REAL fx_5_005 = (REAL)(sqrt(192.0) / 16.0); // 0.866025403784
const REAL fx_5_006 = (REAL)(sqrt(70.0) / 16.0); // 0.522912516584
const REAL fx_5_007 = (REAL)(sqrt(24.0) / 16.0); // 0.306186217848
const REAL fx_5_008 = (REAL)(-sqrt(162.0) / 16.0); // -0.795495128835
const REAL fx_5_009 = (REAL)(sqrt(64.0) / 16.0); // 0.5
const REAL fx_5_010 = (REAL)(sqrt(60.0) / 16.0); // 0.484122918274
const REAL fx_5_011 = (REAL)(sqrt(112.0) / 16.0); // 0.661437827763
const REAL fx_5_012 = (REAL)(sqrt(84.0) / 16.0); // 0.572821961867
const REAL fx_5_013 = (REAL)(sqrt(4.0) / 16.0); // 0.125
const REAL fx_5_014 = (REAL)(sqrt(42.0) / 16.0); // 0.405046293649
const REAL fx_5_015 = (REAL)(sqrt(210.0) / 16.0); // 0.905711046633
const REAL fx_5_016 = (REAL)(sqrt(169.0) / 16.0); // 0.8125
const REAL fx_5_017 = (REAL)(-sqrt(45.0) / 16.0); // -0.419262745781
const REAL fx_5_018 = (REAL)(sqrt(1.0) / 16.0); // 0.0625
const REAL fx_5_019 = (REAL)(-sqrt(126.0) / 16.0); // -0.701561553415
const REAL fx_5_020 = (REAL)(sqrt(120.0) / 16.0); // 0.684653196881
const REAL fx_5_021 = (REAL)(-sqrt(10.0) / 16.0); // -0.197642353761
const REAL fx_5_022 = (REAL)(-sqrt(70.0) / 16.0); // -0.522913107945
const REAL fx_5_023 = (REAL)(-sqrt(60.0) / 16.0); // -0.48412346577
inline void sh_rotx90_5(REAL y[], REAL yr[])
{
yr[0] = fx_5_001*y[5] + fx_5_002*y[7] + fx_5_003*y[9];
yr[1] = fx_5_004*y[1] + fx_5_005*y[3];
yr[2] = fx_5_006*y[5] + fx_5_007*y[7] + fx_5_008*y[9];
yr[3] = fx_5_005*y[1] + fx_5_009*y[3];
yr[4] = fx_5_010*y[5] + fx_5_011*y[7] + fx_5_012*y[9];
yr[5] = fx_5_019*y[0] + fx_5_022*y[2] + fx_5_023*y[4];
yr[6] = fx_5_013*y[6] + fx_5_014*y[8] + fx_5_015*y[10];
yr[7] = fx_5_020*y[0] - fx_5_007*y[2] - fx_5_011*y[4];
yr[8] = fx_5_014*y[6] + fx_5_016*y[8] + fx_5_017*y[10];
yr[9] = fx_5_021*y[0] - fx_5_008*y[2] - fx_5_012*y[4];
yr[10] = fx_5_015*y[6] + fx_5_017*y[8] + fx_5_018*y[10];
};
inline void sh_rotx90_inv_5(REAL y[], REAL yr[])
{
yr[0] = fx_5_019*y[5] + fx_5_020*y[7] + fx_5_021*y[9];
yr[1] = fx_5_004*y[1] + fx_5_005*y[3];
yr[2] = fx_5_022*y[5] - fx_5_007*y[7] - fx_5_008*y[9];
yr[3] = fx_5_005*y[1] + fx_5_009*y[3];
yr[4] = fx_5_023*y[5] - fx_5_011*y[7] - fx_5_012*y[9];
yr[5] = fx_5_001*y[0] + fx_5_006*y[2] + fx_5_010*y[4];
yr[6] = fx_5_013*y[6] + fx_5_014*y[8] + fx_5_015*y[10];
yr[7] = fx_5_002*y[0] + fx_5_007*y[2] + fx_5_011*y[4];
yr[8] = fx_5_014*y[6] + fx_5_016*y[8] + fx_5_017*y[10];
yr[9] = fx_5_003*y[0] + fx_5_008*y[2] + fx_5_012*y[4];
yr[10] = fx_5_015*y[6] + fx_5_017*y[8] + fx_5_018*y[10];
}
inline void sh_rot_1(REAL m[3 * 3], REAL y[NL1], REAL yr[NL1])
{
REAL yr0 = m[4] * y[0] - m[5] * y[1] + m[3] * y[2];
REAL yr1 = m[8] * y[1] - m[7] * y[0] - m[6] * y[2];
REAL yr2 = m[1] * y[0] - m[2] * y[1] + m[0] * y[2];
yr[0] = yr0;
yr[1] = yr1;
yr[2] = yr2;
}
inline void sh_roty_1(REAL ctm[1], REAL stm[1], REAL y[NL1], REAL yr[NL1])
{
yr[0] = y[0];
rot_inv(ctm[0], stm[0], y[1], y[2], yr[1], yr[2]);
}
inline void sh_roty_2(REAL ctm[2], REAL stm[2], REAL y[NL2], REAL yr[NL2])
{
REAL ytmp[NL2];
sh_rotx90_2(y, yr);
sh_rotz_2(ctm, stm, yr, ytmp);
sh_rotx90_inv_2(ytmp, yr);
}
inline void sh_roty_3(REAL ctm[3], REAL stm[3], REAL y[NL3], REAL yr[NL3])
{
REAL ytmp[NL3];
sh_rotx90_3(y, yr);
sh_rotz_3(ctm, stm, yr, ytmp);
sh_rotx90_inv_3(ytmp, yr);
}
inline void sh_roty_4(REAL ctm[4], REAL stm[4], REAL y[NL4], REAL yr[NL4])
{
REAL ytmp[NL4];
sh_rotx90_4(y, yr);
sh_rotz_4(ctm, stm, yr, ytmp);
sh_rotx90_inv_4(ytmp, yr);
}
inline void sh_roty_5(REAL ctm[5], REAL stm[5], REAL y[NL5], REAL yr[NL5])
{
REAL ytmp[NL5];
sh_rotx90_5(y, yr);
sh_rotz_5(ctm, stm, yr, ytmp);
sh_rotx90_inv_5(ytmp, yr);
}
#define ROT_TOL CONSTANT(1e-4)
/*
Finds cosine,sine pairs for zyz rotation (i.e. rotation R_z2 R_y R_z1 v).
The rotation is one which maps mx to (1,0,0) and mz to (0,0,1).
*/
inline void zyz(REAL m[3 * 3], REAL &zc1, REAL &zs1, REAL &yc, REAL &ys, REAL &zc2, REAL &zs2)
{
REAL cz = m[8];
// rotate so that (cx,cy,0) aligns to (1,0,0)
REAL cxylen = (REAL)sqrtf(1.0f - cz*cz);
if (cxylen >= ROT_TOL)
{
// if above is a NaN, will do the correct thing
yc = cz;
ys = cxylen;
REAL len67inv = 1.0f / sqrtf(m[6] * m[6] + m[7] * m[7]);
zc1 = -m[6] * len67inv;
zs1 = m[7] * len67inv;
REAL len25inv = 1.0f / sqrtf(m[2] * m[2] + m[5] * m[5]);
zc2 = m[2] * len25inv;
zs2 = m[5] * len25inv;
}
else { // m[6],m[7],m[8] already aligned to (0,0,1)
zc1 = 1.0; zs1 = 0.0; // identity
yc = cz; ys = 0.0; // identity
zc2 = m[0] * cz; zs2 = -m[1]; // align x axis (mx[0],mx[1],0) to (1,0,0)
}
}
inline void sh_rotzyz_2(REAL zc1m[2], REAL zs1m[2], REAL ycm[2], REAL ysm[2], REAL zc2m[2], REAL zs2m[2], REAL y[NL2], REAL yr[NL2])
{
REAL ytmp[NL2];
sh_rotz_2(zc1m, zs1m, y, yr);
sh_roty_2(ycm, ysm, yr, ytmp);
sh_rotz_2(zc2m, zs2m, ytmp, yr);
}
inline void sh_rotzyz_3(REAL zc1m[3], REAL zs1m[3], REAL ycm[3], REAL ysm[3], REAL zc2m[3], REAL zs2m[3], REAL y[NL3], REAL yr[NL3])
{
REAL ytmp[NL3];
sh_rotz_3(zc1m, zs1m, y, yr);
sh_roty_3(ycm, ysm, yr, ytmp);
sh_rotz_3(zc2m, zs2m, ytmp, yr);
}
inline void sh_rotzyz_4(REAL zc1m[4], REAL zs1m[4], REAL ycm[4], REAL ysm[4], REAL zc2m[4], REAL zs2m[4], REAL y[NL4], REAL yr[NL4])
{
REAL ytmp[NL4];
sh_rotz_4(zc1m, zs1m, y, yr);
sh_roty_4(ycm, ysm, yr, ytmp);
sh_rotz_4(zc2m, zs2m, ytmp, yr);
}
inline void sh_rotzyz_5(REAL zc1m[5], REAL zs1m[5], REAL ycm[5], REAL ysm[5], REAL zc2m[5], REAL zs2m[5], REAL y[NL5], REAL yr[NL5])
{
REAL ytmp[NL5];
sh_rotz_5(zc1m, zs1m, y, yr);
sh_roty_5(ycm, ysm, yr, ytmp);
sh_rotz_5(zc2m, zs2m, ytmp, yr);
}
inline void sh3_rot(REAL m[3 * 3], REAL zc1, REAL zs1, REAL yc, REAL ys, REAL zc2, REAL zs2, REAL y[NSH3], REAL yr[NSH3])
{
REAL zc1m[3], zs1m[3];
rot_3(zc1, zs1, zc1m, zs1m);
REAL ycm[3], ysm[3];
rot_3(yc, ys, ycm, ysm);
REAL zc2m[3], zs2m[3];
rot_3(zc2, zs2, zc2m, zs2m);
yr[0] = y[0];
sh_rot_1(m, y + NSH0, yr + NSH0);
sh_rotzyz_2(zc1m, zs1m, ycm, ysm, zc2m, zs2m, y + NSH1, yr + NSH1);
sh_rotzyz_3(zc1m, zs1m, ycm, ysm, zc2m, zs2m, y + NSH2, yr + NSH2);
}
inline void sh4_rot(REAL m[3 * 3], REAL zc1, REAL zs1, REAL yc, REAL ys, REAL zc2, REAL zs2, REAL y[NSH4], REAL yr[NSH4])
{
REAL zc1m[4], zs1m[4];
rot_4(zc1, zs1, zc1m, zs1m);
REAL ycm[4], ysm[4];
rot_4(yc, ys, ycm, ysm);
REAL zc2m[4], zs2m[4];
rot_4(zc2, zs2, zc2m, zs2m);
yr[0] = y[0];
sh_rot_1(m, y + NSH0, yr + NSH0);
sh_rotzyz_2(zc1m, zs1m, ycm, ysm, zc2m, zs2m, y + NSH1, yr + NSH1);
sh_rotzyz_3(zc1m, zs1m, ycm, ysm, zc2m, zs2m, y + NSH2, yr + NSH2);
sh_rotzyz_4(zc1m, zs1m, ycm, ysm, zc2m, zs2m, y + NSH3, yr + NSH3);
}
inline void sh5_rot(REAL m[3 * 3], REAL zc1, REAL zs1, REAL yc, REAL ys, REAL zc2, REAL zs2, REAL y[NSH5], REAL yr[NSH5])
{
REAL zc1m[5], zs1m[5];
rot_5(zc1, zs1, zc1m, zs1m);
REAL ycm[5], ysm[5];
rot_5(yc, ys, ycm, ysm);
REAL zc2m[5], zs2m[5];
rot_5(zc2, zs2, zc2m, zs2m);
yr[0] = y[0];
sh_rot_1(m, y + NSH0, yr + NSH0);
sh_rotzyz_2(zc1m, zs1m, ycm, ysm, zc2m, zs2m, y + NSH1, yr + NSH1);
sh_rotzyz_3(zc1m, zs1m, ycm, ysm, zc2m, zs2m, y + NSH2, yr + NSH2);
sh_rotzyz_4(zc1m, zs1m, ycm, ysm, zc2m, zs2m, y + NSH3, yr + NSH3);
sh_rotzyz_5(zc1m, zs1m, ycm, ysm, zc2m, zs2m, y + NSH4, yr + NSH4);
}
inline void sh1_rot(REAL m[3 * 3], REAL y[NSH1], REAL yr[NSH1])
{
yr[0] = y[0];
sh_rot_1(m, y + NSH0, yr + NSH0);
}
inline void sh3_rot(REAL m[3 * 3], REAL y[NSH3], REAL yr[NSH3])
{
REAL zc1, zs1, yc, ys, zc2, zs2;
zyz(m, zc1, zs1, yc, ys, zc2, zs2);
sh3_rot(m, zc1, zs1, yc, ys, zc2, zs2, y, yr);
}
inline void sh4_rot(REAL m[3 * 3], REAL y[NSH4], REAL yr[NSH4])
{
REAL zc1, zs1, yc, ys, zc2, zs2;
zyz(m, zc1, zs1, yc, ys, zc2, zs2);
sh4_rot(m, zc1, zs1, yc, ys, zc2, zs2, y, yr);
}
inline void sh5_rot(REAL m[3 * 3], REAL y[NSH5], REAL yr[NSH5])
{
REAL zc1, zs1, yc, ys, zc2, zs2;
zyz(m, zc1, zs1, yc, ys, zc2, zs2);
sh5_rot(m, zc1, zs1, yc, ys, zc2, zs2, y, yr);
}
// simple matrix vector multiply for a square matrix (only used by ZRotation)
inline void SimpMatMul(size_t dim, const float *matrix, const float *input, float *result)
{
for (size_t iR = 0; iR < dim; ++iR)
{
result[iR + 0] = matrix[iR*dim + 0] * input[0];
for (size_t iC = 1; iC < dim; ++iC)
{
result[iR] += matrix[iR*dim + iC] * input[iC];
}
}
}
}; // anonymous namespace
//-------------------------------------------------------------------------------------
// Evaluates the Spherical Harmonic basis functions
//
// http://msdn.microsoft.com/en-us/library/windows/desktop/bb205448.aspx
//-------------------------------------------------------------------------------------
_Use_decl_annotations_
float* XM_CALLCONV DirectX::XMSHEvalDirection(
float *result,
size_t order,
FXMVECTOR dir) noexcept
{
if (!result)
return nullptr;
XMFLOAT4A dv;
XMStoreFloat4A(&dv, dir);
const float fX = dv.x;
const float fY = dv.y;
const float fZ = dv.z;
switch (order)