Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
43d7e61
1
Parent(s):
f1b7a92
update
Browse files
trellis2/renderers/pbr_mesh_renderer.py
CHANGED
|
@@ -19,7 +19,7 @@ def cube_to_dir(s, x, y):
|
|
| 19 |
|
| 20 |
def latlong_to_cubemap(latlong_map, res):
|
| 21 |
if 'dr' not in globals():
|
| 22 |
-
|
| 23 |
cubemap = torch.zeros(6, res[0], res[1], latlong_map.shape[-1], dtype=torch.float32, device='cuda')
|
| 24 |
for s in range(6):
|
| 25 |
gy, gx = torch.meshgrid(torch.linspace(-1.0 + 1.0 / res[0], 1.0 - 1.0 / res[0], res[0], device='cuda'),
|
|
@@ -37,11 +37,17 @@ def latlong_to_cubemap(latlong_map, res):
|
|
| 37 |
|
| 38 |
class EnvMap:
|
| 39 |
def __init__(self, image: torch.Tensor):
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
self
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
def shade(self, gb_pos, gb_normal, kd, ks, view_pos, specular=True):
|
| 47 |
return self._backend.shade(gb_pos, gb_normal, kd, ks, view_pos, specular)
|
|
|
|
| 19 |
|
| 20 |
def latlong_to_cubemap(latlong_map, res):
|
| 21 |
if 'dr' not in globals():
|
| 22 |
+
import nvdiffrast.torch as dr
|
| 23 |
cubemap = torch.zeros(6, res[0], res[1], latlong_map.shape[-1], dtype=torch.float32, device='cuda')
|
| 24 |
for s in range(6):
|
| 25 |
gy, gx = torch.meshgrid(torch.linspace(-1.0 + 1.0 / res[0], 1.0 - 1.0 / res[0], res[0], device='cuda'),
|
|
|
|
| 37 |
|
| 38 |
class EnvMap:
|
| 39 |
def __init__(self, image: torch.Tensor):
|
| 40 |
+
self.image = image
|
| 41 |
+
|
| 42 |
+
@property
|
| 43 |
+
def _backend(self):
|
| 44 |
+
if not hasattr(self, '_nvdiffrec_envlight'):
|
| 45 |
+
if 'EnvironmentLight' not in globals():
|
| 46 |
+
from nvdiffrec_render.light import EnvironmentLight
|
| 47 |
+
cubemap = latlong_to_cubemap(self.image, [512, 512])
|
| 48 |
+
self._nvdiffrec_envlight = EnvironmentLight(cubemap)
|
| 49 |
+
self._nvdiffrec_envlight.build_mips()
|
| 50 |
+
return self._nvdiffrec_envlight
|
| 51 |
|
| 52 |
def shade(self, gb_pos, gb_normal, kd, ks, view_pos, specular=True):
|
| 53 |
return self._backend.shade(gb_pos, gb_normal, kd, ks, view_pos, specular)
|