mirror of
https://github.com/facebookresearch/pytorch3d.git
synced 2026-04-11 23:16:01 +08:00
Add benchmark for diffuse and specular lighting
Summary: I was trying to speed up the lighting computations, but my ideas didn't work. Even if that didn't work, we can at least commit the benchmarking script I wrote for diffuse and specular shading. Reviewed By: nikhilaravi Differential Revision: D21580171 fbshipit-source-id: 8b60c0284e91ecbe258b6aae839bd5c2bbe788aa
This commit is contained in:
committed by
Facebook GitHub Bot
parent
3fef506895
commit
d8987c6f48
@@ -61,6 +61,7 @@ def diffuse(normals, color, direction) -> torch.Tensor:
|
||||
color = color.view(expand_dims)
|
||||
|
||||
# Renormalize the normals in case they have been interpolated.
|
||||
# We tried to replace the following with F.cosine_similarity, but it wasn't faster.
|
||||
normals = F.normalize(normals, p=2, dim=-1, eps=1e-6)
|
||||
direction = F.normalize(direction, p=2, dim=-1, eps=1e-6)
|
||||
angle = F.relu(torch.sum(normals * direction, dim=-1))
|
||||
@@ -132,6 +133,8 @@ def specular(
|
||||
shininess = shininess.view(expand_dims)
|
||||
|
||||
# Renormalize the normals in case they have been interpolated.
|
||||
# We tried a version that uses F.cosine_similarity instead of renormalizing,
|
||||
# but it was slower.
|
||||
normals = F.normalize(normals, p=2, dim=-1, eps=1e-6)
|
||||
direction = F.normalize(direction, p=2, dim=-1, eps=1e-6)
|
||||
cos_angle = torch.sum(normals * direction, dim=-1)
|
||||
|
||||
Reference in New Issue
Block a user