-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCompileTest.hlsl
107 lines (96 loc) · 3.39 KB
/
CompileTest.hlsl
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
//=================================================================================================
//
// SHforHLSL - Spherical harmonics suppport library for HLSL 2021, by MJP
// https://github.com/TheRealMJP/SHforHLSL
// https://therealmjp.github.io/
//
// All code licensed under the MIT license
//
//================================================================================================
#include "SH.hlsli"
template<typename T, int N> void TestOperatorOverloads()
{
{
SH::L1<T, N> sh = SH::L1<T, N>::Zero();
sh = sh + SH::L1<T, N>::Zero();
sh = sh - SH::L1<T, N>::Zero();
sh = sh * T(1.0);
sh = sh * (vector<T, N>)(1.0);
sh = sh / T(1.0);
sh = sh / (vector<T, N>)(1.0);
}
{
SH::L2<T, N> sh = SH::L2<T, N>::Zero();
sh = sh + SH::L2<T, N>::Zero();
sh = sh - SH::L2<T, N>::Zero();
sh = sh * T(1.0);
sh = sh * (vector<T, N>)(1.0);
sh = sh / T(1.0);
sh = sh / (vector<T, N>)(1.0);
}
}
template<typename T, int N> void TestBasics()
{
{
SH::L1<T, N> a = SH::L1<T, N>::Zero();
SH::L1<T, N> b = SH::L1<T, N>::Zero();
a = SH::Lerp(a, b, T(0.5));
vector<T, N> v = SH::DotProduct(a, b);
v = SH::Evaluate(a, vector<T, 3>(0.0, 1.0, 0.0));
a = SH::ConvolveWithZH(b, vector<T, 2>(1.0, 1.0));
a = SH::ConvolveWithCosineLobe(a);
a = ConvolveWithGGX(b, T(0.5));
v = SH::CalculateIrradiance(a, vector<T, 3>(0.0, 1.0, 0.0));
a = SH::Rotate(a, float3x3(1, 0, 0, 0, 1, 0, 0, 0, 1));
}
{
SH::L2<T, N> a = SH::L2<T, N>::Zero();
SH::L2<T, N> b = SH::L2<T, N>::Zero();
a = SH::Lerp(a, b, T(0.5));
vector<T, N> v = SH::DotProduct(a, b);
v = SH::Evaluate(a, vector<T, 3>(0.0, 1.0, 0.0));
a = SH::ConvolveWithZH(b, vector<T, 3>(1.0, 1.0, 1.0));
a = SH::ConvolveWithCosineLobe(a);
a = ConvolveWithGGX(b, T(0.5));
v = SH::CalculateIrradiance(a, vector<T, 3>(0.0, 1.0, 0.0));
a = SH::Rotate(a, float3x3(1, 0, 0, 0, 1, 0, 0, 0, 1));
}
}
template<typename T, int N> void TestL1Specifics()
{
SH::L1<T, N> sh = SH::ProjectOntoL1(vector<T, 3>(0.0, 1.0, 0.0), (vector<T, N>)(1.0));
vector<T, 3> d = SH::OptimalLinearDirection(sh);
vector<T, N> v = (vector<T, N>)(0.0);
SH::ApproximateDirectionalLight(sh, d, v);
v = SH::CalculateIrradianceGeomerics(sh, vector<T, 3>(0.0, 1.0, 0.0));
v = SH::CalculateIrradianceL1ZH3Hallucinate(sh, vector<T, 3>(0.0, 1.0, 0.0));
vector<T, 2> zh = SH::ApproximateGGXAsL1ZH(T(0.5));
T s = T(0.0);
SH::ExtractSpecularDirLight(sh, T(0.5), d, v, s);
}
template<typename T, int N> void TestL2Specifics()
{
SH::L2<T, N> sh = SH::L2<T, N>::Zero();
SH::L1<T, N> l1 = SH::L2toL1(sh);
vector<T, 3> zh = SH::ApproximateGGXAsL2ZH(T(0.5));
}
[numthreads(1, 1, 1)]
void CompileTest()
{
TestOperatorOverloads<float, 1>();
TestOperatorOverloads<float, 3>();
TestOperatorOverloads<half, 1>();
TestOperatorOverloads<half, 3>();
TestBasics<float, 1>();
TestBasics<float, 3>();
TestBasics<half, 1>();
TestBasics<half, 3>();
TestL1Specifics<float, 1>();
TestL1Specifics<float, 3>();
TestL1Specifics<half, 1>();
TestL1Specifics<half, 3>();
TestL2Specifics<float, 1>();
TestL2Specifics<float, 3>();
TestL2Specifics<half, 1>();
TestL2Specifics<half, 3>();
}