forked from microsoft/TRELLIS.2
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_cube_to_dir.py
More file actions
56 lines (50 loc) · 1.89 KB
/
test_cube_to_dir.py
File metadata and controls
56 lines (50 loc) · 1.89 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
#!/usr/bin/env python3
"""
Test if cube_to_dir is working correctly for environment map conversion.
"""
import torch
import numpy as np
def cube_to_dir_old(s, x, y):
"""Old fork version."""
if s == 0: rx, ry, rz = torch.ones_like(x), -y, -x
elif s == 1: rx, ry, rz = -torch.ones_like(x), -y, x
elif s == 2: rx, ry, rz = x, torch.ones_like(x), y
elif s == 3: rx, ry, rz = x, -torch.ones_like(x), -y
elif s == 4: rx, ry, rz = x, -y, torch.ones_like(x)
elif s == 5: rx, ry, rz = -x, -y, -torch.ones_like(x)
return torch.stack((rx, ry, rz), dim=-1)
def cube_to_dir_new(s, x, y):
"""New official version."""
if s == 0: rx, ry, rz = torch.ones_like(x), -x, -y
elif s == 1: rx, ry, rz = -torch.ones_like(x), x, -y
elif s == 2: rx, ry, rz = x, y, torch.ones_like(x)
elif s == 3: rx, ry, rz = x, -y, -torch.ones_like(x)
elif s == 4: rx, ry, rz = x, torch.ones_like(x), -y
elif s == 5: rx, ry, rz = -x, -torch.ones_like(x), -y
return torch.stack((rx, ry, rz), dim=-1)
print("Testing cube_to_dir differences:")
print("=" * 60)
x = torch.tensor([0.5])
y = torch.tensor([0.5])
for s in range(6):
old_dir = cube_to_dir_old(s, x, y)
new_dir = cube_to_dir_new(s, x, y)
diff = (old_dir - new_dir).abs().max().item()
print(f"Face {s}: old={old_dir[0].tolist()}, new={new_dir[0].tolist()}, diff={diff:.4f}")
print("\n" + "=" * 60)
print("Face conventions:")
print(" 0: +X")
print(" 1: -X")
print(" 2: +Y")
print(" 3: -Y")
print(" 4: +Z")
print(" 5: -Z")
print()
print("OLD: Y and Y, swapped in some faces")
print("NEW: Official nvdiffrast/nvdiffrec convention")
print()
print("If the cubemap is built differently, lighting directions will")
print("differ. This affects specular reflection and diffuse irradiance.")
print()
print("The issue is that latlong_to_cubemap needs to use the SAME")
print("convention as when sampling the cubemap during shade().")