Skip to content

Dealing with normals of sharp edges #139

Closed
@ffreyer

Description

@ffreyer

For a smooth underlying shape, you want normals to vary smoothly as well. That way shading will restore smooth of the curvature that is lost in triangulation. If you have sharp edges though, this effect is undesired. In a cube for example, you want normals to jump when moving from face to face, even if you're looking at the same position.

One way to deal with this is to duplicate vertices (i.e. position and normal) like I did in #36 a while ago. This is the case now for some primitives, likeRect3D or Pyramind.

Screenshot from 2021-03-11 12-46-18
(The bottom face has normals in the wrong direction here...)

Other primitives don't do this, like for example Cylinder.

Screenshot from 2021-03-11 12-47-09

We could go through all the mesh generating functions and duplicate vertices where needed, but I don't think that a good idea. My concerns are the following:

  • We should avoid repeating data. Currently a Rect3D generates 24 coordinates instead of 8. There are also only 6 unique normals, but we generate 24. That's a lot of extra fat...
  • It's weird to get duplicate positions from coordinates as user. For example, in MakieTeX I needed to transform a 3D bounding box and I thought I could just do map(v -> transform * v, coordinates(bbox)) and then remembered that that is 3x more work than it should be.

I think the way to deal with is detach positions, normals, etc, for example by changing faces to have one index per attribute like in obj files. Or by adding some remapping functionality that can map vertex indices (1:24 for Rect3D) to attribute indices (1:8 for positions, 1:6 for normals). Making these changes should also mean that reading obj files (and probably others?) becomes easier. (I think JuliaIO/MeshIO.jl#64 would become unnecessary and we could go back on it, for example.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions