Skip to content

Smaller faces are abandoned? #888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kunyao opened this issue Oct 19, 2021 · 6 comments
Closed

Smaller faces are abandoned? #888

kunyao opened this issue Oct 19, 2021 · 6 comments
Assignees
Labels
question Further information is requested Stale

Comments

@kunyao
Copy link

kunyao commented Oct 19, 2021

When I trace a very weird bug in my program, I find pytorch3d sometimes fails to render some parts of the meshes. An example mesh and rendering scripts are attached below. I am not sure if it's because the renderer abandons some small triangles. Is there any way to solve this?

import os
import torch
import numpy as np

# Util function for loading meshes
from pytorch3d.io import load_objs_as_meshes, load_obj

# Data structures and functions for rendering
from pytorch3d.structures import Meshes
from pytorch3d.renderer import (
    look_at_view_transform,
    FoVPerspectiveCameras,
    OrthographicCameras,
    PointLights,
    DirectionalLights,
    AmbientLights,
    Materials,
    BlendParams,
    RasterizationSettings,
    MeshRenderer,
    MeshRasterizer,
    SoftPhongShader,
    SoftSilhouetteShader,
    Textures,
    TexturesUV,
    TexturesVertex
)
import torchvision


device = torch.device("cuda:0")
print("Loading...")
obj_filename = './a.obj'
verts, faces, aux = load_obj(obj_filename)
verts = verts * 0.7
meshes = Meshes(verts=[verts], faces=[faces.verts_idx], textures=None)

print("Done...")

print("Generating...")
meshes = meshes.cuda()

cameras = OrthographicCameras(focal_length=((1, 1280 / 720),), principal_point=((0, 0),), device=device)

raster_settings = RasterizationSettings(
    image_size=(1280, 720),
    bin_size=None,
    blur_radius=1e-3,
    faces_per_pixel=1,
)

lights = AmbientLights(device=device)
blend_params = BlendParams(background_color=(0, 0, 0))
renderer = MeshRenderer(
    rasterizer=MeshRasterizer(cameras=cameras, raster_settings=raster_settings),
    shader=SoftSilhouetteShader(blend_params=blend_params)
)

print("Rendering...")
images = renderer(meshes)
images[images !=0 ]= 1.0

torchvision.utils.save_image(images.permute(0, 3, 1, 2)[:, 3:4, :, :], 'out.png')

mesh.zip

A whole face is rendered with many strip artifect
out

@nikhilaravi
Copy link
Contributor

Hi @kunyao apologies for the late response. Can you confirm that all vertices have a positive z value? If not they will be culled.

@nikhilaravi nikhilaravi self-assigned this Nov 15, 2021
@nikhilaravi nikhilaravi added the question Further information is requested label Nov 15, 2021
@kunyao
Copy link
Author

kunyao commented Nov 19, 2021

@nikhilaravi Thanks for your response. I've double checked the issue and pretty sure it came from neither depth culling nor back face culling. I attached the obj file above(see mesh.zip).

@github-actions
Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Dec 19, 2021
@github-actions
Copy link

This issue was closed because it has been stalled for 5 days with no activity.

@ompugao
Copy link

ompugao commented Jan 19, 2022

same here, and the similar behavior can be observed when the camera is far from an object.

@ompugao
Copy link

ompugao commented Jan 20, 2022

ah, sorry. my problem is already well-explained here #348 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested Stale
Projects
None yet
Development

No branches or pull requests

3 participants