@xeokit/xeokit-sdk 2.3.0-beta-14 → 2.3.0-beta-17

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.
@@ -14609,7 +14609,8 @@ class SAODepthLimitedBlurRenderer {
14609
14609
  }
14610
14610
 
14611
14611
  outColor = packFloatToRGBA(occlusionSum / weightSum);
14612
- }`]
14612
+ }`
14613
+ ]
14613
14614
  });
14614
14615
 
14615
14616
  if (this._program.errors) {
@@ -14699,7 +14700,7 @@ class SAODepthLimitedBlurRenderer {
14699
14700
 
14700
14701
  gl.uniform1fv(this._uSampleWeights, sampleWeights);
14701
14702
 
14702
- const depthTexture = depthRenderBuffer.getDepthTexture();
14703
+ const depthTexture = depthRenderBuffer.getDepthTexture();
14703
14704
  const occlusionTexture = occlusionRenderBuffer.getTexture();
14704
14705
 
14705
14706
  program.bindTexture(this._uDepthTexture, depthTexture, 0); // TODO: use FrameCtx.textureUnit
@@ -15999,22 +16000,6 @@ const Renderer = function (scene, options) {
15999
16000
  gl.depthMask(false);
16000
16001
  }
16001
16002
 
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
16003
  // Transparent color edges
16019
16004
 
16020
16005
  if (normalFillTransparentBinLen > 0 || normalEdgesTransparentBinLen > 0) {
@@ -16035,6 +16020,23 @@ const Renderer = function (scene, options) {
16035
16020
  drawable.drawColorTransparent(frameCtx);
16036
16021
  }
16037
16022
  }
16023
+
16024
+ // Transparent X-ray edges
16025
+
16026
+ if (xrayEdgesTransparentBinLen > 0) {
16027
+ for (i = 0; i < xrayEdgesTransparentBinLen; i++) {
16028
+ xrayEdgesTransparentBin[i].drawEdgesXRayed(frameCtx);
16029
+ }
16030
+ }
16031
+
16032
+ // Transparent X-ray fill
16033
+
16034
+ if (xrayedFillTransparentBinLen > 0) {
16035
+ for (i = 0; i < xrayedFillTransparentBinLen; i++) {
16036
+ xrayedFillTransparentBin[i].drawSilhouetteXRayed(frameCtx);
16037
+ }
16038
+ }
16039
+
16038
16040
  gl.disable(gl.BLEND);
16039
16041
  if (!alphaDepthMask) {
16040
16042
  gl.depthMask(true);
@@ -45607,10 +45609,7 @@ class TrianglesBatchingColorTextureRenderer {
45607
45609
  gl.uniform1i(this._uRenderPass, renderPass);
45608
45610
 
45609
45611
  gl.uniformMatrix4fv(this._uViewMatrix, false, (origin) ? createRTCViewMat(camera.viewMatrix, origin) : camera.viewMatrix);
45610
- gl.uniformMatrix4fv(this._uViewNormalMatrix, false, camera.viewNormalMatrix);
45611
-
45612
45612
  gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix);
45613
- gl.uniformMatrix4fv(this._uWorldNormalMatrix, false, model.worldNormalMatrix);
45614
45613
 
45615
45614
  const numSectionPlanes = scene._sectionPlanesState.sectionPlanes.length;
45616
45615
  if (numSectionPlanes > 0) {
@@ -45644,10 +45643,6 @@ class TrianglesBatchingColorTextureRenderer {
45644
45643
 
45645
45644
  this._aPosition.bindArrayBuffer(state.positionsBuf);
45646
45645
 
45647
- if (this._aNormal) {
45648
- this._aNormal.bindArrayBuffer(state.normalsBuf);
45649
- }
45650
-
45651
45646
  if (this._aUV) {
45652
45647
  this._aUV.bindArrayBuffer(state.uvBuf);
45653
45648
  }
@@ -45718,9 +45713,7 @@ class TrianglesBatchingColorTextureRenderer {
45718
45713
  this._uPositionsDecodeMatrix = program.getLocation("positionsDecodeMatrix");
45719
45714
  this._uUVDecodeMatrix = program.getLocation("uvDecodeMatrix");
45720
45715
  this._uWorldMatrix = program.getLocation("worldMatrix");
45721
- this._uWorldNormalMatrix = program.getLocation("worldNormalMatrix");
45722
45716
  this._uViewMatrix = program.getLocation("viewMatrix");
45723
- this._uViewNormalMatrix = program.getLocation("viewNormalMatrix");
45724
45717
  this._uProjMatrix = program.getLocation("projMatrix");
45725
45718
 
45726
45719
  this._uLightAmbient = program.getLocation("lightAmbient");
@@ -45767,7 +45760,6 @@ class TrianglesBatchingColorTextureRenderer {
45767
45760
 
45768
45761
  this._aPosition = program.getAttribute("position");
45769
45762
  this._aOffset = program.getAttribute("offset");
45770
- this._aNormal = program.getAttribute("normal");
45771
45763
  this._aUV = program.getAttribute("uv");
45772
45764
  this._aColor = program.getAttribute("color");
45773
45765
  this._aFlags = program.getAttribute("flags");
@@ -45834,9 +45826,7 @@ class TrianglesBatchingColorTextureRenderer {
45834
45826
 
45835
45827
  const scene = this._scene;
45836
45828
  const sectionPlanesState = scene._sectionPlanesState;
45837
- const lightsState = scene._lightsState;
45838
45829
  const clipping = sectionPlanesState.sectionPlanes.length > 0;
45839
- let light;
45840
45830
  const src = [];
45841
45831
  src.push("#version 300 es");
45842
45832
  src.push("// Triangles batching color texture vertex shader");
@@ -45844,7 +45834,6 @@ class TrianglesBatchingColorTextureRenderer {
45844
45834
  src.push("uniform int renderPass;");
45845
45835
 
45846
45836
  src.push("in vec3 position;");
45847
- src.push("in vec3 normal;");
45848
45837
  src.push("in vec4 color;");
45849
45838
  src.push("in vec2 uv;");
45850
45839
  src.push("in vec4 flags;");
@@ -45855,11 +45844,9 @@ class TrianglesBatchingColorTextureRenderer {
45855
45844
  }
45856
45845
 
45857
45846
  src.push("uniform mat4 worldMatrix;");
45858
- src.push("uniform mat4 worldNormalMatrix;");
45859
45847
 
45860
45848
  src.push("uniform mat4 viewMatrix;");
45861
45849
  src.push("uniform mat4 projMatrix;");
45862
- src.push("uniform mat4 viewNormalMatrix;");
45863
45850
  src.push("uniform mat4 positionsDecodeMatrix;");
45864
45851
  src.push("uniform mat3 uvDecodeMatrix;");
45865
45852
 
@@ -45872,38 +45859,11 @@ class TrianglesBatchingColorTextureRenderer {
45872
45859
  src.push("out float isPerspective;");
45873
45860
  }
45874
45861
 
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
45862
  if (clipping) {
45904
45863
  src.push("out vec4 vWorldPosition;");
45905
45864
  src.push("out vec4 vFlags2;");
45906
45865
  }
45866
+ src.push("out vec4 vViewPosition;");
45907
45867
  src.push("out vec4 vColor;");
45908
45868
  src.push("out vec2 vUV;");
45909
45869
 
@@ -45922,45 +45882,8 @@ class TrianglesBatchingColorTextureRenderer {
45922
45882
  src.push("worldPosition.xyz = worldPosition.xyz + offset;");
45923
45883
  }
45924
45884
  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);");
45885
+ src.push("vViewPosition = viewPosition;");
45886
+ 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
45887
  src.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;");
45965
45888
 
45966
45889
  src.push("vec4 clipPos = projMatrix * viewPosition;");
@@ -45980,6 +45903,7 @@ class TrianglesBatchingColorTextureRenderer {
45980
45903
 
45981
45904
  _buildFragmentShader() {
45982
45905
  const scene = this._scene;
45906
+ const lightsState = scene._lightsState;
45983
45907
  const sectionPlanesState = scene._sectionPlanesState;
45984
45908
  const clipping = sectionPlanesState.sectionPlanes.length > 0;
45985
45909
  const src = [];
@@ -45999,9 +45923,7 @@ class TrianglesBatchingColorTextureRenderer {
45999
45923
  src.push("uniform float logDepthBufFC;");
46000
45924
  src.push("in float vFragDepth;");
46001
45925
  }
46002
-
46003
45926
  src.push("uniform sampler2D uColorMap;");
46004
-
46005
45927
  if (this._withSAO) {
46006
45928
  src.push("uniform sampler2D uOcclusionTexture;");
46007
45929
  src.push("uniform vec4 uSAOParams;");
@@ -46015,7 +45937,6 @@ class TrianglesBatchingColorTextureRenderer {
46015
45937
  src.push(" return dot( v, unPackFactors );");
46016
45938
  src.push("}");
46017
45939
  }
46018
-
46019
45940
  if (clipping) {
46020
45941
  src.push("in vec4 vWorldPosition;");
46021
45942
  src.push("in vec4 vFlags2;");
@@ -46025,7 +45946,27 @@ class TrianglesBatchingColorTextureRenderer {
46025
45946
  src.push("uniform vec3 sectionPlaneDir" + i + ";");
46026
45947
  }
46027
45948
  }
45949
+ src.push("uniform mat4 viewMatrix;");
45950
+ src.push("uniform vec4 lightAmbient;");
45951
+ for (let i = 0, len = lightsState.lights.length; i < len; i++) {
45952
+ const light = lightsState.lights[i];
45953
+ if (light.type === "ambient") {
45954
+ continue;
45955
+ }
45956
+ src.push("uniform vec4 lightColor" + i + ";");
45957
+ if (light.type === "dir") {
45958
+ src.push("uniform vec3 lightDir" + i + ";");
45959
+ }
45960
+ if (light.type === "point") {
45961
+ src.push("uniform vec3 lightPos" + i + ";");
45962
+ }
45963
+ if (light.type === "spot") {
45964
+ src.push("uniform vec3 lightPos" + i + ";");
45965
+ src.push("uniform vec3 lightDir" + i + ";");
45966
+ }
45967
+ }
46028
45968
 
45969
+ src.push("in vec4 vViewPosition;");
46029
45970
  src.push("in vec4 vColor;");
46030
45971
  src.push("in vec2 vUV;");
46031
45972
  src.push("out vec4 outColor;");
@@ -46047,12 +45988,49 @@ class TrianglesBatchingColorTextureRenderer {
46047
45988
  src.push("}");
46048
45989
  }
46049
45990
 
46050
- if (scene.logarithmicDepthBufferEnabled) {
46051
- src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
45991
+ src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");
45992
+ src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");
45993
+
45994
+ src.push("float lambertian = 1.0;");
45995
+
45996
+ src.push("vec3 xTangent = dFdx( vViewPosition.xyz );");
45997
+ src.push("vec3 yTangent = dFdy( vViewPosition.xyz );");
45998
+ src.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");
45999
+
46000
+ for (let i = 0, len = lightsState.lights.length; i < len; i++) {
46001
+ const light = lightsState.lights[i];
46002
+ if (light.type === "ambient") {
46003
+ continue;
46004
+ }
46005
+ if (light.type === "dir") {
46006
+ if (light.space === "view") {
46007
+ src.push("viewLightDir = normalize(lightDir" + i + ");");
46008
+ } else {
46009
+ src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
46010
+ }
46011
+ } else if (light.type === "point") {
46012
+ if (light.space === "view") {
46013
+ src.push("viewLightDir = -normalize(lightPos" + i + " - viewPosition.xyz);");
46014
+ } else {
46015
+ src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos" + i + ", 0.0)).xyz);");
46016
+ }
46017
+ } else if (light.type === "spot") {
46018
+ if (light.space === "view") {
46019
+ src.push("viewLightDir = normalize(lightDir" + i + ");");
46020
+ } else {
46021
+ src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
46022
+ }
46023
+ } else {
46024
+ continue;
46025
+ }
46026
+
46027
+ src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");
46028
+ src.push("reflectedColor += lambertian * (lightColor" + i + ".rgb * lightColor" + i + ".a);");
46052
46029
  }
46053
46030
 
46054
- src.push("vec4 colorTexel = vColor * texture(uColorMap, vUV);");
46055
- src.push("float opacity = vColor.a;");
46031
+ src.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);");
46032
+ src.push("vec4 colorTexel = color * texture(uColorMap, vUV);");
46033
+ src.push("float opacity = color.a;");
46056
46034
 
46057
46035
  if (this._withSAO) {
46058
46036
  // Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
@@ -46069,6 +46047,10 @@ class TrianglesBatchingColorTextureRenderer {
46069
46047
  src.push(" outColor = vec4(colorTexel.rgb, opacity);");
46070
46048
  }
46071
46049
 
46050
+ if (scene.logarithmicDepthBufferEnabled) {
46051
+ src.push("gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
46052
+ }
46053
+
46072
46054
  src.push("}");
46073
46055
  return src;
46074
46056
  }
@@ -46455,6 +46437,11 @@ function quantizePositions(positions, aabb, positionsDecodeMatrix) { // http://c
46455
46437
  */
46456
46438
  function transformAndOctEncodeNormals(worldNormalMatrix, normals, lenNormals, compressedNormals, lenCompressedNormals) {
46457
46439
  // http://jcgt.org/published/0003/02/01/
46440
+
46441
+ function dot(array, vec3) {
46442
+ return array[0] * vec3[0] + array[1] * vec3[1] + array[2] * vec3[2];
46443
+ }
46444
+
46458
46445
  let oct, dec, best, currentCos, bestCos;
46459
46446
  let i;
46460
46447
  let localNormal = new Float32Array([0, 0, 0, 0]);
@@ -46506,29 +46493,29 @@ function transformAndOctEncodeNormals(worldNormalMatrix, normals, lenNormals, co
46506
46493
  function octEncodeNormals(normals) { // http://jcgt.org/published/0003/02/01/
46507
46494
  const lenNormals = normals.length;
46508
46495
  const compressedNormals = new Int8Array(lenNormals);
46509
- let oct, best, currentCos, bestCos;
46496
+ let oct, dec, best, currentCos, bestCos;
46510
46497
  for (let i = 0; i < lenNormals; i += 3) {
46511
46498
  // Test various combinations of ceil and floor to minimize rounding errors
46512
46499
  best = oct = octEncodeNormal(normals, i, "floor", "floor");
46513
- octDecodeVec2(oct);
46514
- currentCos = bestCos = dot(normals, i);
46500
+ dec = octDecodeVec2(oct);
46501
+ currentCos = bestCos = dot(normals, i, dec);
46515
46502
  oct = octEncodeNormal(normals, i, "ceil", "floor");
46516
- octDecodeVec2(oct);
46517
- currentCos = dot(normals, i);
46503
+ dec = octDecodeVec2(oct);
46504
+ currentCos = dot(normals, i, dec);
46518
46505
  if (currentCos > bestCos) {
46519
46506
  best = oct;
46520
46507
  bestCos = currentCos;
46521
46508
  }
46522
46509
  oct = octEncodeNormal(normals, i, "floor", "ceil");
46523
- octDecodeVec2(oct);
46524
- currentCos = dot(normals, i);
46510
+ dec = octDecodeVec2(oct);
46511
+ currentCos = dot(normals, i, dec);
46525
46512
  if (currentCos > bestCos) {
46526
46513
  best = oct;
46527
46514
  bestCos = currentCos;
46528
46515
  }
46529
46516
  oct = octEncodeNormal(normals, i, "ceil", "ceil");
46530
- octDecodeVec2(oct);
46531
- currentCos = dot(normals, i);
46517
+ dec = octDecodeVec2(oct);
46518
+ currentCos = dot(normals, i, dec);
46532
46519
  if (currentCos > bestCos) {
46533
46520
  best = oct;
46534
46521
  bestCos = currentCos;
@@ -46602,8 +46589,8 @@ function octDecodeVec2(oct) { // Decode an oct-encoded normal
46602
46589
  /**
46603
46590
  * @private
46604
46591
  */
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];
46592
+ function dot(array, i, vec3) {
46593
+ return array[i] * vec3[0] + array[i + 1] * vec3[1] + array[i + 2] * vec3[2];
46607
46594
  }
46608
46595
 
46609
46596
  const tempMat4$2 = math.mat4();
@@ -47132,7 +47119,6 @@ class TrianglesBatchingLayer {
47132
47119
 
47133
47120
  this._state.colorTextureSupported
47134
47121
  = !!state.uvBuf
47135
- && !!state.normalsBuf
47136
47122
  && !!state.textureSet
47137
47123
  && !!state.textureSet.colorTexture;
47138
47124
 
@@ -48875,8 +48861,8 @@ class TrianglesInstancingFlatColorRenderer {
48875
48861
 
48876
48862
  src.push("in vec4 vViewPosition;");
48877
48863
  src.push("in vec4 vColor;");
48878
-
48879
48864
  src.push("out vec4 outColor;");
48865
+
48880
48866
  src.push("void main(void) {");
48881
48867
 
48882
48868
  if (clipping) {
@@ -53549,10 +53535,7 @@ class TrianglesInstancingColorTextureRenderer {
53549
53535
  gl.uniform1i(this._uRenderPass, renderPass);
53550
53536
 
53551
53537
  gl.uniformMatrix4fv(this._uViewMatrix, false, (origin) ? createRTCViewMat(camera.viewMatrix, origin) : camera.viewMatrix);
53552
- gl.uniformMatrix4fv(this._uViewNormalMatrix, false, camera.viewNormalMatrix);
53553
-
53554
53538
  gl.uniformMatrix4fv(this._uWorldMatrix, false, model.worldMatrix);
53555
- gl.uniformMatrix4fv(this._uWorldNormalMatrix, false, model.worldNormalMatrix);
53556
53539
 
53557
53540
  const numSectionPlanes = scene._sectionPlanesState.sectionPlanes.length;
53558
53541
  if (numSectionPlanes > 0) {
@@ -53592,16 +53575,7 @@ class TrianglesInstancingColorTextureRenderer {
53592
53575
  gl.vertexAttribDivisor(this._aModelMatrixCol1.location, 1);
53593
53576
  gl.vertexAttribDivisor(this._aModelMatrixCol2.location, 1);
53594
53577
 
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
53578
  this._aPosition.bindArrayBuffer(geometry.positionsBuf);
53604
- this._aNormal.bindArrayBuffer(geometry.normalsBuf);
53605
53579
  this._aUV.bindArrayBuffer(geometry.uvBuf);
53606
53580
 
53607
53581
  this._aColor.bindArrayBuffer(state.colorsBuf);
@@ -53629,9 +53603,6 @@ class TrianglesInstancingColorTextureRenderer {
53629
53603
  gl.vertexAttribDivisor(this._aModelMatrixCol0.location, 0);
53630
53604
  gl.vertexAttribDivisor(this._aModelMatrixCol1.location, 0);
53631
53605
  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
53606
  gl.vertexAttribDivisor(this._aColor.location, 0);
53636
53607
  gl.vertexAttribDivisor(this._aFlags.location, 0);
53637
53608
 
@@ -53687,10 +53658,8 @@ class TrianglesInstancingColorTextureRenderer {
53687
53658
  this._uUVDecodeMatrix = program.getLocation("uvDecodeMatrix");
53688
53659
 
53689
53660
  this._uWorldMatrix = program.getLocation("worldMatrix");
53690
- this._uWorldNormalMatrix = program.getLocation("worldNormalMatrix");
53691
53661
 
53692
53662
  this._uViewMatrix = program.getLocation("viewMatrix");
53693
- this._uViewNormalMatrix = program.getLocation("viewNormalMatrix");
53694
53663
  this._uProjMatrix = program.getLocation("projMatrix");
53695
53664
 
53696
53665
  this._uLightAmbient = program.getLocation("lightAmbient");
@@ -53736,7 +53705,6 @@ class TrianglesInstancingColorTextureRenderer {
53736
53705
  }
53737
53706
 
53738
53707
  this._aPosition = program.getAttribute("position");
53739
- this._aNormal = program.getAttribute("normal");
53740
53708
  this._aColor = program.getAttribute("color");
53741
53709
  this._aUV = program.getAttribute("uv");
53742
53710
  this._aFlags = program.getAttribute("flags");
@@ -53747,10 +53715,6 @@ class TrianglesInstancingColorTextureRenderer {
53747
53715
  this._aModelMatrixCol1 = program.getAttribute("modelMatrixCol1");
53748
53716
  this._aModelMatrixCol2 = program.getAttribute("modelMatrixCol2");
53749
53717
 
53750
- this._aModelNormalMatrixCol0 = program.getAttribute("modelNormalMatrixCol0");
53751
- this._aModelNormalMatrixCol1 = program.getAttribute("modelNormalMatrixCol1");
53752
- this._aModelNormalMatrixCol2 = program.getAttribute("modelNormalMatrixCol2");
53753
-
53754
53718
  this._uColorMap = "uColorMap";
53755
53719
 
53756
53720
  this._uOcclusionTexture = "uOcclusionTexture";
@@ -53809,11 +53773,7 @@ class TrianglesInstancingColorTextureRenderer {
53809
53773
  _buildVertexShader() {
53810
53774
  const scene = this._scene;
53811
53775
  const sectionPlanesState = scene._sectionPlanesState;
53812
- const lightsState = scene._lightsState;
53813
53776
  const clipping = sectionPlanesState.sectionPlanes.length > 0;
53814
- let i;
53815
- let len;
53816
- let light;
53817
53777
  const src = [];
53818
53778
  src.push("#version 300 es");
53819
53779
  src.push("// Instancing geometry drawing vertex shader");
@@ -53821,7 +53781,6 @@ class TrianglesInstancingColorTextureRenderer {
53821
53781
  src.push("uniform int renderPass;");
53822
53782
 
53823
53783
  src.push("in vec3 position;");
53824
- src.push("in vec3 normal;");
53825
53784
  src.push("in vec4 color;");
53826
53785
  src.push("in vec2 uv;");
53827
53786
  src.push("in vec4 flags;");
@@ -53835,14 +53794,8 @@ class TrianglesInstancingColorTextureRenderer {
53835
53794
  src.push("in vec4 modelMatrixCol1;");
53836
53795
  src.push("in vec4 modelMatrixCol2;");
53837
53796
 
53838
- src.push("in vec4 modelNormalMatrixCol0;");
53839
- src.push("in vec4 modelNormalMatrixCol1;");
53840
- src.push("in vec4 modelNormalMatrixCol2;");
53841
-
53842
53797
  src.push("uniform mat4 worldMatrix;");
53843
- src.push("uniform mat4 worldNormalMatrix;");
53844
53798
  src.push("uniform mat4 viewMatrix;");
53845
- src.push("uniform mat4 viewNormalMatrix;");
53846
53799
  src.push("uniform mat4 projMatrix;");
53847
53800
  src.push("uniform mat4 positionsDecodeMatrix;");
53848
53801
  src.push("uniform mat3 uvDecodeMatrix;");
@@ -53856,38 +53809,11 @@ class TrianglesInstancingColorTextureRenderer {
53856
53809
  src.push("out float isPerspective;");
53857
53810
  }
53858
53811
 
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
53812
  if (clipping) {
53888
53813
  src.push("out vec4 vWorldPosition;");
53889
53814
  src.push("out vec4 vFlags2;");
53890
53815
  }
53816
+ src.push("out vec4 vViewPosition;");
53891
53817
  src.push("out vec4 vColor;");
53892
53818
  src.push("out vec2 vUV;");
53893
53819
 
@@ -53908,47 +53834,8 @@ class TrianglesInstancingColorTextureRenderer {
53908
53834
  }
53909
53835
 
53910
53836
  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);");
53837
+ src.push("vViewPosition = viewPosition;");
53838
+ 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
53839
  src.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;");
53953
53840
 
53954
53841
  src.push("vec4 clipPos = projMatrix * viewPosition;");
@@ -53971,6 +53858,9 @@ class TrianglesInstancingColorTextureRenderer {
53971
53858
  _buildFragmentShader() {
53972
53859
  const scene = this._scene;
53973
53860
  const sectionPlanesState = scene._sectionPlanesState;
53861
+ const lightsState = scene._lightsState;
53862
+ let i;
53863
+ let len;
53974
53864
  const clipping = sectionPlanesState.sectionPlanes.length > 0;
53975
53865
  const src = [];
53976
53866
  src.push("#version 300 es");
@@ -54012,9 +53902,31 @@ class TrianglesInstancingColorTextureRenderer {
54012
53902
  src.push("uniform vec3 sectionPlaneDir" + i + ";");
54013
53903
  }
54014
53904
  }
53905
+ src.push("uniform mat4 viewMatrix;");
53906
+ src.push("uniform vec4 lightAmbient;");
53907
+ for (i = 0, len = lightsState.lights.length; i < len; i++) {
53908
+ const light = lightsState.lights[i];
53909
+ if (light.type === "ambient") {
53910
+ continue;
53911
+ }
53912
+ src.push("uniform vec4 lightColor" + i + ";");
53913
+ if (light.type === "dir") {
53914
+ src.push("uniform vec3 lightDir" + i + ";");
53915
+ }
53916
+ if (light.type === "point") {
53917
+ src.push("uniform vec3 lightPos" + i + ";");
53918
+ }
53919
+ if (light.type === "spot") {
53920
+ src.push("uniform vec3 lightPos" + i + ";");
53921
+ src.push("uniform vec3 lightDir" + i + ";");
53922
+ }
53923
+ }
53924
+
53925
+ src.push("in vec4 vViewPosition;");
54015
53926
  src.push("in vec4 vColor;");
54016
53927
  src.push("in vec2 vUV;");
54017
53928
  src.push("out vec4 outColor;");
53929
+
54018
53930
  src.push("void main(void) {");
54019
53931
 
54020
53932
  if (clipping) {
@@ -54032,17 +53944,52 @@ class TrianglesInstancingColorTextureRenderer {
54032
53944
  src.push("}");
54033
53945
  }
54034
53946
 
54035
- if (scene.logarithmicDepthBufferEnabled) {
54036
- src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
54037
- }
53947
+ src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");
53948
+ src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");
54038
53949
 
54039
- src.push("vec4 colorTexel = texture(uColorMap, vUV);");
54040
- src.push("float opacity = vColor.a;");
53950
+ src.push("float lambertian = 1.0;");
54041
53951
 
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
53952
+ src.push("vec3 xTangent = dFdx( vViewPosition.xyz );");
53953
+ src.push("vec3 yTangent = dFdy( vViewPosition.xyz );");
53954
+ src.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");
53955
+
53956
+ for (i = 0, len = lightsState.lights.length; i < len; i++) {
53957
+ const light = lightsState.lights[i];
53958
+ if (light.type === "ambient") {
53959
+ continue;
53960
+ }
53961
+ if (light.type === "dir") {
53962
+ if (light.space === "view") {
53963
+ src.push("viewLightDir = normalize(lightDir" + i + ");");
53964
+ } else {
53965
+ src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
53966
+ }
53967
+ } else if (light.type === "point") {
53968
+ if (light.space === "view") {
53969
+ src.push("viewLightDir = -normalize(lightPos" + i + " - viewPosition.xyz);");
53970
+ } else {
53971
+ src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos" + i + ", 0.0)).xyz);");
53972
+ }
53973
+ } else if (light.type === "spot") {
53974
+ if (light.space === "view") {
53975
+ src.push("viewLightDir = normalize(lightDir" + i + ");");
53976
+ } else {
53977
+ src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
53978
+ }
53979
+ } else {
53980
+ continue;
53981
+ }
53982
+ src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");
53983
+ src.push("reflectedColor += lambertian * (lightColor" + i + ".rgb * lightColor" + i + ".a);");
53984
+ }
53985
+
53986
+ src.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);");
53987
+ src.push("vec4 colorTexel = color * texture(uColorMap, vUV);");
53988
+ src.push("float opacity = color.a;");
54044
53989
 
54045
53990
  if (this._withSAO) {
53991
+ // Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
53992
+ // Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
54046
53993
  src.push(" float viewportWidth = uSAOParams[0];");
54047
53994
  src.push(" float viewportHeight = uSAOParams[1];");
54048
53995
  src.push(" float blendCutoff = uSAOParams[2];");
@@ -54053,6 +54000,11 @@ class TrianglesInstancingColorTextureRenderer {
54053
54000
  } else {
54054
54001
  src.push(" outColor = vec4(vColor.rgb * colorTexel.rgb, opacity);");
54055
54002
  }
54003
+
54004
+ if (scene.logarithmicDepthBufferEnabled) {
54005
+ src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
54006
+ }
54007
+
54056
54008
  src.push("}");
54057
54009
  return src;
54058
54010
  }
@@ -54708,7 +54660,6 @@ class TrianglesInstancingLayer {
54708
54660
 
54709
54661
  this._state.colorTextureSupported
54710
54662
  = !!geometry.uvBuf
54711
- && !!geometry.normalsBuf
54712
54663
  && !!textureSet
54713
54664
  && !!textureSet.colorTexture;
54714
54665
 
@@ -163374,7 +163325,7 @@ class CityJSONLoaderPlugin extends Plugin {
163374
163325
 
163375
163326
  _parseGeometrySurfacesWithSharedMaterial(ctx, geometry, objectMaterial, meshIds) {
163376
163327
 
163377
- ctx.performanceModel;
163328
+ const sceneModel = ctx.sceneModel;
163378
163329
  const sharedIndices = [];
163379
163330
  const geometryCfg = {
163380
163331
  positions: [],
@@ -163420,7 +163371,7 @@ class CityJSONLoaderPlugin extends Plugin {
163420
163371
 
163421
163372
  const meshId = "" + ctx.nextId++;
163422
163373
 
163423
- performanceModel.createMesh({
163374
+ sceneModel.createMesh({
163424
163375
  id: meshId,
163425
163376
  primitive: "triangles",
163426
163377
  positions: geometryCfg.positions,