antimatter15 commited on
Commit
b5a9e6a
1 Parent(s): 1973aad

minor bug fixes

Browse files
Files changed (2) hide show
  1. .gitattributes +0 -1
  2. main.js +49 -78
.gitattributes DELETED
@@ -1 +0,0 @@
1
- *.{ply,splat} filter=lfs diff=lfs merge=lfs -text
 
 
main.js CHANGED
@@ -482,9 +482,6 @@ function createWorker(self) {
482
  position[2] = attrs.z;
483
 
484
  if (types["f_dc_0"]) {
485
- // rgba[0] = (1 / (1 + Math.exp(-attrs.f_dc_0))) * 255;
486
- // rgba[1] = (1 / (1 + Math.exp(-attrs.f_dc_1))) * 255;
487
- // rgba[2] = (1 / (1 + Math.exp(-attrs.f_dc_2))) * 255;
488
  const SH_C0 = 0.28209479177387814;
489
  rgba[0] = (0.5 + SH_C0 * attrs.f_dc_0) * 255;
490
  rgba[1] = (0.5 + SH_C0 * attrs.f_dc_1) * 255;
@@ -539,31 +536,24 @@ function createWorker(self) {
539
  }
540
 
541
  const vertexShaderSource = `
542
- precision mediump float;
543
- attribute vec2 position;
544
-
545
- attribute vec4 color;
546
- attribute vec4 quat;
547
- attribute vec3 scale;
548
- attribute vec3 center;
549
-
550
- uniform mat4 projection, view;
551
- uniform vec2 focal;
552
-
553
- varying vec4 vColor;
554
- varying vec3 vConic;
555
- varying vec2 vCenter;
556
- varying vec2 vPosition;
557
- uniform vec2 viewport;
558
-
559
- mat3 transpose(mat3 m) {
560
- return mat3(
561
- m[0][0], m[1][0], m[2][0],
562
- m[0][1], m[1][1], m[2][1],
563
- m[0][2], m[1][2], m[2][2]
564
- );
565
- }
566
 
 
 
 
 
 
 
 
567
 
568
  mat3 compute_cov3d(vec3 scale, vec4 rot) {
569
  mat3 S = mat3(
@@ -596,7 +586,7 @@ vec3 compute_cov2d(vec3 center, vec3 scale, vec4 rot){
596
  return vec3(cov[0][0] + 0.3, cov[0][1], cov[1][1] + 0.3);
597
  }
598
 
599
- void main () {
600
  vec4 camspace = view * vec4(center, 1);
601
  vec4 pos2d = projection * mat4(1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1) * camspace;
602
 
@@ -615,31 +605,29 @@ vec3 compute_cov2d(vec3 center, vec3 scale, vec4 rot){
615
 
616
  vPosition = vec2(vCenter + position.x * (position.y < 0.0 ? v1 : v2) / viewport);
617
  gl_Position = vec4(vPosition, pos2d.z / pos2d.w, 1);
618
-
619
- }
620
- `;
621
 
622
  const fragmentShaderSource = `
623
- precision mediump float;
624
-
625
- varying vec4 vColor;
626
- varying vec3 vConic;
627
- varying vec2 vCenter;
628
- uniform vec2 viewport;
629
- uniform vec2 focal;
630
-
631
- void main () {
632
- vec2 d = (vCenter - 2.0 * (gl_FragCoord.xy/viewport - vec2(0.5, 0.5))) * viewport * 0.5;
633
- float power = -0.5 * (vConic.x * d.x * d.x + vConic.z * d.y * d.y) - vConic.y * d.x * d.y;
634
- if (power > 0.0) discard;
635
- float alpha = min(0.99, vColor.a * exp(power));
636
- if(alpha < 0.02) discard;
637
-
638
- gl_FragColor = vec4(alpha * vColor.rgb, alpha);
639
- }
640
- `;
641
-
642
- // let viewMatrix = getViewMatrix(camera);
643
  let defaultViewMatrix = [
644
  0.47, 0.04, 0.88, 0, -0.11, 0.99, 0.02, 0, -0.88, -0.11, 0.47, 0, 0.07,
645
  0.03, 6.55, 1,
@@ -650,7 +638,7 @@ async function main() {
650
  let carousel = true;
651
  const params = new URLSearchParams(location.search);
652
  try {
653
- viewMatrix = JSON.parse(location.hash.slice(1));
654
  carousel = false;
655
  } catch (err) {}
656
  const url = new URL(
@@ -663,7 +651,7 @@ async function main() {
663
  });
664
  console.log(req);
665
  if (req.status != 200)
666
- throw new Error("Unable to load " + req.url + ": " + req.statusText);
667
 
668
  const rowLength = 3 * 4 + 3 * 4 + 4 + 4;
669
  const reader = req.body.getReader();
@@ -998,6 +986,7 @@ async function main() {
998
  let lastFrame = 0;
999
  let avgFps = 0;
1000
  let start = Date.now() + 2000;
 
1001
  const frame = (now) => {
1002
  let inv = invert4(viewMatrix);
1003
  // let preY = inv[13];
@@ -1045,15 +1034,7 @@ async function main() {
1045
 
1046
  if (vertexCount > 0) {
1047
  document.getElementById("spinner").style.display = "none";
1048
-
1049
  gl.uniformMatrix4fv(u_view, false, actualViewMatrix);
1050
-
1051
- // gl.clearColor(0.0, 0.0, 0.0, 1.0); // Set the clear color to black with full opacity
1052
- // gl.clear(gl.COLOR_BUFFER_BIT);
1053
-
1054
- // gl.clearDepth(100000.0);
1055
- // gl.clear(gl.DEPTH_BUFFER_BIT);
1056
-
1057
  ext.drawArraysInstancedANGLE(gl.TRIANGLE_STRIP, 0, 4, vertexCount);
1058
  } else {
1059
  gl.clear(gl.COLOR_BUFFER_BIT);
@@ -1065,9 +1046,7 @@ async function main() {
1065
  } else {
1066
  document.getElementById("progress").style.display = "none";
1067
  }
1068
- fps.innerText =
1069
- Math.round(avgFps) +
1070
- " fps";
1071
  lastFrame = now;
1072
  requestAnimationFrame(frame);
1073
  };
@@ -1118,26 +1097,18 @@ async function main() {
1118
 
1119
  window.addEventListener("hashchange", (e) => {
1120
  try {
1121
- viewMatrix = JSON.parse(location.hash.slice(1));
1122
  carousel = false;
1123
  } catch (err) {}
1124
  });
1125
 
1126
- document.addEventListener("dragenter", (e) => {
1127
- e.preventDefault();
1128
- e.stopPropagation();
1129
- });
1130
-
1131
- document.addEventListener("dragover", (e) => {
1132
- e.preventDefault();
1133
- e.stopPropagation();
1134
- });
1135
-
1136
- document.addEventListener("dragleave", (e) => {
1137
  e.preventDefault();
1138
  e.stopPropagation();
1139
- });
1140
-
 
 
1141
  document.addEventListener("drop", (e) => {
1142
  e.preventDefault();
1143
  e.stopPropagation();
 
482
  position[2] = attrs.z;
483
 
484
  if (types["f_dc_0"]) {
 
 
 
485
  const SH_C0 = 0.28209479177387814;
486
  rgba[0] = (0.5 + SH_C0 * attrs.f_dc_0) * 255;
487
  rgba[1] = (0.5 + SH_C0 * attrs.f_dc_1) * 255;
 
536
  }
537
 
538
  const vertexShaderSource = `
539
+ precision mediump float;
540
+ attribute vec2 position;
541
+
542
+ attribute vec4 color;
543
+ attribute vec4 quat;
544
+ attribute vec3 scale;
545
+ attribute vec3 center;
546
+
547
+ uniform mat4 projection, view;
548
+ uniform vec2 focal;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
549
 
550
+ varying vec4 vColor;
551
+ varying vec3 vConic;
552
+ varying vec2 vCenter;
553
+ varying vec2 vPosition;
554
+ uniform vec2 viewport;
555
+
556
+ mat3 transpose(mat3 m) { return mat3(m[0][0], m[1][0], m[2][0], m[0][1], m[1][1], m[2][1], m[0][2], m[1][2], m[2][2]); }
557
 
558
  mat3 compute_cov3d(vec3 scale, vec4 rot) {
559
  mat3 S = mat3(
 
586
  return vec3(cov[0][0] + 0.3, cov[0][1], cov[1][1] + 0.3);
587
  }
588
 
589
+ void main () {
590
  vec4 camspace = view * vec4(center, 1);
591
  vec4 pos2d = projection * mat4(1,0,0,0,0,-1,0,0,0,0,1,0,0,0,0,1) * camspace;
592
 
 
605
 
606
  vPosition = vec2(vCenter + position.x * (position.y < 0.0 ? v1 : v2) / viewport);
607
  gl_Position = vec4(vPosition, pos2d.z / pos2d.w, 1);
608
+ }
609
+ `;
 
610
 
611
  const fragmentShaderSource = `
612
+ precision mediump float;
613
+
614
+ varying vec4 vColor;
615
+ varying vec3 vConic;
616
+ varying vec2 vCenter;
617
+ uniform vec2 viewport;
618
+ uniform vec2 focal;
619
+
620
+ void main () {
621
+ vec2 d = (vCenter - 2.0 * (gl_FragCoord.xy/viewport - vec2(0.5, 0.5))) * viewport * 0.5;
622
+ float power = -0.5 * (vConic.x * d.x * d.x + vConic.z * d.y * d.y) - vConic.y * d.x * d.y;
623
+ if (power > 0.0) discard;
624
+ float alpha = min(0.99, vColor.a * exp(power));
625
+ if(alpha < 0.02) discard;
626
+
627
+ gl_FragColor = vec4(alpha * vColor.rgb, alpha);
628
+ }
629
+ `;
630
+
 
631
  let defaultViewMatrix = [
632
  0.47, 0.04, 0.88, 0, -0.11, 0.99, 0.02, 0, -0.88, -0.11, 0.47, 0, 0.07,
633
  0.03, 6.55, 1,
 
638
  let carousel = true;
639
  const params = new URLSearchParams(location.search);
640
  try {
641
+ viewMatrix = JSON.parse(decodeURIComponent(location.hash.slice(1)));
642
  carousel = false;
643
  } catch (err) {}
644
  const url = new URL(
 
651
  });
652
  console.log(req);
653
  if (req.status != 200)
654
+ throw new Error(req.status + " Unable to load " + req.url);
655
 
656
  const rowLength = 3 * 4 + 3 * 4 + 4 + 4;
657
  const reader = req.body.getReader();
 
986
  let lastFrame = 0;
987
  let avgFps = 0;
988
  let start = Date.now() + 2000;
989
+
990
  const frame = (now) => {
991
  let inv = invert4(viewMatrix);
992
  // let preY = inv[13];
 
1034
 
1035
  if (vertexCount > 0) {
1036
  document.getElementById("spinner").style.display = "none";
 
1037
  gl.uniformMatrix4fv(u_view, false, actualViewMatrix);
 
 
 
 
 
 
 
1038
  ext.drawArraysInstancedANGLE(gl.TRIANGLE_STRIP, 0, 4, vertexCount);
1039
  } else {
1040
  gl.clear(gl.COLOR_BUFFER_BIT);
 
1046
  } else {
1047
  document.getElementById("progress").style.display = "none";
1048
  }
1049
+ fps.innerText = Math.round(avgFps) + " fps";
 
 
1050
  lastFrame = now;
1051
  requestAnimationFrame(frame);
1052
  };
 
1097
 
1098
  window.addEventListener("hashchange", (e) => {
1099
  try {
1100
+ viewMatrix = JSON.parse(decodeURIComponent(location.hash.slice(1)));
1101
  carousel = false;
1102
  } catch (err) {}
1103
  });
1104
 
1105
+ const preventDefault = (e) => {
 
 
 
 
 
 
 
 
 
 
1106
  e.preventDefault();
1107
  e.stopPropagation();
1108
+ }
1109
+ document.addEventListener("dragenter", preventDefault);
1110
+ document.addEventListener("dragover", preventDefault);
1111
+ document.addEventListener("dragleave", preventDefault);
1112
  document.addEventListener("drop", (e) => {
1113
  e.preventDefault();
1114
  e.stopPropagation();