Skip to content

Commit

Permalink
demo: Apply small depth offset to geometry to avoid overlay z-fighting
Browse files Browse the repository at this point in the history
This has to be done on the material itself as lines do not support depth
offset in three.js; unfortunately this also means this doesn't help when
wireframe rendering is used.
  • Loading branch information
zeux committed Aug 19, 2024
1 parent 275d732 commit 621b207
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions demo/simplify.html
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,12 @@
if (object.isMesh) {
if (!object.original) {
object.original = object.geometry.clone();

// use small depth offset to avoid overlay z-fighting with the original mesh
// has to be done on the main material as overlays use lines that don't support depth offset
object.material.polygonOffset = true;
object.material.polygonOffsetUnits = 16;

object.material = [
object.material,
new THREE.MeshBasicMaterial({ color: 0x0000ff, wireframe: true }), // border
Expand Down

0 comments on commit 621b207

Please sign in to comment.