Closed ghost closed 3 years ago
@SHOW-xiuchao do you mean you don't want lighting and only want to blend the texture color? Do you want the rendering to be differentiable or you only require the forward pass?
You can create your own shader class which doesn't use lighting e.g.
class SoftShader(nn.Module):
"""
Soft Shader with no lighting
"""
def __init__(self, device="cpu", cameras=None, blend_params=None):
super().__init__()
self.cameras = cameras
self.blend_params = blend_params if blend_params is not None else BlendParams()
def to(self, device):
# Manually move to device modules which are not subclasses of nn.Module
self.cameras = self.cameras.to(device)
return self
def forward(self, fragments, meshes, **kwargs) -> torch.Tensor:
cameras = kwargs.get("cameras", self.cameras)
if cameras is None:
msg = "Cameras must be specified either at initialization \
or in the forward pass of SoftPhongShader"
raise ValueError(msg)
texels = meshes.sample_textures(fragments)
blend_params = kwargs.get("blend_params", self.blend_params)
znear = kwargs.get("znear", getattr(cameras, "znear", 1.0))
zfar = kwargs.get("zfar", getattr(cameras, "zfar", 100.0))
images = softmax_rgb_blend(
texels, fragments, blend_params, znear=znear, zfar=zfar
)
return images
If you don't need the rendering to be differentiable you can swap out softmax_rgb_blend
for hard_rgb_blend
.
@nikhilaravi Hi, it works for me, thanks!
Hi, I'd like to know if there is a way to directly use texture color as final shading color, which is useful for some operations like warping.