This project is mirrored from https://github.com/zeux/meshoptimizer.git. Pull mirroring updated .
  1. 22 Apr, 2021 2 commits
    • Arseny Kapoulkine's avatar
      simplify: Fix a significant hash quality issue for integer coordiantes · 761387ad
      Arseny Kapoulkine authored
      When the input coordinates to the hash function were integers (in
      floating point form), the resulting hash function was incredibly poor.
      
      It generated too many collisions because it mostly used the entropy from
      the lower bits, and for integer values many lower bits are 0.
      
      This change fixes the problem by lightly mixing the bits before hashing,
      which seems to completely fix this issue in practice. On a Minecraft
      export, the stats are as follows:
      
      Total number of vertices (with many duplicates): 13 408 528
      Number of unique 32-bit hashes with Murmur: 2 525 651
      Number of unique 32-bit hashes with spatial hash: 205 457
      Number of unique 32-bit hashes with scrambled spatial hash: 2 525 626
      761387ad
    • Arseny Kapoulkine's avatar
      gltfpack: Make sure that toktx is used when -tp is specified · accdba2e
      Arseny Kapoulkine authored
      Without this, we'd silently skip the rescale step when using basisu for
      encoding.
      accdba2e
  2. 14 Apr, 2021 1 commit
  3. 11 Apr, 2021 1 commit
  4. 07 Apr, 2021 7 commits
  5. 06 Apr, 2021 2 commits
  6. 01 Apr, 2021 2 commits
  7. 30 Mar, 2021 3 commits
    • Arseny Kapoulkine's avatar
      Merge pull request #260 from zeux/wasm-movemask · 655c9177
      Arseny Kapoulkine authored
      vertexcodec: Improve Wasm SIMD movemask fallback
      655c9177
    • Arseny Kapoulkine's avatar
      Attempt to fix ARM64 build · 80ad7cc3
      Arseny Kapoulkine authored
      80ad7cc3
    • Arseny Kapoulkine's avatar
      vertexcodec: Improve Wasm SIMD movemask fallback · a53af0ea
      Arseny Kapoulkine authored
      Instead of using bit shifts to compute the bit mask, use a magic 64-bit
      constant to extract the necessary bits in one multiply & shift per
      64-bit lane.
      
      The constant has been found using z3 SMT (thanks to @0b0000000000000 for
      the idea) with the following program:
      
      	; $ z3 bits.smt2
      	; sat
      	; (model
      	;   (define-fun magic () (_ BitVec 64)
      	;     #x000103070f1f3f80)
      	; )
      
      	(set-logic BV)
      
      	(declare-const magic (_ BitVec 64))
      
      	(define-fun same ((v (_ BitVec 8))) Bool
      	 (or (= v #x00) (= v #xFF)))
      
      	(assert
      	  (forall ((x (_ BitVec 64)))
      	    (let ((y (bvmul x magic)))
      	      (or
      		(not
      		  (and
      		   (same ((_ extract 63 56) x))
      		   (same ((_ extract 55 48) x))
      		   (same ((_ extract 47 40) x))
      		   (same ((_ extract 39 32) x))
      		   (same ((_ extract 31 24) x))
      		   (same ((_ extract 23 16) x))
      		   (same ((_ extract 15 8) x))
      		   (same ((_ extract 7 0) x))
      		   )
      		)
      		(and
      		  (= ((_ extract 63 63) x) ((_ extract 63 63) y))
      		  (= ((_ extract 55 55) x) ((_ extract 62 62) y))
      		  (= ((_ extract 47 47) x) ((_ extract 61 61) y))
      		  (= ((_ extract 39 39) x) ((_ extract 60 60) y))
      		  (= ((_ extract 31 31) x) ((_ extract 59 59) y))
      		  (= ((_ extract 23 23) x) ((_ extract 58 58) y))
      		  (= ((_ extract 15 15) x) ((_ extract 57 57) y))
      		  (= ((_ extract  7  7) x) ((_ extract 56 56) y))
      		)
      	      )
      	    )
      	  )
      	)
      
      	(check-sat)
      	(get-model)
      
      This improves vertexcodec performance by ~5% on latest node.js/x64.
      a53af0ea
  8. 05 Feb, 2021 2 commits
    • Arseny Kapoulkine's avatar
      Merge pull request #239 from zeux/gltf-variants · 3bdc8125
      Arseny Kapoulkine authored
      gltfpack: Implement support for KHR_materials_variants
      3bdc8125
    • Arseny Kapoulkine's avatar
      gltfpack: Implement union-find to correctly quantize variant UVs · 0d0c363d
      Arseny Kapoulkine authored
      To make sure that all variants can be used interchangeably we need to
      make sure that whenever multiple materials can be used on a given mesh,
      the quantization grid for these materials matches.
      
      Since multiple meshes can use a single material as well, this means that
      multiple materials can be bound by the same quantization rules even if
      they are never used on the same mesh, for example:
      
      	mesh 0: materials 0, 1
      	mesh 1: materials 2, 3
      	mesh 2: materials 0, 3
      
      Here all 4 materials must use the same quantization settings even though
      materials 1 & 2 never overlap; to make all 3 meshes render correctly we
      need to use the common quantization for all 3 meshes for all 4
      materials.
      
      To make this work, we use union-find to find a single "canonical"
      material for each source mesh & material; we use that slot to accumulate
      UV bounds and then redistribute the resulting quantization parameters to
      all relevant materials.
      0d0c363d
  9. 04 Feb, 2021 1 commit
  10. 02 Feb, 2021 8 commits
  11. 31 Jan, 2021 6 commits
  12. 27 Jan, 2021 5 commits
    • Arseny Kapoulkine's avatar
      Merge pull request #235 from zeux/adj · d5620df6
      Arseny Kapoulkine authored
      indexgenerator: Implement support for triangle adjacency index buffers
      d5620df6
    • Arseny Kapoulkine's avatar
      indexgenerator: Share buildPositionRemap across two new generators · dc2823ce
      Arseny Kapoulkine authored
      This code is identical and self-sufficient so it's easy to extract.
      Building the edge table is more specialized due to the need for storing
      the opposite vertex, and the hasher along with other data is necessary
      during lookup, so it's better to leave that duplicated for now.
      dc2823ce
    • Arseny Kapoulkine's avatar
      indexgenerator: Implement support for triangle adjacency index buffers · 91fbf4e2
      Arseny Kapoulkine authored
      Several algorithms that use geometry shaders to render data require
      adjacency information; triangle-with-adjacency topology in various APIs
      provides a way to supply 3 extra vertices per each triangle that
      represent vertices opposite to each triangle's edge.
      
      This data can then be used to compute silhouettes and perform other
      types of local geometric processing.
      
      This change implements the data preprocessing step that is similar to
      the previous tessellation IB - but instead of storing vertices that
      adjoin the triangle from the opposite side, we need to store
      complementary / opposite vertices of adjacent triangles, which requires
      a separate temporary table.
      91fbf4e2
    • Arseny Kapoulkine's avatar
      Merge pull request #234 from zeux/tess · 63bacf12
      Arseny Kapoulkine authored
      indexgenerator: Implement support for PN-AEN tessellation buffers
      63bacf12
    • Arseny Kapoulkine's avatar
      indexgenerator: Implement support for PN-AEN tessellation buffers · 0ad425d7
      Arseny Kapoulkine authored
      To render a mesh with normal/UV seams using hardware tessellation, the
      PN-triangles method is not sufficient as it produces cracks on normal
      discontinuities (position displacement based on normal is not consistent
      along both sides of the seam), and displacement mapping uses slightly
      different texture samples which results in cracks along UV seams.
      
      In 2010, NVidia proposed a PN-AEN tessellation scheme that fixes the
      problem around normal discontinuities by using opposite edge normals and
      averaging the resulting control point data. In 2011, NVidia proposed a
      further tweak on top of this technique that allows to select the
      "dominant" edge by choosing the min. edge index out of the
      current/adjacent edges, and using the UV data from that edge on the
      patch edges to sample the displacement data. For corners, there can be
      more than two wedges that have the same position, so you need to store
      the dominant vertex for each patch corner as well.
      
      As a result, generating a 12-vertex patch for each input triangle allows
      to use the hardware tessellation engine to implement PN-AEN (using 9
      vertices) and/or displacement mapping (using 3 more vertices) without
      cracks.
      
      This change implements the data preprocessing step for this algorithm as
      meshopt_generateTessellationIndexBuffer; this index buffer can be
      directly fed to the GPU along with the requisite hull/domain shaders.
      
      For implementing the shader code, the following papers are recommended:
      
      John McDonald, Mark Kilgard
      Crack-Free Point-Normal Triangles using Adjacent Edge Normals. 2010
      
      John McDonald
      Tessellation on Any Budget. 2010
      
      Bryan Dudash
      My Tessellation Has Cracks! 2012
      0ad425d7