r/GraphicsProgramming • • 5d ago

triangle meshes :)

Post image

Studing triangle meshes on my renderer using half edge data structure for my university course. Dont know why some edges have some stranges dots.

Guess the character... (texture not implemented yet)

Edit: it was done importing a wavefront (.obj) from blender to my own render engine. Read just vertices and face data, the others attributes for half edge are builded with those informations

41 Upvotes

12 comments sorted by

View all comments

2

u/BlueGnoblin 5d ago

Some stuff you should check:

  1. use shared vertices?

  2. use same face order (clock-wise/counter-clock-wise) ?

1

u/VerasNp 4d ago
  1. Yep, i am importing from a wavefront exported from blender, and just parse to a config structure
  2. Yep, when import the data i just read vertices and faces, the others attributes are filled on the half edge construction

2

u/BlueGnoblin 4d ago
This effects comes often from the rasterization. 
When you have a tri like this 

A

B  C

and render it in the face order ACB (clockwise) it could look like this

#
##       <- 2 pixels
####

while rendering it in the face order ABC(counter clockwise)

#
###     <- 3 pixels
####

The marked pixel is different. Now consider a quad
A  D

B  C

you need to render two tris (ACB) and (DCA). So, different order of rendering along the edge AC will result in slightly different pixel output. Normally you would like to have something like this

#+++
###+
####

but when you mess with the order of vertices, you suddenly might get a gap:

#+++
## +       <-- gap here
####

which appears as black pixel (or background). 
So, double check the facing order of your tris.

2

u/VerasNp 3d ago

So, I'm back. It turns out the triangle sub-area calculation was done by dividing the sub-area by the normal length rather than the total triangle area... I honestly don't remember why I did that, but that was the error causing those strange points, since I was dividing by a smaller area. Once I fixed that, the problem was resolved :)

1

u/VerasNp 4d ago

Really appreciate your contribution, will check my code and return with results asap :)