MCPcopy Create free account
hub / github.com/3DAnimals/3DAnimals / FixedDirectionLight

Class FixedDirectionLight

visualization/visualize_results.py:59–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57
58
59class FixedDirectionLight(torch.nn.Module):
60 def __init__(self, direction, amb, diff):
61 super(FixedDirectionLight, self).__init__()
62 self.light_dir = direction
63 self.amb = amb
64 self.diff = diff
65 self.is_hacking = not (isinstance(self.amb, float)
66 or isinstance(self.amb, int))
67
68 def forward(self, feat):
69 batch_size = feat.shape[0]
70 if self.is_hacking:
71 return torch.concat([self.light_dir, self.amb, self.diff], -1)
72 else:
73 return torch.concat([self.light_dir, torch.FloatTensor([self.amb, self.diff]).to(self.light_dir.device)], -1).expand(batch_size, -1)
74
75 def shade(self, feat, kd, normal):
76 light_params = self.forward(feat)
77 light_dir = light_params[..., :3][:, None, None, :]
78 int_amb = light_params[..., 3:4][:, None, None, :]
79 int_diff = light_params[..., 4:5][:, None, None, :]
80 shading = (int_amb + int_diff *
81 torch.clamp(util.dot(light_dir, normal), min=0.0))
82 shaded = shading * kd
83 return shaded, shading
84
85
86def interpolate(attr, rast, attr_idx, rast_db=None):

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected