-
Notifications
You must be signed in to change notification settings - Fork 3
/
test.cpp
83 lines (66 loc) · 3.28 KB
/
test.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
// A numerical validation for the paper "Microsurface Transformations"
// by Asen Atanasov, Vladimir Koylazov, Rossen Dimov and Alexander Wilkie, EGSR'22
// A number of microsurfaces (GTR, GGX, Beckmann, Phong, Sheen, STD, Discrete) with random parameters are created.
// Their normalization and shadowing constraints are integrated numerically, then these microsurfaces
// are transformed by a random matrix M and the constraints are computed again. Note that in some cases like
// Phong, Sheen, STD, Discrete the Smith shadowing approximations are not always accurate. When a shadowing
// constraint is not accurate for the original surface it is also not accurate for the transformed surface.
// Author: Asen Atanasov
#include <iostream>
#include <math.h>
#include <string.h>
#include "microsurface_transformations.h"
using namespace std;
int main() {
const int numTests=10;
const int numSamples=1000000;
for(int i=1; i<=numTests; i++) {
cout << "**********************************************************************************************" << endl;
cout << "Test " << i << ":" << endl;
const float alphaX=rnd();
const float alphaY=rnd();
const float gamma=rnd(0.0f, 4.0f);
cout << "Random roughness and tail parameters:" << endl;
cout << "AlphaX: " << alphaX << endl;
cout << "AlphaY: " << alphaY << endl;
cout << "Gamma: " << gamma << endl;
cout << endl;
const Vector outgoing=getSphereDir(rnd(), rnd());
cout << "Random shadowing direction = (" << outgoing.x << ", " << outgoing.y << ", " << outgoing.z << ")" << endl << endl;
Matrix m;
m.setCol(0, Vector(rnd(-10.0f, 10.0f), rnd(-10.0f, 10.0f), 0.0f));
m.setCol(1, Vector(rnd(-10.0f, 10.0f), rnd(-10.0f, 10.0f), 0.0f));
m.setCol(2, Vector(0.0f, 0.0f, 1.0f));
cout << "Generate matrix M with random entries in (-10, 10):" << endl;
cout << "M = (" << m[0][0] << ", " << m[0][1] << ") (" << m[1][0] << ", " << m[1][1] << ")" << endl << endl;
GTR gtr(alphaX, gamma);
GGX ggx(alphaX, alphaY);
Beckmann beckmann(alphaX, alphaY);
Phong phong(alphaX);
Sheen sheen(alphaX);
STD std(alphaX, alphaY, gamma+1.5f);
Discrete discrete(alphaX, gamma, 100);
int numSurfaces=0;
Microsurface *microsurfaces[8];
microsurfaces[numSurfaces++]=>r;
microsurfaces[numSurfaces++]=&ggx;
microsurfaces[numSurfaces++]=&beckmann;
microsurfaces[numSurfaces++]=&phong;
microsurfaces[numSurfaces++]=&sheen;
microsurfaces[numSurfaces++]=&std;
microsurfaces[numSurfaces++]=&discrete;
cout << "Test normalization and shadowing constraints for the original and transformed by M surfaces:" << endl;
for(int j=0; j<numSurfaces; j++) {
Microsurface *surface=microsurfaces[j];
const char *name=surface->getName();
const float norm=surface->integrateDistribution(numSamples);
const float shadow=surface->shadowingConstraint(outgoing, numSamples);
surface->initTransform(m);
const float normM=surface->integrateDistribution(numSamples);
const float shadowM=surface->shadowingConstraint(outgoing, numSamples);
cout << name << " Normalization constraint:\toriginal=" << norm << ",\ttransformed=" << normM << endl;
cout << name << " Shadowing constraint:\toriginal=" << shadow << ",\ttransformed=" << shadowM << endl;
}
}
return 0;
}