Skip to content

Instantly share code, notes, and snippets.

@jdeagle
Last active January 23, 2018 16:17
Show Gist options
  • Save jdeagle/e53735fd299e3e5d669abce48ad41158 to your computer and use it in GitHub Desktop.
Save jdeagle/e53735fd299e3e5d669abce48ad41158 to your computer and use it in GitHub Desktop.
Notes for Hector PBF

PBF notes for hector

Global

Use const if you aren’t going to reassign the variable value (especially for functions)

Mesher

72: for (let i = 0; i <trianglesOnVoxels.length; i ++) tInV.push(trianglesOnVoxels[i].length);

Can be rewritten with map (faster for https://jsperf.com/map-vs-for-loop-performance/6)

tInV = trianglesOnVoxels.map((i) => i.length);

Division is slow. Can you do *.33333?

86: let u = tInV[i] / 3;

102: tTriangles, tNormals, tVoxeslOffset are all the same values, can these be one shared texture? Is there a faster way to clone textures over webGL2createTexture2D?

loop optimizations

Your loop length gets evaluated on each iteration, save as var for faster loops...

123: for (let i = 0, l =Math.ceil(Math.log(_expandedTextureSize) / Math.log(2)); i < l; i++) {

instead of

123: for (let i = 0; i < Math.ceil(Math.log(_expandedTextureSize) / Math.log(2)); i++) {

array length over push (if your really need it) https://jsperf.com/ereioeriuoerwiouewjfkfsjkdjhroweuryw

WebGL2

in createTexture2D, can you use multiplication or bitshifting instead of division for generating m?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment