-
Notifications
You must be signed in to change notification settings - Fork 70
Expand file tree
/
Copy pathcommon.hlsl
More file actions
1271 lines (1144 loc) · 57.2 KB
/
common.hlsl
File metadata and controls
1271 lines (1144 loc) · 57.2 KB
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
// Copyright (C) 2018-2023 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine".
// For conditions of distribution and use, see copyright notice in nabla.h
#ifndef _NBL_BUILTIN_HLSL_BXDF_COMMON_INCLUDED_
#define _NBL_BUILTIN_HLSL_BXDF_COMMON_INCLUDED_
#include "nbl/builtin/hlsl/limits.hlsl"
#include "nbl/builtin/hlsl/numbers.hlsl"
#include "nbl/builtin/hlsl/type_traits.hlsl"
#include "nbl/builtin/hlsl/concepts/core.hlsl"
#include "nbl/builtin/hlsl/ieee754.hlsl"
#include "nbl/builtin/hlsl/tgmath.hlsl"
#include "nbl/builtin/hlsl/math/functions.hlsl"
// #include "nbl/builtin/hlsl/glsl_compat/core.hlsl"
#include "nbl/builtin/hlsl/cpp_compat/promote.hlsl"
#include "nbl/builtin/hlsl/bxdf/fresnel.hlsl"
#include "nbl/builtin/hlsl/sampling/quotient_and_pdf.hlsl"
#include "nbl/builtin/hlsl/vector_utils/vector_traits.hlsl"
namespace nbl
{
namespace hlsl
{
namespace bxdf
{
namespace ray_dir_info
{
#define NBL_CONCEPT_NAME Basic
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (rdirinfo, T)
#define NBL_CONCEPT_PARAM_1 (v, typename T::vector3_type)
#define NBL_CONCEPT_PARAM_2 (rcpEta, typename T::scalar_type)
#define NBL_CONCEPT_PARAM_3 (m, typename T::matrix3x3_type)
#define NBL_CONCEPT_PARAM_4 (rfl, Reflect<typename T::scalar_type>)
#define NBL_CONCEPT_PARAM_5 (rfr, Refract<typename T::scalar_type>)
#define NBL_CONCEPT_PARAM_6 (t, bool)
#define NBL_CONCEPT_PARAM_7 (rr, ReflectRefract<typename T::scalar_type>)
NBL_CONCEPT_BEGIN(8)
#define rdirinfo NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define v NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define rcpEta NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
#define m NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
#define rfl NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_4
#define rfr NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_5
#define t NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_6
#define rr NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_7
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(T::scalar_type))
((NBL_CONCEPT_REQ_TYPE)(T::vector3_type))
((NBL_CONCEPT_REQ_TYPE)(T::matrix3x3_type))
((NBL_CONCEPT_REQ_EXPR)(rdirinfo.setDirection(v)))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((rdirinfo.getDirection()), ::nbl::hlsl::is_same_v, typename T::vector3_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((rdirinfo.transmit()), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((rdirinfo.reflect(rfl)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((rdirinfo.refract(rfr, rcpEta)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((rdirinfo.reflectTransmit(rfl, t)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((rdirinfo.reflectRefract(rr, t, rcpEta)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((rdirinfo.transform(m)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((rdirinfo.isValid()), ::nbl::hlsl::is_same_v, bool))
((NBL_CONCEPT_REQ_EXPR)(rdirinfo.makeInvalid()))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(is_scalar_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(is_vector_v, typename T::vector3_type))
);
#undef rr
#undef t
#undef rfr
#undef rfl
#undef m
#undef rcpEta
#undef v
#undef rdirinfo
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
template <typename T>
struct SBasic
{
using scalar_type = T;
using vector3_type = vector<T, 3>;
using matrix3x3_type = matrix<T, 3, 3>;
void setDirection(const vector3_type v) { direction = v; }
vector3_type getDirection() NBL_CONST_MEMBER_FUNC { return direction; }
SBasic<T> transmit() NBL_CONST_MEMBER_FUNC
{
SBasic<T> retval;
retval.direction = -direction;
return retval;
}
template<typename R=Reflect<scalar_type> >
SBasic<T> reflect(NBL_CONST_REF_ARG(R) r) NBL_CONST_MEMBER_FUNC
{
SBasic<T> retval;
retval.direction = r();
return retval;
}
template<typename R=Refract<scalar_type> >
SBasic<T> refract(NBL_CONST_REF_ARG(R) r, scalar_type rcpOrientedEta) NBL_CONST_MEMBER_FUNC
{
SBasic<T> retval;
retval.direction = r(rcpOrientedEta);
return retval;
}
template<typename R=Reflect<scalar_type> >
SBasic<T> reflectTransmit(NBL_CONST_REF_ARG(R) r, bool transmitted) NBL_CONST_MEMBER_FUNC
{
SBasic<T> retval;
retval.direction = hlsl::mix(r(), -direction, transmitted);
return retval;
}
template<typename R=ReflectRefract<scalar_type> >
SBasic<T> reflectRefract(NBL_CONST_REF_ARG(R) rr, bool transmitted, scalar_type rcpOrientedEta) NBL_CONST_MEMBER_FUNC
{
SBasic<T> retval;
retval.direction = rr(transmitted, rcpOrientedEta);
return retval;
}
// WARNING: matrix must be orthonormal
SBasic<T> transform(const matrix3x3_type m) NBL_CONST_MEMBER_FUNC
{
matrix3x3_type m_T = nbl::hlsl::transpose<matrix3x3_type>(m);
assert(nbl::hlsl::abs<scalar_type>(nbl::hlsl::dot<vector3_type>(m_T[0], m_T[1])) < 1e-5);
assert(nbl::hlsl::abs<scalar_type>(nbl::hlsl::dot<vector3_type>(m_T[0], m_T[2])) < 1e-5);
assert(nbl::hlsl::abs<scalar_type>(nbl::hlsl::dot<vector3_type>(m_T[1], m_T[2])) < 1e-5);
SBasic<T> retval;
retval.direction = nbl::hlsl::mul<matrix3x3_type,vector3_type>(m, direction);
return retval;
}
void makeInvalid()
{
direction = vector3_type(0,0,0);
}
bool isValid() NBL_CONST_MEMBER_FUNC { return hlsl::any<vector<bool, 3> >(hlsl::glsl::notEqual(direction, hlsl::promote<vector3_type>(0.0))); }
vector3_type direction;
};
// more to come!
}
enum BxDFClampMode : uint16_t
{
BCM_NONE = 0,
BCM_MAX,
BCM_ABS
};
enum PathOrigin : uint16_t
{
PO_SENSOR = 0,
PO_LIGHT
};
template<typename T NBL_FUNC_REQUIRES(concepts::FloatingPointScalar<T>)
T conditionalAbsOrMax(T x, BxDFClampMode _clamp)
{
return hlsl::mix(math::conditionalAbsOrMax<T>(_clamp == BxDFClampMode::BCM_ABS, x, 0.0), x, _clamp == BxDFClampMode::BCM_NONE);
}
namespace surface_interactions
{
#define NBL_CONCEPT_NAME Isotropic
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (iso, T)
#define NBL_CONCEPT_PARAM_1 (normV, typename T::ray_dir_info_type)
#define NBL_CONCEPT_PARAM_2 (normN, typename T::vector3_type)
#define NBL_CONCEPT_PARAM_3 (clampMode, BxDFClampMode)
NBL_CONCEPT_BEGIN(4)
#define iso NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define normV NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define normN NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
#define clampMode NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(T::ray_dir_info_type))
((NBL_CONCEPT_REQ_TYPE)(T::scalar_type))
((NBL_CONCEPT_REQ_TYPE)(T::vector3_type))
((NBL_CONCEPT_REQ_TYPE)(T::spectral_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getV()), ::nbl::hlsl::is_same_v, typename T::ray_dir_info_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getN()), ::nbl::hlsl::is_same_v, typename T::vector3_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getNdotV(clampMode)), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getNdotV2()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getPathOrigin()), ::nbl::hlsl::is_same_v, PathOrigin))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((iso.getLuminosityContributionHint()), ::nbl::hlsl::is_same_v, typename T::spectral_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(normV,normN)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(ray_dir_info::Basic, typename T::ray_dir_info_type))
);
#undef clampMode
#undef normN
#undef normV
#undef iso
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
template<class RayDirInfo, class Spectrum NBL_PRIMARY_REQUIRES(ray_dir_info::Basic<RayDirInfo> && concepts::FloatingPointLikeVectorial<Spectrum>)
struct SIsotropic
{
using this_t = SIsotropic<RayDirInfo, Spectrum>;
using ray_dir_info_type = RayDirInfo;
using scalar_type = typename RayDirInfo::scalar_type;
using vector3_type = typename RayDirInfo::vector3_type;
using spectral_type = vector3_type;
// WARNING: Changed since GLSL, now arguments need to be normalized!
static this_t create(NBL_CONST_REF_ARG(RayDirInfo) normalizedV, const vector3_type normalizedN)
{
this_t retval;
retval.V = normalizedV;
retval.N = normalizedN;
retval.NdotV = nbl::hlsl::dot<vector3_type>(retval.N, retval.V.getDirection());
retval.NdotV2 = retval.NdotV * retval.NdotV;
retval.luminosityContributionHint = hlsl::promote<spectral_type>(1.0);
return retval;
}
RayDirInfo getV() NBL_CONST_MEMBER_FUNC { return V; }
vector3_type getN() NBL_CONST_MEMBER_FUNC { return N; }
scalar_type getNdotV(BxDFClampMode _clamp = BxDFClampMode::BCM_NONE) NBL_CONST_MEMBER_FUNC
{
return bxdf::conditionalAbsOrMax<scalar_type>(NdotV, _clamp);
}
scalar_type getNdotV2() NBL_CONST_MEMBER_FUNC { return NdotV2; }
PathOrigin getPathOrigin() NBL_CONST_MEMBER_FUNC { return PathOrigin::PO_SENSOR; }
spectral_type getLuminosityContributionHint() NBL_CONST_MEMBER_FUNC { return luminosityContributionHint; }
RayDirInfo V;
vector3_type N;
scalar_type NdotV;
scalar_type NdotV2;
spectral_type luminosityContributionHint;
};
#define NBL_CONCEPT_NAME Anisotropic
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (aniso, T)
#define NBL_CONCEPT_PARAM_1 (iso, typename T::isotropic_interaction_type)
#define NBL_CONCEPT_PARAM_2 (normT, typename T::vector3_type)
NBL_CONCEPT_BEGIN(3)
#define aniso NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define iso NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define normT NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(Isotropic, T))
((NBL_CONCEPT_REQ_TYPE)(T::isotropic_interaction_type))
((NBL_CONCEPT_REQ_TYPE)(T::matrix3x3_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((aniso.getT()), ::nbl::hlsl::is_same_v, typename T::vector3_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((aniso.getB()), ::nbl::hlsl::is_same_v, typename T::vector3_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((aniso.getTdotV()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((aniso.getTdotV2()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((aniso.getBdotV()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((aniso.getBdotV2()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(iso,normT,normT)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((aniso.getTangentSpaceV()), ::nbl::hlsl::is_same_v, typename T::vector3_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((aniso.getToTangentSpace()), ::nbl::hlsl::is_same_v, typename T::matrix3x3_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((aniso.getFromTangentSpace()), ::nbl::hlsl::is_same_v, typename T::matrix3x3_type))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(Isotropic, typename T::isotropic_interaction_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((aniso.isotropic), ::nbl::hlsl::is_same_v, typename T::isotropic_interaction_type))
);
#undef normT
#undef iso
#undef aniso
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
template<class IsotropicInteraction NBL_PRIMARY_REQUIRES(Isotropic<IsotropicInteraction>)
struct SAnisotropic
{
using this_t = SAnisotropic<IsotropicInteraction>;
using isotropic_interaction_type = IsotropicInteraction;
using ray_dir_info_type = typename isotropic_interaction_type::ray_dir_info_type;
using scalar_type = typename ray_dir_info_type::scalar_type;
using vector3_type = typename ray_dir_info_type::vector3_type;
using matrix3x3_type = matrix<scalar_type, 3, 3>;
using spectral_type = typename isotropic_interaction_type::spectral_type;
// WARNING: Changed since GLSL, now arguments need to be normalized!
static this_t create(
NBL_CONST_REF_ARG(isotropic_interaction_type) isotropic,
const vector3_type normalizedT,
const vector3_type normalizedB
)
{
this_t retval;
retval.isotropic = isotropic;
retval.T = normalizedT;
retval.B = normalizedB;
retval.TdotV = nbl::hlsl::dot<vector3_type>(retval.isotropic.getV().getDirection(), retval.T);
retval.BdotV = nbl::hlsl::dot<vector3_type>(retval.isotropic.getV().getDirection(), retval.B);
return retval;
}
static this_t create(NBL_CONST_REF_ARG(isotropic_interaction_type) isotropic, const vector3_type normalizedT)
{
return create(isotropic, normalizedT, cross(isotropic.getN(), normalizedT));
}
static this_t create(NBL_CONST_REF_ARG(isotropic_interaction_type) isotropic)
{
vector3_type T, B;
math::frisvad<vector3_type>(isotropic.getN(), T, B);
return create(isotropic, nbl::hlsl::normalize<vector3_type>(T), nbl::hlsl::normalize<vector3_type>(B));
}
static this_t create(NBL_CONST_REF_ARG(ray_dir_info_type) normalizedV, const vector3_type normalizedN)
{
isotropic_interaction_type isotropic = isotropic_interaction_type::create(normalizedV, normalizedN);
return create(isotropic);
}
ray_dir_info_type getV() NBL_CONST_MEMBER_FUNC { return isotropic.getV(); }
vector3_type getN() NBL_CONST_MEMBER_FUNC { return isotropic.getN(); }
scalar_type getNdotV(BxDFClampMode _clamp = BxDFClampMode::BCM_NONE) NBL_CONST_MEMBER_FUNC { return isotropic.getNdotV(_clamp); }
scalar_type getNdotV2() NBL_CONST_MEMBER_FUNC { return isotropic.getNdotV2(); }
PathOrigin getPathOrigin() NBL_CONST_MEMBER_FUNC { return isotropic.getPathOrigin(); }
spectral_type getLuminosityContributionHint() NBL_CONST_MEMBER_FUNC { return isotropic.getLuminosityContributionHint(); }
vector3_type getT() NBL_CONST_MEMBER_FUNC { return T; }
vector3_type getB() NBL_CONST_MEMBER_FUNC { return B; }
scalar_type getTdotV() NBL_CONST_MEMBER_FUNC { return TdotV; }
scalar_type getTdotV2() NBL_CONST_MEMBER_FUNC { const scalar_type t = getTdotV(); return t*t; }
scalar_type getBdotV() NBL_CONST_MEMBER_FUNC { return BdotV; }
scalar_type getBdotV2() NBL_CONST_MEMBER_FUNC { const scalar_type t = getBdotV(); return t*t; }
vector3_type getTangentSpaceV() NBL_CONST_MEMBER_FUNC { return vector3_type(TdotV, BdotV, isotropic.getNdotV()); }
matrix3x3_type getToTangentSpace() NBL_CONST_MEMBER_FUNC { return matrix3x3_type(T, B, isotropic.getN()); }
matrix3x3_type getFromTangentSpace() NBL_CONST_MEMBER_FUNC { return nbl::hlsl::transpose<matrix3x3_type>(matrix3x3_type(T, B, isotropic.getN())); }
isotropic_interaction_type isotropic;
vector3_type T;
vector3_type B;
scalar_type TdotV;
scalar_type BdotV;
};
}
#define NBL_CONCEPT_NAME LightSample
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (_sample, T)
#define NBL_CONCEPT_PARAM_1 (inter, surface_interactions::SIsotropic<typename T::ray_dir_info_type, typename T::vector3_type>)
#define NBL_CONCEPT_PARAM_2 (rdirinfo, typename T::ray_dir_info_type)
#define NBL_CONCEPT_PARAM_3 (pV, typename T::vector3_type)
#define NBL_CONCEPT_PARAM_4 (frame, typename T::matrix3x3_type)
#define NBL_CONCEPT_PARAM_5 (clampMode, BxDFClampMode)
#define NBL_CONCEPT_PARAM_6 (pNdotL, typename T::scalar_type)
NBL_CONCEPT_BEGIN(7)
#define _sample NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define inter NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define rdirinfo NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
#define pV NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
#define frame NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_4
#define clampMode NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_5
#define pNdotL NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_6
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(T::ray_dir_info_type))
((NBL_CONCEPT_REQ_TYPE)(T::scalar_type))
((NBL_CONCEPT_REQ_TYPE)(T::vector3_type))
((NBL_CONCEPT_REQ_TYPE)(T::matrix3x3_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((_sample.getL()), ::nbl::hlsl::is_same_v, typename T::ray_dir_info_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((_sample.getTdotL()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((_sample.getTdotL2()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((_sample.getBdotL()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((_sample.getBdotL2()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((_sample.getNdotL(clampMode)), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((_sample.getNdotL2()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((_sample.isValid()), ::nbl::hlsl::is_same_v, bool))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createFromTangentSpace(rdirinfo,frame)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(rdirinfo,pV)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(rdirinfo,pV,pV,pV)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(rdirinfo,pV,pV,pNdotL)), ::nbl::hlsl::is_same_v, T))
// ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template create<surface_interactions::SIsotropic<typename T::ray_dir_info_type, typename T::vector3_type> >(pV,inter)), ::nbl::hlsl::is_same_v, T)) // NOTE: temporarily commented out due to dxc bug https://github.com/microsoft/DirectXShaderCompiler/issues/7154
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((_sample.getTangentSpaceL()), ::nbl::hlsl::is_same_v, typename T::vector3_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createInvalid()), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(ray_dir_info::Basic, typename T::ray_dir_info_type))
);
#undef pNdotL
#undef clampMode
#undef frame
#undef pV
#undef rdirinfo
#undef inter
#undef _sample
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
template<class RayDirInfo NBL_PRIMARY_REQUIRES(ray_dir_info::Basic<RayDirInfo>)
struct SLightSample
{
using this_t = SLightSample<RayDirInfo>;
using ray_dir_info_type = RayDirInfo;
using scalar_type = typename ray_dir_info_type::scalar_type;
using vector3_type = typename ray_dir_info_type::vector3_type;
using matrix3x3_type = matrix<scalar_type, 3, 3>;
static this_t createFromTangentSpace(
NBL_CONST_REF_ARG(ray_dir_info_type) tangentSpaceL,
const matrix3x3_type tangentFrame
)
{
this_t retval;
const vector3_type tsL = tangentSpaceL.getDirection();
retval.L = tangentSpaceL.transform(tangentFrame);
retval.TdotL = tsL.x;
retval.BdotL = tsL.y;
retval.NdotL = tsL.z;
retval.NdotL2 = retval.NdotL*retval.NdotL;
return retval;
}
static this_t create(NBL_CONST_REF_ARG(ray_dir_info_type) L, const vector3_type N)
{
this_t retval;
retval.L = L;
retval.TdotL = bit_cast<scalar_type>(numeric_limits<scalar_type>::quiet_NaN);
retval.BdotL = bit_cast<scalar_type>(numeric_limits<scalar_type>::quiet_NaN);
retval.NdotL = nbl::hlsl::dot<vector3_type>(N,L.getDirection());
retval.NdotL2 = retval.NdotL * retval.NdotL;
return retval;
}
static this_t create(NBL_CONST_REF_ARG(ray_dir_info_type) L, const vector3_type T, const vector3_type B, const vector3_type N)
{
this_t retval = create(L,N);
retval.TdotL = nbl::hlsl::dot<vector3_type>(T,L.getDirection());
retval.BdotL = nbl::hlsl::dot<vector3_type>(B,L.getDirection());
return retval;
}
static this_t create(NBL_CONST_REF_ARG(ray_dir_info_type) L, const vector3_type T, const vector3_type B, const scalar_type NdotL)
{
this_t retval;
retval.L = L;
retval.TdotL = nbl::hlsl::dot<vector3_type>(T,L.getDirection());
retval.BdotL = nbl::hlsl::dot<vector3_type>(B,L.getDirection());
retval.NdotL = NdotL;
retval.NdotL2 = NdotL * NdotL;
return retval;
}
template<class SurfaceInteraction NBL_FUNC_REQUIRES(surface_interactions::Isotropic<SurfaceInteraction>)
static this_t create(const vector3_type L, NBL_CONST_REF_ARG(SurfaceInteraction) interaction)
{
const vector3_type V = interaction.V.getDirection();
const scalar_type VdotL = nbl::hlsl::dot<vector3_type>(V,L);
this_t retval;
NBL_IF_CONSTEXPR(surface_interactions::Anisotropic<SurfaceInteraction>)
retval = create(L,interaction.T,interaction.B,interaction.N);
else
retval = create(L,interaction.N);
return retval;
}
vector3_type getTangentSpaceL() NBL_CONST_MEMBER_FUNC
{
return vector3_type(TdotL, BdotL, NdotL);
}
ray_dir_info_type getL() NBL_CONST_MEMBER_FUNC { return L; }
scalar_type getTdotL() NBL_CONST_MEMBER_FUNC { return TdotL; }
scalar_type getTdotL2() NBL_CONST_MEMBER_FUNC { const scalar_type t = getTdotL(); return t*t; }
scalar_type getBdotL() NBL_CONST_MEMBER_FUNC { return BdotL; }
scalar_type getBdotL2() NBL_CONST_MEMBER_FUNC { const scalar_type t = getBdotL(); return t*t; }
scalar_type getNdotL(BxDFClampMode _clamp = BxDFClampMode::BCM_NONE) NBL_CONST_MEMBER_FUNC
{
return bxdf::conditionalAbsOrMax<scalar_type>(NdotL, _clamp);
}
scalar_type getNdotL2() NBL_CONST_MEMBER_FUNC { return NdotL2; }
static this_t createInvalid()
{
this_t retval;
retval.L.makeInvalid();
return retval;
}
bool isValid() NBL_CONST_MEMBER_FUNC { return L.isValid(); }
RayDirInfo L;
scalar_type TdotL;
scalar_type BdotL;
scalar_type NdotL;
scalar_type NdotL2;
};
#define NBL_CONCEPT_NAME ReadableIsotropicMicrofacetCache
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (cache, T)
#define NBL_CONCEPT_PARAM_1 (eta, fresnel::OrientedEtas<vector<typename T::scalar_type,1> >)
NBL_CONCEPT_BEGIN(2)
#define cache NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define eta NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(T::scalar_type))
((NBL_CONCEPT_REQ_TYPE)(T::vector3_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.getVdotL()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.getVdotH()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.getLdotH()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.getVdotHLdotH()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.getAbsNdotH()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.getNdotH2()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.isTransmission()), ::nbl::hlsl::is_same_v, bool))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.isValid(eta)), ::nbl::hlsl::is_same_v, bool))
);
#undef eta
#undef cache
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
#define NBL_CONCEPT_NAME CreatableIsotropicMicrofacetCache
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (cache, T)
#define NBL_CONCEPT_PARAM_1 (iso, surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type >)
#define NBL_CONCEPT_PARAM_2 (pNdotV, typename T::scalar_type)
#define NBL_CONCEPT_PARAM_3 (_sample, SLightSample<ray_dir_info::SBasic<typename T::scalar_type> >)
#define NBL_CONCEPT_PARAM_4 (V, typename T::vector3_type)
#define NBL_CONCEPT_PARAM_5 (eta, fresnel::OrientedEtas<vector<typename T::scalar_type,1> >)
NBL_CONCEPT_BEGIN(6)
#define cache NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define iso NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define pNdotV NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
#define _sample NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
#define V NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_4
#define eta NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_5
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createForReflection(pNdotV,pNdotV,pNdotV,pNdotV)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createForReflection(pNdotV,pNdotV,pNdotV)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template createForReflection<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(iso,_sample)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(V,V,V,eta,V)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template create<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(iso,_sample,eta,V)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(ReadableIsotropicMicrofacetCache, T))
);
#undef eta
#undef V
#undef _sample
#undef pNdotV
#undef iso
#undef cache
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
template <typename T NBL_PRIMARY_REQUIRES(concepts::FloatingPointScalar<T>)
struct SIsotropicMicrofacetCache
{
using this_t = SIsotropicMicrofacetCache<T>;
using scalar_type = T;
using vector3_type = vector<scalar_type, 3>;
using matrix3x3_type = matrix<scalar_type, 3, 3>;
using monochrome_type = vector<scalar_type, 1>;
// always valid because its specialized for the reflective case
static this_t createForReflection(const scalar_type NdotV, const scalar_type NdotL, const scalar_type VdotL, NBL_REF_ARG(scalar_type) LplusV_rcpLen)
{
scalar_type unoriented_LplusV_rcpLen = rsqrt<scalar_type>(2.0 + 2.0 * VdotL);
this_t retval;
retval.VdotL = VdotL;
scalar_type NdotLplusVdotL = NdotL + NdotV;
scalar_type oriented_LplusV_rcpLen = ieee754::flipSign<scalar_type>(unoriented_LplusV_rcpLen, NdotLplusVdotL < scalar_type(0.0));
retval.VdotH = oriented_LplusV_rcpLen * VdotL + oriented_LplusV_rcpLen;
retval.LdotH = retval.VdotH;
retval.absNdotH = NdotLplusVdotL * oriented_LplusV_rcpLen;
retval.NdotH2 = retval.absNdotH * retval.absNdotH;
LplusV_rcpLen = unoriented_LplusV_rcpLen;
return retval;
}
static this_t createForReflection(const scalar_type NdotV, const scalar_type NdotL, const scalar_type VdotL)
{
float dummy;
return createForReflection(NdotV, NdotL, VdotL, dummy);
}
template<class IsotropicInteraction, class LS NBL_FUNC_REQUIRES(surface_interactions::Isotropic<IsotropicInteraction> && LightSample<LS>)
static this_t createForReflection(
NBL_CONST_REF_ARG(IsotropicInteraction) interaction,
NBL_CONST_REF_ARG(LS) _sample)
{
return createForReflection(interaction.getNdotV(), _sample.getNdotL(), hlsl::dot<vector3_type>(interaction.getV().getDirection(), _sample.getL().getDirection()));
}
// transmissive cases need to be checked if the path is valid before usage
static this_t create(const bool transmitted, NBL_CONST_REF_ARG(ComputeMicrofacetNormal<scalar_type>) computeMicrofacetNormal, const scalar_type VdotL,
const vector3_type N, NBL_REF_ARG(vector3_type) H)
{
this_t retval;
retval.VdotL = VdotL;
H = computeMicrofacetNormal.normalized(transmitted);
scalar_type NdotH = hlsl::dot<vector3_type>(N, H);
H = ieee754::flipSign<vector3_type>(H, NdotH < scalar_type(0.0));
retval.absNdotH = hlsl::abs(NdotH);
// not coming from the medium (reflected) OR
// exiting at the macro scale AND ( (not L outside the cone of possible directions given IoR with constraint VdotH*LdotH<0.0) OR (microfacet not facing toward the macrosurface, i.e. non heightfield profile of microsurface) )
const bool valid = ComputeMicrofacetNormal<scalar_type>::isValidMicrofacet(transmitted, VdotL, retval.absNdotH, fresnel::OrientedEtas<monochrome_type>::create(1.0, computeMicrofacetNormal.orientedEta));
if (valid)
{
retval.VdotH = hlsl::dot<vector3_type>(computeMicrofacetNormal.V,H);
retval.LdotH = hlsl::dot<vector3_type>(computeMicrofacetNormal.L,H);
retval.NdotH2 = retval.absNdotH * retval.absNdotH;
}
else
retval.absNdotH = bit_cast<scalar_type>(numeric_limits<scalar_type>::quiet_NaN);
return retval;
}
static this_t create(
const vector3_type V, const vector3_type L, const vector3_type N,
NBL_CONST_REF_ARG(fresnel::OrientedEtas<monochrome_type>) orientedEtas, NBL_REF_ARG(vector3_type) H)
{
this_t retval;
const scalar_type NdotV = hlsl::dot<vector3_type>(N, V);
const scalar_type NdotL = hlsl::dot<vector3_type>(N, L);
const scalar_type VdotL = hlsl::dot<vector3_type>(V, L);
const bool transmitted = ComputeMicrofacetNormal<scalar_type>::isTransmissionPath(NdotV,NdotL);
ComputeMicrofacetNormal<scalar_type> computeMicrofacetNormal = ComputeMicrofacetNormal<scalar_type>::create(V,L,N,1.0);
computeMicrofacetNormal.orientedEta = orientedEtas.value[0];
return create(transmitted, computeMicrofacetNormal, VdotL, N, H);
}
static this_t create(
const vector3_type V, const vector3_type L, const vector3_type N,
NBL_CONST_REF_ARG(fresnel::OrientedEtas<monochrome_type>) orientedEtas)
{
vector3_type dummy;
return create(V, L, N, orientedEtas, dummy);
}
template<class IsotropicInteraction, class LS NBL_FUNC_REQUIRES(surface_interactions::Isotropic<IsotropicInteraction> && LightSample<LS>)
static this_t create(
NBL_CONST_REF_ARG(IsotropicInteraction) interaction,
NBL_CONST_REF_ARG(LS) _sample,
NBL_CONST_REF_ARG(fresnel::OrientedEtas<monochrome_type>) orientedEtas, NBL_REF_ARG(vector3_type) H)
{
const vector3_type V = interaction.getV().getDirection();
const vector3_type L = _sample.getL().getDirection();
const vector3_type N = interaction.getN();
const bool transmitted = ComputeMicrofacetNormal<scalar_type>::isTransmissionPath(interaction.getNdotV(),_sample.getNdotL());
ComputeMicrofacetNormal<scalar_type> computeMicrofacetNormal = ComputeMicrofacetNormal<scalar_type>::create(V,L,N,1.0);
computeMicrofacetNormal.orientedEta = orientedEtas.value[0];
return create(transmitted, computeMicrofacetNormal, hlsl::dot<vector3_type>(V, L), N, H);
}
template<class IsotropicInteraction, class LS NBL_FUNC_REQUIRES(surface_interactions::Isotropic<IsotropicInteraction> && LightSample<LS>)
static this_t create(
NBL_CONST_REF_ARG(IsotropicInteraction) interaction,
NBL_CONST_REF_ARG(LS) _sample,
NBL_CONST_REF_ARG(fresnel::OrientedEtas<monochrome_type>) orientedEtas)
{
vector3_type dummy;
return create(interaction,_sample,orientedEtas,dummy);
}
// note on usage: assert sign(VdotH)==sign(NdotV) and similar for L
// problem is that BRDF GGX and friends can generate unmasked H, which is actually backfacing towards L (non VNDF variants can even generate VdotH<0)
// similar with BSDF sampling, as fresnel can be high while reflection can be invalid, or low while refraction would be invalid too
bool isTransmission() NBL_CONST_MEMBER_FUNC { return getVdotHLdotH() < scalar_type(0.0); }
bool isValid(NBL_CONST_REF_ARG(fresnel::OrientedEtas<monochrome_type>) orientedEtas) NBL_CONST_MEMBER_FUNC
{
return ComputeMicrofacetNormal<scalar_type>::isValidMicrofacet(isTransmission(), VdotL, absNdotH, orientedEtas);
}
scalar_type getVdotL() NBL_CONST_MEMBER_FUNC { return VdotL; }
scalar_type getVdotH() NBL_CONST_MEMBER_FUNC { return VdotH; }
scalar_type getLdotH() NBL_CONST_MEMBER_FUNC { return LdotH; }
scalar_type getVdotHLdotH() NBL_CONST_MEMBER_FUNC { return getVdotH() * getLdotH(); }
scalar_type getAbsNdotH() NBL_CONST_MEMBER_FUNC { return absNdotH; }
scalar_type getNdotH2() NBL_CONST_MEMBER_FUNC { return NdotH2; }
scalar_type VdotL;
scalar_type VdotH;
scalar_type LdotH;
scalar_type absNdotH;
scalar_type NdotH2;
};
#define NBL_CONCEPT_NAME AnisotropicMicrofacetCache
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (cache, T)
#define NBL_CONCEPT_PARAM_1 (aniso, surface_interactions::SAnisotropic<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type > >)
#define NBL_CONCEPT_PARAM_2 (pNdotL, typename T::scalar_type)
#define NBL_CONCEPT_PARAM_3 (_sample, SLightSample<ray_dir_info::SBasic<typename T::scalar_type> >)
#define NBL_CONCEPT_PARAM_4 (V, typename T::vector3_type)
#define NBL_CONCEPT_PARAM_5 (b0, bool)
#define NBL_CONCEPT_PARAM_6 (eta, fresnel::OrientedEtas<vector<typename T::scalar_type, 1> >)
#define NBL_CONCEPT_PARAM_7 (rcp_eta, fresnel::OrientedEtaRcps<vector<typename T::scalar_type, 1> >)
NBL_CONCEPT_BEGIN(8)
#define cache NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define aniso NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define pNdotL NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
#define _sample NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_3
#define V NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_4
#define b0 NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_5
#define eta NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_6
#define rcp_eta NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_7
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(ReadableIsotropicMicrofacetCache, T))
((NBL_CONCEPT_REQ_TYPE)(T::isocache_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.getTdotH()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.getTdotH2()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.getBdotH()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((cache.getBdotH2()), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createForReflection(V,V)), ::nbl::hlsl::is_same_v, T))
// ((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(V,V,b0,rcp_eta)), ::nbl::hlsl::is_same_v, T)) // TODO: refuses to compile when arg4 is rcp_eta for some reason, eta is fine
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createForReflection(V,V,pNdotL)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template createForReflection<surface_interactions::SAnisotropic<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type > >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(aniso,_sample)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::create(V,V,V,V,V,eta,V)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::template create<surface_interactions::SAnisotropic<surface_interactions::SIsotropic<ray_dir_info::SBasic<typename T::scalar_type>, typename T::vector3_type > >,SLightSample<ray_dir_info::SBasic<typename T::scalar_type> > >(aniso,_sample,eta)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((T::createPartial(pNdotL,pNdotL,pNdotL,b0,rcp_eta)), ::nbl::hlsl::is_same_v, T))
((NBL_CONCEPT_REQ_EXPR)(cache.fillTangents(V,V,V)))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(CreatableIsotropicMicrofacetCache, typename T::isocache_type))
);
#undef rcp_eta
#undef eta
#undef b0
#undef V
#undef _sample
#undef pNdotL
#undef aniso
#undef cache
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
template<class IsoCache NBL_PRIMARY_REQUIRES(CreatableIsotropicMicrofacetCache<IsoCache>)
struct SAnisotropicMicrofacetCache
{
using this_t = SAnisotropicMicrofacetCache<IsoCache>;
using isocache_type = IsoCache;
using scalar_type = typename IsoCache::scalar_type;
using vector3_type = vector<scalar_type, 3>;
using matrix3x3_type = matrix<scalar_type, 3, 3>;
using monochrome_type = vector<scalar_type, 1>;
// always valid by construction
static this_t createForReflection(const vector3_type tangentSpaceV, const vector3_type tangentSpaceH)
{
this_t retval;
retval.iso_cache.VdotH = nbl::hlsl::dot<vector3_type>(tangentSpaceV,tangentSpaceH);
retval.iso_cache.VdotL = scalar_type(2.0) * retval.iso_cache.VdotH * retval.iso_cache.VdotH - scalar_type(1.0);
retval.iso_cache.LdotH = retval.iso_cache.getVdotH();
assert(tangentSpaceH.z >= scalar_type(0.0));
retval.iso_cache.absNdotH = tangentSpaceH.z;
retval.iso_cache.NdotH2 = retval.iso_cache.getAbsNdotH() * retval.iso_cache.getAbsNdotH();
retval.TdotH = tangentSpaceH.x;
retval.BdotH = tangentSpaceH.y;
return retval;
}
static this_t create(
const vector3_type tangentSpaceV,
const vector3_type tangentSpaceH,
const bool transmitted,
NBL_CONST_REF_ARG(fresnel::OrientedEtaRcps<monochrome_type>) rcpOrientedEta
)
{
this_t retval = createForReflection(tangentSpaceV,tangentSpaceH);
if (transmitted)
{
Refract<scalar_type> r = Refract<scalar_type>::create(tangentSpaceV, tangentSpaceH);
retval.iso_cache.LdotH = r.getNdotT(rcpOrientedEta.value2[0]);
retval.iso_cache.VdotL = retval.iso_cache.VdotH * (retval.iso_cache.LdotH - rcpOrientedEta.value[0] + retval.iso_cache.VdotH * rcpOrientedEta.value[0]);
}
return retval;
}
// always valid because its specialized for the reflective case
static this_t createForReflection(const vector3_type tangentSpaceV, const vector3_type tangentSpaceL, const scalar_type VdotL)
{
this_t retval;
scalar_type LplusV_rcpLen;
retval.iso_cache = isocache_type::createForReflection(tangentSpaceV.z, tangentSpaceL.z, VdotL, LplusV_rcpLen);
retval.TdotH = (tangentSpaceV.x + tangentSpaceL.x) * LplusV_rcpLen;
retval.BdotH = (tangentSpaceV.y + tangentSpaceL.y) * LplusV_rcpLen;
return retval;
}
template<class AnisotropicInteraction, class LS NBL_FUNC_REQUIRES(surface_interactions::Anisotropic<AnisotropicInteraction> && LightSample<LS>)
static this_t createForReflection(
NBL_CONST_REF_ARG(AnisotropicInteraction) interaction,
NBL_CONST_REF_ARG(LS) _sample)
{
return createForReflection(interaction.getTangentSpaceV(), _sample.getTangentSpaceL(), hlsl::dot<vector3_type>(interaction.getV().getDirection(), _sample.getL().getDirection()));
}
// transmissive cases need to be checked if the path is valid before usage
static this_t create(
const vector3_type V, const vector3_type L,
const vector3_type T, const vector3_type B, const vector3_type N,
NBL_CONST_REF_ARG(fresnel::OrientedEtas<monochrome_type>) orientedEtas, NBL_REF_ARG(vector3_type) H
)
{
this_t retval;
retval.iso_cache = isocache_type::create(V,L,N,orientedEtas,H);
retval.TdotH = nbl::hlsl::dot<vector3_type>(T,H);
retval.BdotH = nbl::hlsl::dot<vector3_type>(B,H);
return retval;
}
template<class AnisotropicInteraction, class LS NBL_FUNC_REQUIRES(surface_interactions::Anisotropic<AnisotropicInteraction> && LightSample<LS>)
static this_t create(
NBL_CONST_REF_ARG(AnisotropicInteraction) interaction,
NBL_CONST_REF_ARG(LS) _sample,
NBL_CONST_REF_ARG(fresnel::OrientedEtas<monochrome_type>) orientedEtas
)
{
this_t retval;
vector3_type H;
retval.iso_cache = isocache_type::template create<typename AnisotropicInteraction::isotropic_interaction_type, LS>(interaction.isotropic,_sample,orientedEtas,H);
retval.TdotH = nbl::hlsl::dot<vector3_type>(interaction.getT(),H);
retval.BdotH = nbl::hlsl::dot<vector3_type>(interaction.getB(),H);
return retval;
}
static this_t createPartial(
const scalar_type VdotH, const scalar_type LdotH, const scalar_type NdotH,
bool transmitted, NBL_CONST_REF_ARG(fresnel::OrientedEtaRcps<monochrome_type>) rcpOrientedEta
)
{
this_t retval;
retval.iso_cache.VdotH = VdotH;
retval.iso_cache.LdotH = LdotH;
retval.iso_cache.VdotL = hlsl::mix(scalar_type(2.0) * VdotH * VdotH - scalar_type(1.0),
VdotH * (VdotH * rcpOrientedEta.value[0] + LdotH) - rcpOrientedEta.value[0], transmitted);
assert(NdotH > scalar_type(0.0));
retval.iso_cache.absNdotH = hlsl::abs(NdotH);
retval.iso_cache.NdotH2 = NdotH * NdotH;
return retval;
}
void fillTangents(const vector3_type T, const vector3_type B, const vector3_type H)
{
TdotH = hlsl::dot(T, H);
BdotH = hlsl::dot(B, H);
}
scalar_type getVdotL() NBL_CONST_MEMBER_FUNC { return iso_cache.getVdotL(); }
scalar_type getVdotH() NBL_CONST_MEMBER_FUNC { return iso_cache.getVdotH(); }
scalar_type getLdotH() NBL_CONST_MEMBER_FUNC { return iso_cache.getLdotH(); }
scalar_type getVdotHLdotH() NBL_CONST_MEMBER_FUNC { return iso_cache.getVdotHLdotH(); }
scalar_type getAbsNdotH() NBL_CONST_MEMBER_FUNC { return iso_cache.getAbsNdotH(); }
scalar_type getNdotH2() NBL_CONST_MEMBER_FUNC { return iso_cache.getNdotH2(); }
bool isTransmission() NBL_CONST_MEMBER_FUNC { return iso_cache.isTransmission(); }
bool isValid(NBL_CONST_REF_ARG(fresnel::OrientedEtas<monochrome_type>) orientedEtas) NBL_CONST_MEMBER_FUNC
{
return iso_cache.isValid(orientedEtas);
}
scalar_type getTdotH() NBL_CONST_MEMBER_FUNC { return TdotH; }
scalar_type getTdotH2() NBL_CONST_MEMBER_FUNC { const scalar_type t = getTdotH(); return t*t; }
scalar_type getBdotH() NBL_CONST_MEMBER_FUNC { return BdotH; }
scalar_type getBdotH2() NBL_CONST_MEMBER_FUNC { const scalar_type t = getBdotH(); return t*t; }
isocache_type iso_cache;
scalar_type TdotH;
scalar_type BdotH;
};
namespace bxdf_concepts
{
namespace impl
{
#define NBL_CONCEPT_NAME bxdf_common_typdefs
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (bxdf, T)
NBL_CONCEPT_BEGIN(1)
#define bxdf NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE)(T::scalar_type))
((NBL_CONCEPT_REQ_TYPE)(T::anisotropic_interaction_type))
((NBL_CONCEPT_REQ_TYPE)(T::sample_type))
((NBL_CONCEPT_REQ_TYPE)(T::spectral_type))
((NBL_CONCEPT_REQ_TYPE)(T::quotient_pdf_type))
);
#undef bxdf
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
#define NBL_CONCEPT_NAME bxdf_common
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (bxdf, T)
#define NBL_CONCEPT_PARAM_1 (_sample, typename T::sample_type)
#define NBL_CONCEPT_PARAM_2 (aniso, typename T::anisotropic_interaction_type)
NBL_CONCEPT_BEGIN(3)
#define bxdf NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define _sample NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define aniso NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(bxdf_common_typdefs, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((bxdf.eval(_sample, aniso)), ::nbl::hlsl::is_same_v, typename T::spectral_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((bxdf.pdf(_sample, aniso)), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((bxdf.quotient_and_pdf(_sample, aniso)), ::nbl::hlsl::is_same_v, typename T::quotient_pdf_type))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(LightSample, typename T::sample_type))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(concepts::FloatingPointLikeVectorial, typename T::spectral_type))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(surface_interactions::Anisotropic, typename T::anisotropic_interaction_type))
);
#undef aniso
#undef _sample
#undef bxdf
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
#define NBL_CONCEPT_NAME iso_bxdf_common
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (bxdf, T)
#define NBL_CONCEPT_PARAM_1 (_sample, typename T::sample_type)
#define NBL_CONCEPT_PARAM_2 (iso, typename T::isotropic_interaction_type)
NBL_CONCEPT_BEGIN(3)
#define bxdf NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define _sample NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define iso NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(bxdf_common, T))
((NBL_CONCEPT_REQ_TYPE)(T::isotropic_interaction_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((bxdf.eval(_sample, iso)), ::nbl::hlsl::is_same_v, typename T::spectral_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((bxdf.pdf(_sample, iso)), ::nbl::hlsl::is_same_v, typename T::scalar_type))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((bxdf.quotient_and_pdf(_sample, iso)), ::nbl::hlsl::is_same_v, typename T::quotient_pdf_type))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(concepts::FloatingPointLikeVectorial, typename T::spectral_type))
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(surface_interactions::Isotropic, typename T::isotropic_interaction_type))
);
#undef iso
#undef _sample
#undef bxdf
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
}
#define NBL_CONCEPT_NAME BRDF
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (bxdf, T)
#define NBL_CONCEPT_PARAM_1 (aniso, typename T::anisotropic_interaction_type)
#define NBL_CONCEPT_PARAM_2 (u, vector<typename T::scalar_type, 2>)
NBL_CONCEPT_BEGIN(3)
#define bxdf NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define aniso NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define u NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(impl::bxdf_common, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((bxdf.generate(aniso,u)), ::nbl::hlsl::is_same_v, typename T::sample_type))
);
#undef u
#undef aniso
#undef bxdf
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
#define NBL_CONCEPT_NAME BSDF
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (bxdf, T)
#define NBL_CONCEPT_PARAM_1 (aniso, typename T::anisotropic_interaction_type)
#define NBL_CONCEPT_PARAM_2 (u, vector<typename T::scalar_type, 3>)
NBL_CONCEPT_BEGIN(3)
#define bxdf NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_0
#define aniso NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_1
#define u NBL_CONCEPT_PARAM_T NBL_CONCEPT_PARAM_2
NBL_CONCEPT_END(
((NBL_CONCEPT_REQ_TYPE_ALIAS_CONCEPT)(impl::bxdf_common, T))
((NBL_CONCEPT_REQ_EXPR_RET_TYPE)((bxdf.generate(aniso,u)), ::nbl::hlsl::is_same_v, typename T::sample_type))
);
#undef u
#undef aniso
#undef bxdf
#include <nbl/builtin/hlsl/concepts/__end.hlsl>
#define NBL_CONCEPT_NAME IsotropicBRDF
#define NBL_CONCEPT_TPLT_PRM_KINDS (typename)
#define NBL_CONCEPT_TPLT_PRM_NAMES (T)
#define NBL_CONCEPT_PARAM_0 (bxdf, T)
#define NBL_CONCEPT_PARAM_1 (iso, typename T::isotropic_interaction_type)