Skip to content
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

Edge case #9

Open
anuartask opened this issue Nov 5, 2024 · 0 comments
Open

Edge case #9

anuartask opened this issue Nov 5, 2024 · 0 comments

Comments

@anuartask
Copy link

Hello! We've encountered an edge case that seems to break watertightness in the rasterization step.

import torch
import drtk
device = "cuda:0"
verts = torch.tensor(
    [
        [0.5, 0.49993896484375, 1],
        [0.5, 6.5, 1],
        [6.50006103515625, 0.49993896484375, 1],
        [6.50006103515625, 6.5, 1],
    ], 
    device=device
).unsqueeze(0)
tris = torch.tensor(
    [
        [0, 1, 2],
        [3, 2, 1],
    ], device=device
).int()

rast_out = drtk.rasterize(verts, tris, height=8, width=8)
print(rast_out)

The resulting buffer is:

tensor([[[-1, -1, -1, -1, -1, -1, -1, -1],
         [-1,  0,  0,  0,  0,  0, -1, -1],
         [-1,  0,  0,  0,  0, -1,  1, -1],
         [-1,  0,  0,  0, -1,  1,  1, -1],
         [-1,  0,  0, -1,  1,  1,  1, -1],
         [-1,  0, -1,  1,  1,  1,  1, -1],
         [-1, -1,  1,  1,  1,  1,  1, -1],
         [-1, -1, -1, -1, -1, -1, -1, -1]]], device='cuda:0',
       dtype=torch.int32)

Note -1s on the diagonal strip of pixels between the two triangles. Since the triangles share the edge, there should not be a holes between them. And indeed, nvdiffrast, which uses hardware rasterizer, does not produce similar artefacts.

One curious detail is if we flip one of the triangles the problem seems to go away:

tris = torch.tensor(
    [
        [0, 1, 2],
        [3, 1, 2],
    ], device=device
).int()
rast_out = drtk.rasterize(verts, tris, height=8, width=8)
print(rast_out)

Output:

tensor([[[-1, -1, -1, -1, -1, -1, -1, -1],
         [-1,  0,  0,  0,  0,  0,  1, -1],
         [-1,  0,  0,  0,  0,  1,  1, -1],
         [-1,  0,  0,  0,  1,  1,  1, -1],
         [-1,  0,  0,  1,  1,  1,  1, -1],
         [-1,  0,  1,  1,  1,  1,  1, -1],
         [-1,  1,  1,  1,  1,  1,  1, -1],
         [-1, -1, -1, -1, -1, -1, -1, -1]]], device='cuda:0',
       dtype=torch.int32)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant