@xeokit/xeokit-sdk 2.5.2-beta-11 → 2.5.2-beta-13

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.
Files changed (52) hide show
  1. package/dist/xeokit-sdk.cjs.js +146 -132
  2. package/dist/xeokit-sdk.es.js +146 -132
  3. package/dist/xeokit-sdk.es5.js +84 -84
  4. package/dist/xeokit-sdk.min.cjs.js +1 -1
  5. package/dist/xeokit-sdk.min.es.js +1 -1
  6. package/dist/xeokit-sdk.min.es5.js +1 -1
  7. package/package.json +1 -1
  8. package/src/viewer/scene/model/SceneModel.js +1 -1
  9. package/src/viewer/scene/model/vbo/batching/triangles/VBOBatchingTrianglesLayer.js +1 -1
  10. package/src/viewer/scene/model/vbo/instancing/triangles/VBOInstancingTrianglesLayer.js +1 -1
  11. package/src/viewer/scene/webgl/Renderer.js +20 -19
  12. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesColorRenderer.js +0 -238
  13. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesColorTextureRenderer.js +0 -270
  14. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesDepthRenderer.js +0 -126
  15. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesEdgesColorRenderer.js +0 -127
  16. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesEdgesRenderer.js +0 -133
  17. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesFlatColorRenderer.js +0 -235
  18. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesNormalsRenderer.js +0 -139
  19. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesOcclusionRenderer.js +0 -125
  20. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesPBRRenderer.js +0 -561
  21. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesPickDepthRenderer.js +0 -144
  22. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesPickMeshRenderer.js +0 -130
  23. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesPickNormalsFlatRenderer.js +0 -121
  24. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesPickNormalsRenderer.js +0 -131
  25. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesRenderer.js +0 -33
  26. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesRenderers.js +0 -375
  27. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesShadowRenderer.js +0 -107
  28. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesSilhouetteRenderer.js +0 -136
  29. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesSnapInitRenderer.js +0 -311
  30. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOBatchingTrianglesSnapRenderer.js +0 -308
  31. package/src/viewer/scene/model/vbo/batching/triangles/renderers/VBOSceneModelTriangleBatchingEdgesRenderer.js +0 -12
  32. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesColorRenderer.js +0 -253
  33. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesColorTextureRenderer.js +0 -278
  34. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesDepthRenderer.js +0 -126
  35. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesEdgesColorRenderer.js +0 -132
  36. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesEdgesRenderer.js +0 -134
  37. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesFlatColorRenderer.js +0 -244
  38. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesFlatNormalsRenderer.js +0 -130
  39. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesNormalsRenderer.js +0 -138
  40. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesOcclusionRenderer.js +0 -128
  41. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesPBRRenderer.js +0 -561
  42. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesPickDepthRenderer.js +0 -149
  43. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesPickMeshRenderer.js +0 -136
  44. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesPickNormalsFlatRenderer.js +0 -130
  45. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesPickNormalsRenderer.js +0 -145
  46. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesRenderers.js +0 -376
  47. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesShadowRenderer.js +0 -113
  48. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesSilhouetteRenderer.js +0 -139
  49. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesSnapInitRenderer.js +0 -342
  50. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOInstancingTrianglesSnapRenderer.js +0 -325
  51. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOSceneModelTriangleInstancingEdgesRenderer.js +0 -12
  52. package/src/viewer/scene/model/vbo/instancing/triangles/renderers/VBOSceneModelTriangleInstancingRenderer.js +0 -29
@@ -1,253 +0,0 @@
1
- import {VBOSceneModelTriangleInstancingRenderer} from "./VBOSceneModelTriangleInstancingRenderer.js";
2
-
3
- /**
4
- * @private
5
- */
6
- class VBOInstancingTrianglesColorRenderer extends VBOSceneModelTriangleInstancingRenderer {
7
- _getHash() {
8
- const scene = this._scene;
9
- return [scene._lightsState.getHash(), scene._sectionPlanesState.getHash(), (this._withSAO ? "sao" : "nosao")].join(";");
10
- }
11
-
12
- drawLayer(frameCtx, layer, renderPass) {
13
- super.drawLayer(frameCtx, layer, renderPass, { incrementDrawState: true });
14
- }
15
-
16
- _buildVertexShader() {
17
- const scene = this._scene;
18
- const sectionPlanesState = scene._sectionPlanesState;
19
- const lightsState = scene._lightsState;
20
- const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
21
- let i;
22
- let len;
23
- let light;
24
- const src = [];
25
- src.push("#version 300 es");
26
- src.push("// Instancing geometry drawing vertex shader");
27
-
28
- src.push("uniform int renderPass;");
29
-
30
- src.push("in vec3 position;");
31
- src.push("in vec2 normal;");
32
- src.push("in vec4 color;");
33
- src.push("in float flags;");
34
-
35
- if (scene.entityOffsetsEnabled) {
36
- src.push("in vec3 offset;");
37
- }
38
-
39
- src.push("in vec4 modelMatrixCol0;"); // Modeling matrix
40
- src.push("in vec4 modelMatrixCol1;");
41
- src.push("in vec4 modelMatrixCol2;");
42
-
43
- src.push("in vec4 modelNormalMatrixCol0;");
44
- src.push("in vec4 modelNormalMatrixCol1;");
45
- src.push("in vec4 modelNormalMatrixCol2;");
46
-
47
- this._addMatricesUniformBlockLines(src, true);
48
-
49
- if (scene.logarithmicDepthBufferEnabled) {
50
- src.push("uniform float logDepthBufFC;");
51
- src.push("out float vFragDepth;");
52
- src.push("bool isPerspectiveMatrix(mat4 m) {");
53
- src.push(" return (m[2][3] == - 1.0);");
54
- src.push("}");
55
- src.push("out float isPerspective;");
56
- }
57
-
58
- src.push("uniform vec4 lightAmbient;");
59
-
60
- for (i = 0, len = lightsState.lights.length; i < len; i++) {
61
- light = lightsState.lights[i];
62
- if (light.type === "ambient") {
63
- continue;
64
- }
65
- src.push("uniform vec4 lightColor" + i + ";");
66
- if (light.type === "dir") {
67
- src.push("uniform vec3 lightDir" + i + ";");
68
- }
69
- if (light.type === "point") {
70
- src.push("uniform vec3 lightPos" + i + ";");
71
- }
72
- if (light.type === "spot") {
73
- src.push("uniform vec3 lightPos" + i + ";");
74
- src.push("uniform vec3 lightDir" + i + ";");
75
- }
76
- }
77
-
78
- src.push("vec3 octDecode(vec2 oct) {");
79
- src.push(" vec3 v = vec3(oct.xy, 1.0 - abs(oct.x) - abs(oct.y));");
80
- src.push(" if (v.z < 0.0) {");
81
- 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);");
82
- src.push(" }");
83
- src.push(" return normalize(v);");
84
- src.push("}");
85
-
86
- if (clipping) {
87
- src.push("out vec4 vWorldPosition;");
88
- src.push("out float vFlags;");
89
- }
90
- src.push("out vec4 vColor;");
91
-
92
- src.push("void main(void) {");
93
-
94
- // colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
95
- // renderPass = COLOR_OPAQUE | COLOR_TRANSPARENT
96
-
97
- src.push(`int colorFlag = int(flags) & 0xF;`);
98
- src.push(`if (colorFlag != renderPass) {`);
99
- src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"); // Cull vertex
100
-
101
- src.push("} else {");
102
-
103
- src.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");
104
- src.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");
105
- if (scene.entityOffsetsEnabled) {
106
- src.push("worldPosition.xyz = worldPosition.xyz + offset;");
107
- }
108
-
109
- src.push("vec4 viewPosition = viewMatrix * worldPosition; ");
110
-
111
- src.push("vec4 modelNormal = vec4(octDecode(normal.xy), 0.0); ");
112
- src.push("vec4 worldNormal = worldNormalMatrix * vec4(dot(modelNormal, modelNormalMatrixCol0), dot(modelNormal, modelNormalMatrixCol1), dot(modelNormal, modelNormalMatrixCol2), 0.0);");
113
- src.push("vec3 viewNormal = normalize(vec4(viewNormalMatrix * worldNormal).xyz);");
114
-
115
- src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");
116
- src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");
117
-
118
- src.push("float lambertian = 1.0;");
119
- for (i = 0, len = lightsState.lights.length; i < len; i++) {
120
- light = lightsState.lights[i];
121
- if (light.type === "ambient") {
122
- continue;
123
- }
124
- if (light.type === "dir") {
125
- if (light.space === "view") {
126
- src.push("viewLightDir = normalize(lightDir" + i + ");");
127
- } else {
128
- src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
129
- }
130
- } else if (light.type === "point") {
131
- if (light.space === "view") {
132
- src.push("viewLightDir = -normalize(lightPos" + i + " - viewPosition.xyz);");
133
- } else {
134
- src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos" + i + ", 0.0)).xyz);");
135
- }
136
- } else if (light.type === "spot") {
137
- if (light.space === "view") {
138
- src.push("viewLightDir = normalize(lightDir" + i + ");");
139
- } else {
140
- src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
141
- }
142
- } else {
143
- continue;
144
- }
145
- src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");
146
- src.push("reflectedColor += lambertian * (lightColor" + i + ".rgb * lightColor" + i + ".a);");
147
- }
148
-
149
- src.push("vec3 rgb = (vec3(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0));");
150
- src.push("vColor = vec4((lightAmbient.rgb * lightAmbient.a * rgb) + (reflectedColor * rgb), float(color.a) / 255.0);");
151
-
152
- src.push("vec4 clipPos = projMatrix * viewPosition;");
153
- if (scene.logarithmicDepthBufferEnabled) {
154
- src.push("vFragDepth = 1.0 + clipPos.w;");
155
- src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
156
- }
157
-
158
- if (clipping) {
159
- src.push("vWorldPosition = worldPosition;");
160
- src.push("vFlags = flags;");
161
- }
162
-
163
- src.push("gl_Position = clipPos;");
164
- src.push("}");
165
- src.push("}");
166
- return src;
167
- }
168
-
169
- _buildFragmentShader() {
170
- const scene = this._scene;
171
- const sectionPlanesState = scene._sectionPlanesState;
172
- const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
173
- const src = [];
174
- src.push("#version 300 es");
175
- src.push("// Instancing geometry drawing fragment shader");
176
-
177
- src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");
178
- src.push("precision highp float;");
179
- src.push("precision highp int;");
180
- src.push("#else");
181
- src.push("precision mediump float;");
182
- src.push("precision mediump int;");
183
- src.push("#endif");
184
- if (scene.logarithmicDepthBufferEnabled) {
185
- src.push("in float isPerspective;");
186
- src.push("uniform float logDepthBufFC;");
187
- src.push("in float vFragDepth;");
188
- }
189
- if (this._withSAO) {
190
- src.push("uniform sampler2D uOcclusionTexture;");
191
- src.push("uniform vec4 uSAOParams;");
192
- src.push("const float packUpscale = 256. / 255.;");
193
- src.push("const float unpackDownScale = 255. / 256.;");
194
- src.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );");
195
- src.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );");
196
-
197
- src.push("float unpackRGBToFloat( const in vec4 v ) {");
198
- src.push(" return dot( v, unPackFactors );");
199
- src.push("}");
200
- }
201
-
202
- if (clipping) {
203
- src.push("in vec4 vWorldPosition;");
204
- src.push("in float vFlags;");
205
- for (let i = 0, len = sectionPlanesState.getNumAllocatedSectionPlanes(); i < len; i++) {
206
- src.push("uniform bool sectionPlaneActive" + i + ";");
207
- src.push("uniform vec3 sectionPlanePos" + i + ";");
208
- src.push("uniform vec3 sectionPlaneDir" + i + ";");
209
- }
210
- }
211
- src.push("in vec4 vColor;");
212
- src.push("out vec4 outColor;");
213
- src.push("void main(void) {");
214
-
215
- if (clipping) {
216
- src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");
217
- src.push(" if (clippable) {");
218
- src.push(" float dist = 0.0;");
219
- for (let i = 0, len = sectionPlanesState.getNumAllocatedSectionPlanes(); i < len; i++) {
220
- src.push("if (sectionPlaneActive" + i + ") {");
221
- src.push(" dist += clamp(dot(-sectionPlaneDir" + i + ".xyz, vWorldPosition.xyz - sectionPlanePos" + i + ".xyz), 0.0, 1000.0);");
222
- src.push("}");
223
- }
224
- src.push(" if (dist > 0.0) { ");
225
- src.push(" discard;")
226
- src.push(" }");
227
- src.push("}");
228
- }
229
-
230
- if (scene.logarithmicDepthBufferEnabled) {
231
- src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
232
- }
233
-
234
- // Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
235
- // Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
236
-
237
- if (this._withSAO) {
238
- src.push(" float viewportWidth = uSAOParams[0];");
239
- src.push(" float viewportHeight = uSAOParams[1];");
240
- src.push(" float blendCutoff = uSAOParams[2];");
241
- src.push(" float blendFactor = uSAOParams[3];");
242
- src.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);");
243
- src.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;");
244
- src.push(" outColor = vec4(vColor.rgb * ambient, 1.0);");
245
- } else {
246
- src.push(" outColor = vColor;");
247
- }
248
- src.push("}");
249
- return src;
250
- }
251
- }
252
-
253
- export {VBOInstancingTrianglesColorRenderer};
@@ -1,278 +0,0 @@
1
- import {VBOSceneModelTriangleInstancingRenderer} from "./VBOSceneModelTriangleInstancingRenderer.js";
2
-
3
- /**
4
- * @private
5
- */
6
-
7
-
8
- export class VBOInstancingTrianglesColorTextureRenderer extends VBOSceneModelTriangleInstancingRenderer {
9
- _getHash() {
10
- const scene = this._scene;
11
- return [scene.gammaOutput, scene._lightsState.getHash(), scene._sectionPlanesState.getHash(), (this._withSAO ? "sao" : "nosao")].join(";");
12
- }
13
-
14
- drawLayer(frameCtx, layer, renderPass) {
15
- super.drawLayer(frameCtx, layer, renderPass, { incrementDrawState: true });
16
- }
17
-
18
- _buildVertexShader() {
19
- const scene = this._scene;
20
- const sectionPlanesState = scene._sectionPlanesState;
21
- const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
22
- const src = [];
23
- src.push("#version 300 es");
24
- src.push("// Instancing geometry drawing vertex shader");
25
-
26
- src.push("uniform int renderPass;");
27
-
28
- src.push("in vec3 position;");
29
- src.push("in vec4 color;");
30
- src.push("in vec2 uv;");
31
- src.push("in float flags;");
32
-
33
- if (scene.entityOffsetsEnabled) {
34
- src.push("in vec3 offset;");
35
- }
36
-
37
- src.push("in vec4 modelMatrixCol0;"); // Modeling matrix
38
- src.push("in vec4 modelMatrixCol1;");
39
- src.push("in vec4 modelMatrixCol2;");
40
-
41
- this._addMatricesUniformBlockLines(src);
42
-
43
- src.push("uniform mat3 uvDecodeMatrix;")
44
-
45
- if (scene.logarithmicDepthBufferEnabled) {
46
- src.push("uniform float logDepthBufFC;");
47
- src.push("out float vFragDepth;");
48
- src.push("bool isPerspectiveMatrix(mat4 m) {");
49
- src.push(" return (m[2][3] == - 1.0);");
50
- src.push("}");
51
- src.push("out float isPerspective;");
52
- }
53
-
54
- if (clipping) {
55
- src.push("out vec4 vWorldPosition;");
56
- src.push("out float vFlags;");
57
- }
58
- src.push("out vec4 vViewPosition;");
59
- src.push("out vec4 vColor;");
60
- src.push("out vec2 vUV;");
61
-
62
- src.push("void main(void) {");
63
-
64
- // colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
65
- // renderPass = COLOR_OPAQUE | COLOR_TRANSPARENT
66
-
67
- src.push(`int colorFlag = int(flags) & 0xF;`);
68
- src.push(`if (colorFlag != renderPass) {`);
69
- src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"); // Cull vertex
70
-
71
- src.push("} else {");
72
-
73
- src.push("vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");
74
- src.push("worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");
75
- if (scene.entityOffsetsEnabled) {
76
- src.push(" worldPosition.xyz = worldPosition.xyz + offset;");
77
- }
78
-
79
- src.push("vec4 viewPosition = viewMatrix * worldPosition; ");
80
- src.push("vViewPosition = viewPosition;");
81
- src.push("vColor = vec4(float(color.r) / 255.0, float(color.g) / 255.0, float(color.b) / 255.0, float(color.a) / 255.0);");
82
- src.push("vUV = (uvDecodeMatrix * vec3(uv, 1.0)).xy;");
83
-
84
- src.push("vec4 clipPos = projMatrix * viewPosition;");
85
- if (scene.logarithmicDepthBufferEnabled) {
86
- src.push("vFragDepth = 1.0 + clipPos.w;");
87
- src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
88
- }
89
-
90
- if (clipping) {
91
- src.push("vWorldPosition = worldPosition;");
92
- src.push("vFlags = flags;");
93
- }
94
-
95
- src.push("gl_Position = clipPos;");
96
- src.push("}");
97
- src.push("}");
98
- return src;
99
- }
100
-
101
- _buildFragmentShader() {
102
- const scene = this._scene;
103
- const gammaOutput = scene.gammaOutput; // If set, then it expects that all textures and colors need to be outputted in premultiplied gamma. Default is false.
104
- const sectionPlanesState = scene._sectionPlanesState;
105
- const lightsState = scene._lightsState;
106
- let i;
107
- let len;
108
- const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
109
- const src = [];
110
- src.push("#version 300 es");
111
- src.push("// Instancing geometry drawing fragment shader");
112
-
113
- src.push("#ifdef GL_FRAGMENT_PRECISION_HIGH");
114
- src.push("precision highp float;");
115
- src.push("precision highp int;");
116
- src.push("#else");
117
- src.push("precision mediump float;");
118
- src.push("precision mediump int;");
119
- src.push("#endif");
120
- if (scene.logarithmicDepthBufferEnabled) {
121
- src.push("in float isPerspective;");
122
- src.push("uniform float logDepthBufFC;");
123
- src.push("in float vFragDepth;");
124
- }
125
- src.push("uniform sampler2D uColorMap;");
126
- if (this._withSAO) {
127
- src.push("uniform sampler2D uOcclusionTexture;");
128
- src.push("uniform vec4 uSAOParams;");
129
-
130
- src.push("const float packUpscale = 256. / 255.;");
131
- src.push("const float unpackDownScale = 255. / 256.;");
132
- src.push("const vec3 packFactors = vec3( 256. * 256. * 256., 256. * 256., 256. );");
133
- src.push("const vec4 unPackFactors = unpackDownScale / vec4( packFactors, 1. );");
134
-
135
- src.push("float unpackRGBToFloat( const in vec4 v ) {");
136
- src.push(" return dot( v, unPackFactors );");
137
- src.push("}");
138
- }
139
- src.push("uniform float gammaFactor;");
140
- src.push("vec4 linearToLinear( in vec4 value ) {");
141
- src.push(" return value;");
142
- src.push("}");
143
- src.push("vec4 sRGBToLinear( in vec4 value ) {");
144
- src.push(" return vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.w );");
145
- src.push("}");
146
- src.push("vec4 gammaToLinear( in vec4 value) {");
147
- src.push(" return vec4( pow( value.xyz, vec3( gammaFactor ) ), value.w );");
148
- src.push("}");
149
- if (gammaOutput) {
150
- src.push("vec4 linearToGamma( in vec4 value, in float gammaFactor ) {");
151
- src.push(" return vec4( pow( value.xyz, vec3( 1.0 / gammaFactor ) ), value.w );");
152
- src.push("}");
153
- }
154
- if (clipping) {
155
- src.push("in vec4 vWorldPosition;");
156
- src.push("in float vFlags;");
157
- for (let i = 0, len = sectionPlanesState.getNumAllocatedSectionPlanes(); i < len; i++) {
158
- src.push("uniform bool sectionPlaneActive" + i + ";");
159
- src.push("uniform vec3 sectionPlanePos" + i + ";");
160
- src.push("uniform vec3 sectionPlaneDir" + i + ";");
161
- }
162
- }
163
- this._addMatricesUniformBlockLines(src);
164
-
165
- src.push("uniform vec4 lightAmbient;");
166
- for (i = 0, len = lightsState.lights.length; i < len; i++) {
167
- const light = lightsState.lights[i];
168
- if (light.type === "ambient") {
169
- continue;
170
- }
171
- src.push("uniform vec4 lightColor" + i + ";");
172
- if (light.type === "dir") {
173
- src.push("uniform vec3 lightDir" + i + ";");
174
- }
175
- if (light.type === "point") {
176
- src.push("uniform vec3 lightPos" + i + ";");
177
- }
178
- if (light.type === "spot") {
179
- src.push("uniform vec3 lightPos" + i + ";");
180
- src.push("uniform vec3 lightDir" + i + ";");
181
- }
182
- }
183
-
184
- src.push("in vec4 vViewPosition;");
185
- src.push("in vec4 vColor;");
186
- src.push("in vec2 vUV;");
187
- src.push("out vec4 outColor;");
188
-
189
- src.push("void main(void) {");
190
-
191
- if (clipping) {
192
- src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");
193
- src.push(" if (clippable) {");
194
- src.push(" float dist = 0.0;");
195
- for (let i = 0, len = sectionPlanesState.getNumAllocatedSectionPlanes(); i < len; i++) {
196
- src.push("if (sectionPlaneActive" + i + ") {");
197
- src.push(" dist += clamp(dot(-sectionPlaneDir" + i + ".xyz, vWorldPosition.xyz - sectionPlanePos" + i + ".xyz), 0.0, 1000.0);");
198
- src.push("}");
199
- }
200
- src.push(" if (dist > 0.0) { ");
201
- src.push(" discard;")
202
- src.push(" }");
203
- src.push("}");
204
- }
205
-
206
- src.push("vec3 reflectedColor = vec3(0.0, 0.0, 0.0);");
207
- src.push("vec3 viewLightDir = vec3(0.0, 0.0, -1.0);");
208
-
209
- src.push("float lambertian = 1.0;");
210
-
211
- src.push("vec3 xTangent = dFdx( vViewPosition.xyz );");
212
- src.push("vec3 yTangent = dFdy( vViewPosition.xyz );");
213
- src.push("vec3 viewNormal = normalize( cross( xTangent, yTangent ) );");
214
-
215
- for (i = 0, len = lightsState.lights.length; i < len; i++) {
216
- const light = lightsState.lights[i];
217
- if (light.type === "ambient") {
218
- continue;
219
- }
220
- if (light.type === "dir") {
221
- if (light.space === "view") {
222
- src.push("viewLightDir = normalize(lightDir" + i + ");");
223
- } else {
224
- src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
225
- }
226
- } else if (light.type === "point") {
227
- if (light.space === "view") {
228
- src.push("viewLightDir = -normalize(lightPos" + i + " - viewPosition.xyz);");
229
- } else {
230
- src.push("viewLightDir = -normalize((viewMatrix * vec4(lightPos" + i + ", 0.0)).xyz);");
231
- }
232
- } else if (light.type === "spot") {
233
- if (light.space === "view") {
234
- src.push("viewLightDir = normalize(lightDir" + i + ");");
235
- } else {
236
- src.push("viewLightDir = normalize((viewMatrix * vec4(lightDir" + i + ", 0.0)).xyz);");
237
- }
238
- } else {
239
- continue;
240
- }
241
- src.push("lambertian = max(dot(-viewNormal, viewLightDir), 0.0);");
242
- src.push("reflectedColor += lambertian * (lightColor" + i + ".rgb * lightColor" + i + ".a);");
243
- }
244
-
245
- src.push("vec4 color = vec4((lightAmbient.rgb * lightAmbient.a * vColor.rgb) + (reflectedColor * vColor.rgb), vColor.a);");
246
- if (gammaOutput) {
247
- src.push("vec4 colorTexel = color * sRGBToLinear(texture(uColorMap, vUV));");
248
- } else {
249
- src.push("vec4 colorTexel = color * texture(uColorMap, vUV);");
250
- }
251
- src.push("float opacity = color.a;");
252
-
253
- if (this._withSAO) {
254
- // Doing SAO blend in the main solid fill draw shader just so that edge lines can be drawn over the top
255
- // Would be more efficient to defer this, then render lines later, using same depth buffer for Z-reject
256
- src.push(" float viewportWidth = uSAOParams[0];");
257
- src.push(" float viewportHeight = uSAOParams[1];");
258
- src.push(" float blendCutoff = uSAOParams[2];");
259
- src.push(" float blendFactor = uSAOParams[3];");
260
- src.push(" vec2 uv = vec2(gl_FragCoord.x / viewportWidth, gl_FragCoord.y / viewportHeight);");
261
- src.push(" float ambient = smoothstep(blendCutoff, 1.0, unpackRGBToFloat(texture(uOcclusionTexture, uv))) * blendFactor;");
262
- src.push(" outColor = vec4(vColor.rgb * colorTexel.rgb * ambient, opacity);");
263
- } else {
264
- src.push(" outColor = vec4(vColor.rgb * colorTexel.rgb, opacity);");
265
- }
266
-
267
- if (gammaOutput) {
268
- src.push("outColor = linearToGamma(outColor, gammaFactor);");
269
- }
270
-
271
- if (scene.logarithmicDepthBufferEnabled) {
272
- src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
273
- }
274
-
275
- src.push("}");
276
- return src;
277
- }
278
- }
@@ -1,126 +0,0 @@
1
- import {VBOSceneModelTriangleInstancingRenderer} from "./VBOSceneModelTriangleInstancingRenderer.js";
2
-
3
- /**
4
- * @private
5
- */
6
-
7
-
8
- export class VBOInstancingTrianglesDepthRenderer extends VBOSceneModelTriangleInstancingRenderer {
9
-
10
- _buildVertexShader() {
11
- const scene = this._scene;
12
- const sectionPlanesState = scene._sectionPlanesState;
13
- const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
14
- const src = [];
15
- src.push("#version 300 es");
16
- src.push("// Instancing geometry depth drawing vertex shader");
17
-
18
- src.push("uniform int renderPass;");
19
- src.push("in vec3 position;");
20
- if (scene.entityOffsetsEnabled) {
21
- src.push("in vec3 offset;");
22
- }
23
- src.push("in float flags;");
24
- src.push("in vec4 modelMatrixCol0;");
25
- src.push("in vec4 modelMatrixCol1;");
26
- src.push("in vec4 modelMatrixCol2;");
27
-
28
- this._addMatricesUniformBlockLines(src);
29
-
30
- if (scene.logarithmicDepthBufferEnabled) {
31
- src.push("uniform float logDepthBufFC;");
32
- src.push("out float vFragDepth;");
33
- src.push("bool isPerspectiveMatrix(mat4 m) {");
34
- src.push(" return (m[2][3] == - 1.0);");
35
- src.push("}");
36
- src.push("out float isPerspective;");
37
- }
38
- if (clipping) {
39
- src.push("out vec4 vWorldPosition;");
40
- src.push("out float vFlags;");
41
- }
42
- src.push("out vec2 vHighPrecisionZW;");
43
- src.push("void main(void) {");
44
-
45
- // colorFlag = NOT_RENDERED | COLOR_OPAQUE | COLOR_TRANSPARENT
46
- // renderPass = COLOR_OPAQUE
47
-
48
- src.push(`int colorFlag = int(flags) & 0xF;`);
49
- src.push(`if (colorFlag != renderPass) {`);
50
- src.push(" gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"); // Cull vertex
51
-
52
- src.push("} else {");
53
- src.push(" vec4 worldPosition = positionsDecodeMatrix * vec4(position, 1.0); ");
54
- src.push(" worldPosition = worldMatrix * vec4(dot(worldPosition, modelMatrixCol0), dot(worldPosition, modelMatrixCol1), dot(worldPosition, modelMatrixCol2), 1.0);");
55
- if (scene.entityOffsetsEnabled) {
56
- src.push(" worldPosition.xyz = worldPosition.xyz + offset;");
57
- }
58
- src.push(" vec4 viewPosition = viewMatrix * worldPosition; ");
59
-
60
- if (clipping) {
61
- src.push("vWorldPosition = worldPosition;");
62
- src.push("vFlags = flags;");
63
- }
64
- src.push("vec4 clipPos = projMatrix * viewPosition;");
65
- if (scene.logarithmicDepthBufferEnabled) {
66
- src.push("vFragDepth = 1.0 + clipPos.w;");
67
- src.push("isPerspective = float (isPerspectiveMatrix(projMatrix));");
68
- }
69
- src.push("gl_Position = clipPos;");
70
- src.push("vHighPrecisionZW = gl_Position.zw;");
71
- src.push("}");
72
- src.push("}");
73
- return src;
74
- }
75
-
76
- _buildFragmentShader() {
77
- const scene = this._scene;
78
- const sectionPlanesState = scene._sectionPlanesState;
79
- let i;
80
- let len;
81
- const clipping = sectionPlanesState.getNumAllocatedSectionPlanes() > 0;
82
- const src = [];
83
- src.push("#version 300 es");
84
- src.push("// Instancing geometry depth drawing fragment shader");
85
-
86
- src.push("precision highp float;");
87
- src.push("precision highp int;");
88
- if (scene.logarithmicDepthBufferEnabled) {
89
- src.push("in float isPerspective;");
90
- src.push("uniform float logDepthBufFC;");
91
- src.push("in float vFragDepth;");
92
- }
93
- if (clipping) {
94
- src.push("in vec4 vWorldPosition;");
95
- src.push("in float vFlags;");
96
- for (i = 0, len = sectionPlanesState.getNumAllocatedSectionPlanes(); i < len; i++) {
97
- src.push("uniform bool sectionPlaneActive" + i + ";");
98
- src.push("uniform vec3 sectionPlanePos" + i + ";");
99
- src.push("uniform vec3 sectionPlaneDir" + i + ";");
100
- }
101
- }
102
- src.push("in vec2 vHighPrecisionZW;");
103
- src.push("out vec4 outColor;");
104
- src.push("void main(void) {");
105
- if (clipping) {
106
- src.push(" bool clippable = (int(vFlags) >> 16 & 0xF) == 1;");
107
- src.push(" if (clippable) {");
108
- src.push(" float dist = 0.0;");
109
- for (i = 0, len = sectionPlanesState.getNumAllocatedSectionPlanes(); i < len; i++) {
110
- src.push("if (sectionPlaneActive" + i + ") {");
111
- src.push(" dist += clamp(dot(-sectionPlaneDir" + i + ".xyz, vWorldPosition.xyz - sectionPlanePos" + i + ".xyz), 0.0, 1000.0);");
112
- src.push("}");
113
- }
114
- src.push("if (dist > 0.0) { discard; }");
115
- src.push("}");
116
- }
117
- if (scene.logarithmicDepthBufferEnabled) {
118
- src.push(" gl_FragDepth = isPerspective == 0.0 ? gl_FragCoord.z : log2( vFragDepth ) * logDepthBufFC * 0.5;");
119
- }
120
- src.push("float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;");
121
- src.push(" outColor = vec4(vec3(1.0 - fragCoordZ), 1.0); ");
122
- src.push("}");
123
- return src;
124
- }
125
- }
126
-