@xeokit/xeokit-sdk 2.3.0-beta-15 → 2.3.0-beta-18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12106,34 +12106,27 @@ class Canvas extends Component {
12106
12106
 
12107
12107
  let lastParent = null;
12108
12108
 
12109
- let tickCount = 0; // chipmunk
12109
+ let tickCount = 0;
12110
12110
 
12111
12111
  this._tick = this.scene.on("tick", () => {
12112
12112
 
12113
- tickCount++; // chipmunk
12113
+ tickCount++;
12114
12114
 
12115
12115
  self._canvasSizeChanged = false;
12116
12116
 
12117
- if (self.optimizeResizeDetection)
12118
- {
12119
- if (tickCount < 60) // chipmunk
12120
- { // chipmunk
12121
- return; // chipmunk
12122
- } // chipmunk
12117
+ if (self.optimizeResizeDetection) {
12118
+ if (tickCount < 10) {
12119
+ return;
12120
+ }
12123
12121
  }
12124
12122
 
12125
- tickCount = 0; // chipmunk
12123
+ tickCount = 0;
12126
12124
 
12127
12125
  const canvas = this.canvas;
12128
12126
 
12129
12127
  const newResolutionScale = (this._resolutionScale !== lastResolutionScale);
12130
12128
  const newWindowSize = (window.innerWidth !== lastWindowWidth || window.innerHeight !== lastWindowHeight);
12131
12129
 
12132
- if (!newWindowSize) // chipmunk
12133
- { // chipmunk
12134
- return; // chipmunk
12135
- } // chipmunk
12136
-
12137
12130
  const newCanvasSize = (canvas.clientWidth !== lastCanvasWidth || canvas.clientHeight !== lastCanvasHeight);
12138
12131
  const newCanvasPos = (canvas.offsetLeft !== lastCanvasOffsetLeft || canvas.offsetTop !== lastCanvasOffsetTop);
12139
12132
 
@@ -14609,7 +14602,8 @@ class SAODepthLimitedBlurRenderer {
14609
14602
  }
14610
14603
 
14611
14604
  outColor = packFloatToRGBA(occlusionSum / weightSum);
14612
- }`]
14605
+ }`
14606
+ ]
14613
14607
  });
14614
14608
 
14615
14609
  if (this._program.errors) {
@@ -14699,7 +14693,7 @@ class SAODepthLimitedBlurRenderer {
14699
14693
 
14700
14694
  gl.uniform1fv(this._uSampleWeights, sampleWeights);
14701
14695
 
14702
- const depthTexture = depthRenderBuffer.getDepthTexture();
14696
+ const depthTexture = depthRenderBuffer.getDepthTexture();
14703
14697
  const occlusionTexture = occlusionRenderBuffer.getTexture();
14704
14698
 
14705
14699
  program.bindTexture(this._uDepthTexture, depthTexture, 0); // TODO: use FrameCtx.textureUnit
@@ -15999,22 +15993,6 @@ const Renderer = function (scene, options) {
15999
15993
  gl.depthMask(false);
16000
15994
  }
16001
15995
 
16002
- // Transparent X-ray edges
16003
-
16004
- if (xrayEdgesTransparentBinLen > 0) {
16005
- for (i = 0; i < xrayEdgesTransparentBinLen; i++) {
16006
- xrayEdgesTransparentBin[i].drawEdgesXRayed(frameCtx);
16007
- }
16008
- }
16009
-
16010
- // Transparent X-ray fill
16011
-
16012
- if (xrayedFillTransparentBinLen > 0) {
16013
- for (i = 0; i < xrayedFillTransparentBinLen; i++) {
16014
- xrayedFillTransparentBin[i].drawSilhouetteXRayed(frameCtx);
16015
- }
16016
- }
16017
-
16018
15996
  // Transparent color edges
16019
15997
 
16020
15998
  if (normalFillTransparentBinLen > 0 || normalEdgesTransparentBinLen > 0) {
@@ -16035,6 +16013,23 @@ const Renderer = function (scene, options) {
16035
16013
  drawable.drawColorTransparent(frameCtx);
16036
16014
  }
16037
16015
  }
16016
+
16017
+ // Transparent X-ray edges
16018
+
16019
+ if (xrayEdgesTransparentBinLen > 0) {
16020
+ for (i = 0; i < xrayEdgesTransparentBinLen; i++) {
16021
+ xrayEdgesTransparentBin[i].drawEdgesXRayed(frameCtx);
16022
+ }
16023
+ }
16024
+
16025
+ // Transparent X-ray fill
16026
+
16027
+ if (xrayedFillTransparentBinLen > 0) {
16028
+ for (i = 0; i < xrayedFillTransparentBinLen; i++) {
16029
+ xrayedFillTransparentBin[i].drawSilhouetteXRayed(frameCtx);
16030
+ }
16031
+ }
16032
+
16038
16033
  gl.disable(gl.BLEND);
16039
16034
  if (!alphaDepthMask) {
16040
16035
  gl.depthMask(true);
@@ -45607,10 +45602,7 @@ class TrianglesBatchingColorTextureRenderer {
45607
45602
  gl.uniform1i(this._uRenderPass, renderPass);
45608
45603
 
45609
45604
  gl.uniformMatrix4fv(this._uViewMatrix, false, (origin) ? createRTCViewMat(camera.viewMatrix, origin) : camera.viewMatrix);
45610
- gl.uniformMatrix4fv(this._uViewNormalMatrix, false, camera.viewNormalMatrix);
45611
-
45612
45605
  gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix);
45613
- gl.uniformMatrix4fv(this._uWorldNormalMatrix, false, model.worldNormalMatrix);
45614
45606
 
45615
45607
  const numSectionPlanes = scene._sectionPlanesState.sectionPlanes.length;
45616
45608
  if (numSectionPlanes > 0) {
@@ -45644,10 +45636,6 @@ class TrianglesBatchingColorTextureRenderer {
45644
45636
 
45645
45637
  this._aPosition.bindArrayBuffer(state.positionsBuf);
45646
45638
 
45647
- if (this._aNormal) {
45648
- this._aNormal.bindArrayBuffer(state.normalsBuf);
45649
- }
45650
-
45651
45639
  if (this._aUV) {
45652
45640
  this._aUV.bindArrayBuffer(state.uvBuf);
45653
45641
  }
@@ -45718,9 +45706,7 @@ class TrianglesBatchingColorTextureRenderer {
45718
45706
  this._uPositionsDecodeMatrix = program.getLocation("positionsDecodeMatrix");
45719
45707
  this._uUVDecodeMatrix = program.getLocation("uvDecodeMatrix");
45720
45708
  this._uWorldMatrix = program.getLocation("worldMatrix");
45721
- this._uWorldNormalMatrix = program.getLocation("worldNormalMatrix");
45722
45709
  this._uViewMatrix = program.getLocation("viewMatrix");
45723
- this._uViewNormalMatrix = program.getLocation("viewNormalMatrix");
45724
45710
  this._uProjMatrix = program.getLocation("projMatrix");
45725
45711
 
45726
45712
  this._uLightAmbient = program.getLocation("lightAmbient");
@@ -45767,7 +45753,6 @@ class TrianglesBatchingColorTextureRenderer {
45767
45753
 
45768
45754
  this._aPosition = program.getAttribute("position");
45769
45755
  this._aOffset = program.getAttribute("offset");
45770
- this._aNormal = program.getAttribute("normal");
45771
45756
  this._aUV = program.getAttribute("uv");
45772
45757
  this._aColor = program.getAttribute("color");
45773
45758
  this._aFlags = program.getAttribute("flags");
@@ -45834,9 +45819,7 @@ class TrianglesBatchingColorTextureRenderer {
45834
45819
 
45835
45820
  const scene = this._scene;
45836
45821
  const sectionPlanesState = scene._sectionPlanesState;
45837
- const lightsState = scene._lightsState;
45838
45822
  const clipping = sectionPlanesState.sectionPlanes.length > 0;
45839
- let light;
45840
45823
  const src = [];
45841
45824
  src.push("#version 300 es");
45842
45825
  src.push("// Triangles batching color texture vertex shader");
@@ -45844,7 +45827,6 @@ class TrianglesBatchingColorTextureRenderer {
45844
45827
  src.push("uniform int renderPass;");
45845
45828
 
45846
45829
  src.push("in vec3 position;");
45847
- src.push("in vec3 normal;");
45848
45830
  src.push("in vec4 color;");
45849
45831
  src.push("in vec2 uv;");
45850
45832
  src.push("in vec4 flags;");
@@ -45855,11 +45837,9 @@ class TrianglesBatchingColorTextureRenderer {
45855
45837
  }
45856
45838
 
45857
45839
  src.push("uniform mat4 worldMatrix;");
45858
- src.push("uniform mat4 worldNormalMatrix;");
45859
45840
 
45860
45841
  src.push("uniform mat4 viewMatrix;");
45861
45842
  src.push("uniform mat4 projMatrix;");
45862
- src.push("uniform mat4 viewNormalMatrix;");
45863
45843
  src.push("uniform mat4 positionsDecodeMatrix;");
45864
45844
  src.push("uniform mat3 uvDecodeMatrix;");
45865
45845
 
@@ -45872,38 +45852,11 @@ class TrianglesBatchingColorTextureRenderer {
45872
45852
  src.push("out float isPerspective;");
45873
45853
  }
45874
45854
 
45875
- src.push("uniform vec4 lightAmbient;");
45876
-
45877
- for (let i = 0, len = lightsState.lights.length; i < len; i++) {
45878
- light = lightsState.lights[i];
45879
- if (light.type === "ambient") {
45880
- continue;
45881
- }
45882
- src.push("uniform vec4 lightColor" + i + ";");
45883
- if (light.type === "dir") {
45884
- src.push("uniform vec3 lightDir" + i + ";");
45885
- }
45886
- if (light.type === "point") {
45887
- src.push("uniform vec3 lightPos" + i + ";");
45888
- }
45889
- if (light.type === "spot") {
45890
- src.push("uniform vec3 lightPos" + i + ";");
45891
- src.push("uniform vec3 lightDir" + i + ";");
45892
- }
45893
- }
45894
-
45895
- src.push("vec3 octDecode(vec2 oct) {");
45896
- src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));");
45897
- src.push(" if (v.z < 0.0) {");
45898
- src.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");
45899
- src.push(" }");
45900
- src.push(" return normalize(v);");
45901
- src.push("}");
45902
-
45903
45855
  if (clipping) {
45904
45856
  src.push("out vec4 vWorldPosition;");
45905
45857
  src.push("out vec4 vFlags2;");
45906
45858
  }
45859
+ src.push("out vec4 vViewPosition;");
45907
45860
  src.push("out vec4 vColor;");
45908
45861
  src.push("out vec2 vUV;");
45909
45862
 
@@ -45922,45 +45875,8 @@ class TrianglesBatchingColorTextureRenderer {
45922
45875
  src.push("worldPosition.xyz = worldPosition.xyz + offset;");
45923
45876
  }
45924
45877
  src.push("vec4 viewPosition = viewMatrix * worldPosition; ");
45925
- src.push("vec4 worldNormal = worldNormalMatrix * vec4(octDecode(normal.xy), 0.0); ");
45926
- src.push("vec3 viewNormal = normalize((viewNormalMatrix * worldNormal).xyz);");
45927
-
45928
- src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");
45929
- src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");
45930
-
45931
- src.push("float lambertian = 1.0;");
45932
- for (let i = 0, len = lightsState.lights.length; i < len; i++) {
45933
- light = lightsState.lights[i];
45934
- if (light.type === "ambient") {
45935
- continue;
45936
- }
45937
- if (light.type === "dir") {
45938
- if (light.space === "view") {
45939
- src.push("viewLightDir = normalize(lightDir" + i + ");");
45940
- } else {
45941
- src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
45942
- }
45943
- } else if (light.type === "point") {
45944
- if (light.space === "view") {
45945
- src.push("viewLightDir = -normalize(lightPos" + i + " - viewPosition.xyz);");
45946
- } else {
45947
- src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos" + i + ", 0.0)).xyz);");
45948
- }
45949
- } else if (light.type === "spot") {
45950
- if (light.space === "view") {
45951
- src.push("viewLightDir = normalize(lightDir" + i + ");");
45952
- } else {
45953
- src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
45954
- }
45955
- } else {
45956
- continue;
45957
- }
45958
- src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");
45959
- src.push("reflectedColor += lambertian * (lightColor" + i + ".rgb * lightColor" + i + ".a);");
45960
- }
45961
-
45962
- src.push("vec3 rgb = (vec3(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0));");
45963
- src.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);");
45878
+ src.push("vViewPosition = viewPosition;");
45879
+ src.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);");
45964
45880
  src.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;");
45965
45881
 
45966
45882
  src.push("vec4 clipPos = projMatrix * viewPosition;");
@@ -45980,6 +45896,7 @@ class TrianglesBatchingColorTextureRenderer {
45980
45896
 
45981
45897
  _buildFragmentShader() {
45982
45898
  const scene = this._scene;
45899
+ const lightsState = scene._lightsState;
45983
45900
  const sectionPlanesState = scene._sectionPlanesState;
45984
45901
  const clipping = sectionPlanesState.sectionPlanes.length > 0;
45985
45902
  const src = [];
@@ -45999,9 +45916,7 @@ class TrianglesBatchingColorTextureRenderer {
45999
45916
  src.push("uniform float logDepthBufFC;");
46000
45917
  src.push("in float vFragDepth;");
46001
45918
  }
46002
-
46003
45919
  src.push("uniform sampler2D uColorMap;");
46004
-
46005
45920
  if (this._withSAO) {
46006
45921
  src.push("uniform sampler2D uOcclusionTexture;");
46007
45922
  src.push("uniform vec4 uSAOParams;");
@@ -46015,7 +45930,6 @@ class TrianglesBatchingColorTextureRenderer {
46015
45930
  src.push(" return dot( v, unPackFactors );");
46016
45931
  src.push("}");
46017
45932
  }
46018
-
46019
45933
  if (clipping) {
46020
45934
  src.push("in vec4 vWorldPosition;");
46021
45935
  src.push("in vec4 vFlags2;");
@@ -46025,7 +45939,27 @@ class TrianglesBatchingColorTextureRenderer {
46025
45939
  src.push("uniform vec3 sectionPlaneDir" + i + ";");
46026
45940
  }
46027
45941
  }
45942
+ src.push("uniform mat4 viewMatrix;");
45943
+ src.push("uniform vec4 lightAmbient;");
45944
+ for (let i = 0, len = lightsState.lights.length; i < len; i++) {
45945
+ const light = lightsState.lights[i];
45946
+ if (light.type === "ambient") {
45947
+ continue;
45948
+ }
45949
+ src.push("uniform vec4 lightColor" + i + ";");
45950
+ if (light.type === "dir") {
45951
+ src.push("uniform vec3 lightDir" + i + ";");
45952
+ }
45953
+ if (light.type === "point") {
45954
+ src.push("uniform vec3 lightPos" + i + ";");
45955
+ }
45956
+ if (light.type === "spot") {
45957
+ src.push("uniform vec3 lightPos" + i + ";");
45958
+ src.push("uniform vec3 lightDir" + i + ";");
45959
+ }
45960
+ }
46028
45961
 
45962
+ src.push("in vec4 vViewPosition;");
46029
45963
  src.push("in vec4 vColor;");
46030
45964
  src.push("in vec2 vUV;");
46031
45965
  src.push("out vec4 outColor;");
@@ -46047,12 +45981,49 @@ class TrianglesBatchingColorTextureRenderer {
46047
45981
  src.push("}");
46048
45982
  }
46049
45983
 
46050
- if (scene.logarithmicDepthBufferEnabled) {
46051
- src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
45984
+ src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");
45985
+ src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");
45986
+
45987
+ src.push("float lambertian = 1.0;");
45988
+
45989
+ src.push("vec3 xTangent = dFdx( vViewPosition.xyz );");
45990
+ src.push("vec3 yTangent = dFdy( vViewPosition.xyz );");
45991
+ src.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");
45992
+
45993
+ for (let i = 0, len = lightsState.lights.length; i < len; i++) {
45994
+ const light = lightsState.lights[i];
45995
+ if (light.type === "ambient") {
45996
+ continue;
45997
+ }
45998
+ if (light.type === "dir") {
45999
+ if (light.space === "view") {
46000
+ src.push("viewLightDir = normalize(lightDir" + i + ");");
46001
+ } else {
46002
+ src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
46003
+ }
46004
+ } else if (light.type === "point") {
46005
+ if (light.space === "view") {
46006
+ src.push("viewLightDir = -normalize(lightPos" + i + " - viewPosition.xyz);");
46007
+ } else {
46008
+ src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos" + i + ", 0.0)).xyz);");
46009
+ }
46010
+ } else if (light.type === "spot") {
46011
+ if (light.space === "view") {
46012
+ src.push("viewLightDir = normalize(lightDir" + i + ");");
46013
+ } else {
46014
+ src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
46015
+ }
46016
+ } else {
46017
+ continue;
46018
+ }
46019
+
46020
+ src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");
46021
+ src.push("reflectedColor += lambertian * (lightColor" + i + ".rgb * lightColor" + i + ".a);");
46052
46022
  }
46053
46023
 
46054
- src.push("vec4 colorTexel = vColor * texture(uColorMap, vUV);");
46055
- src.push("float opacity = vColor.a;");
46024
+ src.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);");
46025
+ src.push("vec4 colorTexel = color * texture(uColorMap, vUV);");
46026
+ src.push("float opacity = color.a;");
46056
46027
 
46057
46028
  if (this._withSAO) {
46058
46029
  // Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
@@ -46069,6 +46040,10 @@ class TrianglesBatchingColorTextureRenderer {
46069
46040
  src.push(" outColor = vec4(colorTexel.rgb, opacity);");
46070
46041
  }
46071
46042
 
46043
+ if (scene.logarithmicDepthBufferEnabled) {
46044
+ src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
46045
+ }
46046
+
46072
46047
  src.push("}");
46073
46048
  return src;
46074
46049
  }
@@ -46455,6 +46430,11 @@ function quantizePositions(positions, aabb, positionsDecodeMatrix) { // http://c
46455
46430
  */
46456
46431
  function transformAndOctEncodeNormals(worldNormalMatrix, normals, lenNormals, compressedNormals, lenCompressedNormals) {
46457
46432
  // http://jcgt.org/published/0003/02/01/
46433
+
46434
+ function dot(array, vec3) {
46435
+ return array[0] * vec3[0] + array[1] * vec3[1] + array[2] * vec3[2];
46436
+ }
46437
+
46458
46438
  let oct, dec, best, currentCos, bestCos;
46459
46439
  let i;
46460
46440
  let localNormal = new Float32Array([0, 0, 0, 0]);
@@ -46506,29 +46486,29 @@ function transformAndOctEncodeNormals(worldNormalMatrix, normals, lenNormals, co
46506
46486
  function octEncodeNormals(normals) { // http://jcgt.org/published/0003/02/01/
46507
46487
  const lenNormals = normals.length;
46508
46488
  const compressedNormals = new Int8Array(lenNormals);
46509
- let oct, best, currentCos, bestCos;
46489
+ let oct, dec, best, currentCos, bestCos;
46510
46490
  for (let i = 0; i < lenNormals; i += 3) {
46511
46491
  // Test various combinations of ceil and floor to minimize rounding errors
46512
46492
  best = oct = octEncodeNormal(normals, i, "floor", "floor");
46513
- octDecodeVec2(oct);
46514
- currentCos = bestCos = dot(normals, i);
46493
+ dec = octDecodeVec2(oct);
46494
+ currentCos = bestCos = dot(normals, i, dec);
46515
46495
  oct = octEncodeNormal(normals, i, "ceil", "floor");
46516
- octDecodeVec2(oct);
46517
- currentCos = dot(normals, i);
46496
+ dec = octDecodeVec2(oct);
46497
+ currentCos = dot(normals, i, dec);
46518
46498
  if (currentCos > bestCos) {
46519
46499
  best = oct;
46520
46500
  bestCos = currentCos;
46521
46501
  }
46522
46502
  oct = octEncodeNormal(normals, i, "floor", "ceil");
46523
- octDecodeVec2(oct);
46524
- currentCos = dot(normals, i);
46503
+ dec = octDecodeVec2(oct);
46504
+ currentCos = dot(normals, i, dec);
46525
46505
  if (currentCos > bestCos) {
46526
46506
  best = oct;
46527
46507
  bestCos = currentCos;
46528
46508
  }
46529
46509
  oct = octEncodeNormal(normals, i, "ceil", "ceil");
46530
- octDecodeVec2(oct);
46531
- currentCos = dot(normals, i);
46510
+ dec = octDecodeVec2(oct);
46511
+ currentCos = dot(normals, i, dec);
46532
46512
  if (currentCos > bestCos) {
46533
46513
  best = oct;
46534
46514
  bestCos = currentCos;
@@ -46602,8 +46582,8 @@ function octDecodeVec2(oct) { // Decode an oct-encoded normal
46602
46582
  /**
46603
46583
  * @private
46604
46584
  */
46605
- function dot(p, vec3) { // Dot product of a normal in an array against a candidate decoding
46606
- return p[0] * vec3[0] + p[1] * vec3[1] + p[2] * vec3[2];
46585
+ function dot(array, i, vec3) {
46586
+ return array[i] * vec3[0] + array[i + 1] * vec3[1] + array[i + 2] * vec3[2];
46607
46587
  }
46608
46588
 
46609
46589
  const tempMat4$2 = math.mat4();
@@ -47132,7 +47112,6 @@ class TrianglesBatchingLayer {
47132
47112
 
47133
47113
  this._state.colorTextureSupported
47134
47114
  = !!state.uvBuf
47135
- && !!state.normalsBuf
47136
47115
  && !!state.textureSet
47137
47116
  && !!state.textureSet.colorTexture;
47138
47117
 
@@ -48875,8 +48854,8 @@ class TrianglesInstancingFlatColorRenderer {
48875
48854
 
48876
48855
  src.push("in vec4 vViewPosition;");
48877
48856
  src.push("in vec4 vColor;");
48878
-
48879
48857
  src.push("out vec4 outColor;");
48858
+
48880
48859
  src.push("void main(void) {");
48881
48860
 
48882
48861
  if (clipping) {
@@ -53549,10 +53528,7 @@ class TrianglesInstancingColorTextureRenderer {
53549
53528
  gl.uniform1i(this._uRenderPass, renderPass);
53550
53529
 
53551
53530
  gl.uniformMatrix4fv(this._uViewMatrix, false, (origin) ? createRTCViewMat(camera.viewMatrix, origin) : camera.viewMatrix);
53552
- gl.uniformMatrix4fv(this._uViewNormalMatrix, false, camera.viewNormalMatrix);
53553
-
53554
53531
  gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix);
53555
- gl.uniformMatrix4fv(this._uWorldNormalMatrix, false, model.worldNormalMatrix);
53556
53532
 
53557
53533
  const numSectionPlanes = scene._sectionPlanesState.sectionPlanes.length;
53558
53534
  if (numSectionPlanes > 0) {
@@ -53592,16 +53568,7 @@ class TrianglesInstancingColorTextureRenderer {
53592
53568
  gl.vertexAttribDivisor(this._aModelMatrixCol1.location, 1);
53593
53569
  gl.vertexAttribDivisor(this._aModelMatrixCol2.location, 1);
53594
53570
 
53595
- this._aModelNormalMatrixCol0.bindArrayBuffer(state.modelNormalMatrixCol0Buf);
53596
- this._aModelNormalMatrixCol1.bindArrayBuffer(state.modelNormalMatrixCol1Buf);
53597
- this._aModelNormalMatrixCol2.bindArrayBuffer(state.modelNormalMatrixCol2Buf);
53598
-
53599
- gl.vertexAttribDivisor(this._aModelNormalMatrixCol0.location, 1);
53600
- gl.vertexAttribDivisor(this._aModelNormalMatrixCol1.location, 1);
53601
- gl.vertexAttribDivisor(this._aModelNormalMatrixCol2.location, 1);
53602
-
53603
53571
  this._aPosition.bindArrayBuffer(geometry.positionsBuf);
53604
- this._aNormal.bindArrayBuffer(geometry.normalsBuf);
53605
53572
  this._aUV.bindArrayBuffer(geometry.uvBuf);
53606
53573
 
53607
53574
  this._aColor.bindArrayBuffer(state.colorsBuf);
@@ -53629,9 +53596,6 @@ class TrianglesInstancingColorTextureRenderer {
53629
53596
  gl.vertexAttribDivisor(this._aModelMatrixCol0.location, 0);
53630
53597
  gl.vertexAttribDivisor(this._aModelMatrixCol1.location, 0);
53631
53598
  gl.vertexAttribDivisor(this._aModelMatrixCol2.location, 0);
53632
- gl.vertexAttribDivisor(this._aModelNormalMatrixCol0.location, 0);
53633
- gl.vertexAttribDivisor(this._aModelNormalMatrixCol1.location, 0);
53634
- gl.vertexAttribDivisor(this._aModelNormalMatrixCol2.location, 0);
53635
53599
  gl.vertexAttribDivisor(this._aColor.location, 0);
53636
53600
  gl.vertexAttribDivisor(this._aFlags.location, 0);
53637
53601
 
@@ -53687,10 +53651,8 @@ class TrianglesInstancingColorTextureRenderer {
53687
53651
  this._uUVDecodeMatrix = program.getLocation("uvDecodeMatrix");
53688
53652
 
53689
53653
  this._uWorldMatrix = program.getLocation("worldMatrix");
53690
- this._uWorldNormalMatrix = program.getLocation("worldNormalMatrix");
53691
53654
 
53692
53655
  this._uViewMatrix = program.getLocation("viewMatrix");
53693
- this._uViewNormalMatrix = program.getLocation("viewNormalMatrix");
53694
53656
  this._uProjMatrix = program.getLocation("projMatrix");
53695
53657
 
53696
53658
  this._uLightAmbient = program.getLocation("lightAmbient");
@@ -53736,7 +53698,6 @@ class TrianglesInstancingColorTextureRenderer {
53736
53698
  }
53737
53699
 
53738
53700
  this._aPosition = program.getAttribute("position");
53739
- this._aNormal = program.getAttribute("normal");
53740
53701
  this._aColor = program.getAttribute("color");
53741
53702
  this._aUV = program.getAttribute("uv");
53742
53703
  this._aFlags = program.getAttribute("flags");
@@ -53747,10 +53708,6 @@ class TrianglesInstancingColorTextureRenderer {
53747
53708
  this._aModelMatrixCol1 = program.getAttribute("modelMatrixCol1");
53748
53709
  this._aModelMatrixCol2 = program.getAttribute("modelMatrixCol2");
53749
53710
 
53750
- this._aModelNormalMatrixCol0 = program.getAttribute("modelNormalMatrixCol0");
53751
- this._aModelNormalMatrixCol1 = program.getAttribute("modelNormalMatrixCol1");
53752
- this._aModelNormalMatrixCol2 = program.getAttribute("modelNormalMatrixCol2");
53753
-
53754
53711
  this._uColorMap = "uColorMap";
53755
53712
 
53756
53713
  this._uOcclusionTexture = "uOcclusionTexture";
@@ -53809,11 +53766,7 @@ class TrianglesInstancingColorTextureRenderer {
53809
53766
  _buildVertexShader() {
53810
53767
  const scene = this._scene;
53811
53768
  const sectionPlanesState = scene._sectionPlanesState;
53812
- const lightsState = scene._lightsState;
53813
53769
  const clipping = sectionPlanesState.sectionPlanes.length > 0;
53814
- let i;
53815
- let len;
53816
- let light;
53817
53770
  const src = [];
53818
53771
  src.push("#version 300 es");
53819
53772
  src.push("// Instancing geometry drawing vertex shader");
@@ -53821,7 +53774,6 @@ class TrianglesInstancingColorTextureRenderer {
53821
53774
  src.push("uniform int renderPass;");
53822
53775
 
53823
53776
  src.push("in vec3 position;");
53824
- src.push("in vec3 normal;");
53825
53777
  src.push("in vec4 color;");
53826
53778
  src.push("in vec2 uv;");
53827
53779
  src.push("in vec4 flags;");
@@ -53835,14 +53787,8 @@ class TrianglesInstancingColorTextureRenderer {
53835
53787
  src.push("in vec4 modelMatrixCol1;");
53836
53788
  src.push("in vec4 modelMatrixCol2;");
53837
53789
 
53838
- src.push("in vec4 modelNormalMatrixCol0;");
53839
- src.push("in vec4 modelNormalMatrixCol1;");
53840
- src.push("in vec4 modelNormalMatrixCol2;");
53841
-
53842
53790
  src.push("uniform mat4 worldMatrix;");
53843
- src.push("uniform mat4 worldNormalMatrix;");
53844
53791
  src.push("uniform mat4 viewMatrix;");
53845
- src.push("uniform mat4 viewNormalMatrix;");
53846
53792
  src.push("uniform mat4 projMatrix;");
53847
53793
  src.push("uniform mat4 positionsDecodeMatrix;");
53848
53794
  src.push("uniform mat3 uvDecodeMatrix;");
@@ -53856,38 +53802,11 @@ class TrianglesInstancingColorTextureRenderer {
53856
53802
  src.push("out float isPerspective;");
53857
53803
  }
53858
53804
 
53859
- src.push("uniform vec4 lightAmbient;");
53860
-
53861
- for (i = 0, len = lightsState.lights.length; i < len; i++) {
53862
- light = lightsState.lights[i];
53863
- if (light.type === "ambient") {
53864
- continue;
53865
- }
53866
- src.push("uniform vec4 lightColor" + i + ";");
53867
- if (light.type === "dir") {
53868
- src.push("uniform vec3 lightDir" + i + ";");
53869
- }
53870
- if (light.type === "point") {
53871
- src.push("uniform vec3 lightPos" + i + ";");
53872
- }
53873
- if (light.type === "spot") {
53874
- src.push("uniform vec3 lightPos" + i + ";");
53875
- src.push("uniform vec3 lightDir" + i + ";");
53876
- }
53877
- }
53878
-
53879
- src.push("vec3 octDecode(vec2 oct) {");
53880
- src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));");
53881
- src.push(" if (v.z < 0.0) {");
53882
- src.push(" v.xy = (1.0 - abs(v.yx)) * vec2(v.x >= 0.0 ? 1.0 : -1.0, v.y >= 0.0 ? 1.0 : -1.0);");
53883
- src.push(" }");
53884
- src.push(" return normalize(v);");
53885
- src.push("}");
53886
-
53887
53805
  if (clipping) {
53888
53806
  src.push("out vec4 vWorldPosition;");
53889
53807
  src.push("out vec4 vFlags2;");
53890
53808
  }
53809
+ src.push("out vec4 vViewPosition;");
53891
53810
  src.push("out vec4 vColor;");
53892
53811
  src.push("out vec2 vUV;");
53893
53812
 
@@ -53908,47 +53827,8 @@ class TrianglesInstancingColorTextureRenderer {
53908
53827
  }
53909
53828
 
53910
53829
  src.push("vec4 viewPosition = viewMatrix * worldPosition; ");
53911
-
53912
- src.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); ");
53913
- src.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);");
53914
- src.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);");
53915
-
53916
- src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");
53917
- src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");
53918
-
53919
- src.push("float lambertian = 1.0;");
53920
- for (i = 0, len = lightsState.lights.length; i < len; i++) {
53921
- light = lightsState.lights[i];
53922
- if (light.type === "ambient") {
53923
- continue;
53924
- }
53925
- if (light.type === "dir") {
53926
- if (light.space === "view") {
53927
- src.push("viewLightDir = normalize(lightDir" + i + ");");
53928
- } else {
53929
- src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
53930
- }
53931
- } else if (light.type === "point") {
53932
- if (light.space === "view") {
53933
- src.push("viewLightDir = -normalize(lightPos" + i + " - viewPosition.xyz);");
53934
- } else {
53935
- src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos" + i + ", 0.0)).xyz);");
53936
- }
53937
- } else if (light.type === "spot") {
53938
- if (light.space === "view") {
53939
- src.push("viewLightDir = normalize(lightDir" + i + ");");
53940
- } else {
53941
- src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
53942
- }
53943
- } else {
53944
- continue;
53945
- }
53946
- src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");
53947
- src.push("reflectedColor += lambertian * (lightColor" + i + ".rgb * lightColor" + i + ".a);");
53948
- }
53949
-
53950
- src.push("vec3 rgb = (vec3(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0));");
53951
- src.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);");
53830
+ src.push("vViewPosition = viewPosition;");
53831
+ src.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);");
53952
53832
  src.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;");
53953
53833
 
53954
53834
  src.push("vec4 clipPos = projMatrix * viewPosition;");
@@ -53971,6 +53851,9 @@ class TrianglesInstancingColorTextureRenderer {
53971
53851
  _buildFragmentShader() {
53972
53852
  const scene = this._scene;
53973
53853
  const sectionPlanesState = scene._sectionPlanesState;
53854
+ const lightsState = scene._lightsState;
53855
+ let i;
53856
+ let len;
53974
53857
  const clipping = sectionPlanesState.sectionPlanes.length > 0;
53975
53858
  const src = [];
53976
53859
  src.push("#version 300 es");
@@ -54012,9 +53895,31 @@ class TrianglesInstancingColorTextureRenderer {
54012
53895
  src.push("uniform vec3 sectionPlaneDir" + i + ";");
54013
53896
  }
54014
53897
  }
53898
+ src.push("uniform mat4 viewMatrix;");
53899
+ src.push("uniform vec4 lightAmbient;");
53900
+ for (i = 0, len = lightsState.lights.length; i < len; i++) {
53901
+ const light = lightsState.lights[i];
53902
+ if (light.type === "ambient") {
53903
+ continue;
53904
+ }
53905
+ src.push("uniform vec4 lightColor" + i + ";");
53906
+ if (light.type === "dir") {
53907
+ src.push("uniform vec3 lightDir" + i + ";");
53908
+ }
53909
+ if (light.type === "point") {
53910
+ src.push("uniform vec3 lightPos" + i + ";");
53911
+ }
53912
+ if (light.type === "spot") {
53913
+ src.push("uniform vec3 lightPos" + i + ";");
53914
+ src.push("uniform vec3 lightDir" + i + ";");
53915
+ }
53916
+ }
53917
+
53918
+ src.push("in vec4 vViewPosition;");
54015
53919
  src.push("in vec4 vColor;");
54016
53920
  src.push("in vec2 vUV;");
54017
53921
  src.push("out vec4 outColor;");
53922
+
54018
53923
  src.push("void main(void) {");
54019
53924
 
54020
53925
  if (clipping) {
@@ -54032,17 +53937,52 @@ class TrianglesInstancingColorTextureRenderer {
54032
53937
  src.push("}");
54033
53938
  }
54034
53939
 
54035
- if (scene.logarithmicDepthBufferEnabled) {
54036
- src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
54037
- }
53940
+ src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");
53941
+ src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");
54038
53942
 
54039
- src.push("vec4 colorTexel = texture(uColorMap, vUV);");
54040
- src.push("float opacity = vColor.a;");
53943
+ src.push("float lambertian = 1.0;");
54041
53944
 
54042
- // Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
54043
- // Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
53945
+ src.push("vec3 xTangent = dFdx( vViewPosition.xyz );");
53946
+ src.push("vec3 yTangent = dFdy( vViewPosition.xyz );");
53947
+ src.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");
53948
+
53949
+ for (i = 0, len = lightsState.lights.length; i < len; i++) {
53950
+ const light = lightsState.lights[i];
53951
+ if (light.type === "ambient") {
53952
+ continue;
53953
+ }
53954
+ if (light.type === "dir") {
53955
+ if (light.space === "view") {
53956
+ src.push("viewLightDir = normalize(lightDir" + i + ");");
53957
+ } else {
53958
+ src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
53959
+ }
53960
+ } else if (light.type === "point") {
53961
+ if (light.space === "view") {
53962
+ src.push("viewLightDir = -normalize(lightPos" + i + " - viewPosition.xyz);");
53963
+ } else {
53964
+ src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos" + i + ", 0.0)).xyz);");
53965
+ }
53966
+ } else if (light.type === "spot") {
53967
+ if (light.space === "view") {
53968
+ src.push("viewLightDir = normalize(lightDir" + i + ");");
53969
+ } else {
53970
+ src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
53971
+ }
53972
+ } else {
53973
+ continue;
53974
+ }
53975
+ src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");
53976
+ src.push("reflectedColor += lambertian * (lightColor" + i + ".rgb * lightColor" + i + ".a);");
53977
+ }
53978
+
53979
+ src.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);");
53980
+ src.push("vec4 colorTexel = color * texture(uColorMap, vUV);");
53981
+ src.push("float opacity = color.a;");
54044
53982
 
54045
53983
  if (this._withSAO) {
53984
+ // Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
53985
+ // Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
54046
53986
  src.push(" float viewportWidth = uSAOParams[0];");
54047
53987
  src.push(" float viewportHeight = uSAOParams[1];");
54048
53988
  src.push(" float blendCutoff = uSAOParams[2];");
@@ -54053,6 +53993,11 @@ class TrianglesInstancingColorTextureRenderer {
54053
53993
  } else {
54054
53994
  src.push(" outColor = vec4(vColor.rgb * colorTexel.rgb, opacity);");
54055
53995
  }
53996
+
53997
+ if (scene.logarithmicDepthBufferEnabled) {
53998
+ src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
53999
+ }
54000
+
54056
54001
  src.push("}");
54057
54002
  return src;
54058
54003
  }
@@ -54708,7 +54653,6 @@ class TrianglesInstancingLayer {
54708
54653
 
54709
54654
  this._state.colorTextureSupported
54710
54655
  = !!geometry.uvBuf
54711
- && !!geometry.normalsBuf
54712
54656
  && !!textureSet
54713
54657
  && !!textureSet.colorTexture;
54714
54658