bg2e-js 2.0.1 → 2.0.2

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 (135) hide show
  1. package/dist/bg2e-js.js +11001 -0
  2. package/dist/bg2e-js.js.map +1 -0
  3. package/package.json +17 -6
  4. package/app/AppController.d.ts +0 -37
  5. package/app/AppController.js +0 -32
  6. package/app/Canvas.d.ts +0 -42
  7. package/app/Canvas.js +0 -98
  8. package/app/EventBase.js +0 -8
  9. package/app/KeyboardEvent.js +0 -51
  10. package/app/MainLoop.d.ts +0 -245
  11. package/app/MainLoop.js +0 -251
  12. package/app/MouseEvent.js +0 -77
  13. package/app/TouchEvent.js +0 -15
  14. package/base/Color.js +0 -131
  15. package/base/Environment.js +0 -78
  16. package/base/Light.js +0 -176
  17. package/base/Material.js +0 -619
  18. package/base/PolyList.js +0 -336
  19. package/base/Texture.js +0 -545
  20. package/db/Bg2LoaderPlugin.js +0 -113
  21. package/db/DBPluginApi.js +0 -40
  22. package/db/Loader.js +0 -91
  23. package/db/LoaderPlugin.js +0 -26
  24. package/db/MtlParser.js +0 -7
  25. package/db/ObjLoaderPlugin.js +0 -51
  26. package/db/ObjParser.js +0 -233
  27. package/db/ObjWriterPlugin.js +0 -18
  28. package/db/VitscnjLoaderPlugin.js +0 -87
  29. package/db/Writer.js +0 -49
  30. package/db/WriterPlugin.js +0 -20
  31. package/debug/DebugRenderer.js +0 -138
  32. package/debug/WebGLTextureViewer.js +0 -67
  33. package/manipulation/SelectionBuffer.js +0 -65
  34. package/manipulation/SelectionHighlight.js +0 -69
  35. package/manipulation/SelectionIdAssignVisitor.js +0 -86
  36. package/manipulation/SelectionManager.js +0 -134
  37. package/manipulation/SelectionMode.js +0 -6
  38. package/math/Mat3.js +0 -248
  39. package/math/Mat4.js +0 -694
  40. package/math/MatrixStrategy.js +0 -23
  41. package/math/Quat.js +0 -60
  42. package/math/Vec.js +0 -728
  43. package/math/constants.js +0 -44
  44. package/math/functions.js +0 -104
  45. package/math/index.js +0 -74
  46. package/phsics/joint.js +0 -124
  47. package/primitives/arrow.js +0 -58
  48. package/primitives/cone.js +0 -137
  49. package/primitives/cube.js +0 -59
  50. package/primitives/cylinder.js +0 -215
  51. package/primitives/index.js +0 -13
  52. package/primitives/plane.js +0 -31
  53. package/primitives/sphere.js +0 -808
  54. package/render/BRDFIntegrationMap.js +0 -4
  55. package/render/Environment.js +0 -105
  56. package/render/EnvironmentRenderer.js +0 -12
  57. package/render/FrameBuffer.js +0 -26
  58. package/render/MaterialRenderer.js +0 -28
  59. package/render/Pipeline.js +0 -83
  60. package/render/PolyListRenderer.js +0 -42
  61. package/render/RenderBuffer.js +0 -189
  62. package/render/RenderQueue.js +0 -162
  63. package/render/RenderState.js +0 -82
  64. package/render/Renderer.js +0 -202
  65. package/render/SceneAppController.js +0 -208
  66. package/render/SceneRenderer.js +0 -310
  67. package/render/Shader.js +0 -21
  68. package/render/ShadowRenderer.js +0 -159
  69. package/render/SkyCube.js +0 -77
  70. package/render/SkySphere.js +0 -94
  71. package/render/TextureMergerRenderer.js +0 -58
  72. package/render/TextureRenderer.js +0 -29
  73. package/render/webgl/FrameBuffer.js +0 -9
  74. package/render/webgl/MaterialRenderer.js +0 -99
  75. package/render/webgl/Pipeline.js +0 -82
  76. package/render/webgl/PolyListRenderer.js +0 -224
  77. package/render/webgl/RenderBuffer.js +0 -244
  78. package/render/webgl/Renderer.js +0 -239
  79. package/render/webgl/SceneRenderer.js +0 -43
  80. package/render/webgl/ShaderProgram.js +0 -350
  81. package/render/webgl/ShadowRenderer.js +0 -6
  82. package/render/webgl/SkyCube.js +0 -15
  83. package/render/webgl/SkySphere.js +0 -14
  84. package/render/webgl/State.js +0 -149
  85. package/render/webgl/TextureRenderer.js +0 -167
  86. package/render/webgl/VertexBuffer.js +0 -128
  87. package/scene/Camera.js +0 -378
  88. package/scene/Chain.js +0 -43
  89. package/scene/ChainJoint.js +0 -55
  90. package/scene/Component.js +0 -146
  91. package/scene/ComponentMap.js +0 -99
  92. package/scene/Drawable.js +0 -130
  93. package/scene/EnvironmentComponent.js +0 -123
  94. package/scene/FindNodeVisitor.js +0 -55
  95. package/scene/LightComponent.js +0 -146
  96. package/scene/MatrixState.js +0 -39
  97. package/scene/Node.js +0 -300
  98. package/scene/NodeVisitor.js +0 -12
  99. package/scene/OrbitCameraController.js +0 -407
  100. package/scene/SmoothOrbitCameraController.js +0 -92
  101. package/scene/Transform.js +0 -74
  102. package/scene/index.js +0 -24
  103. package/shaders/BasicDiffuseColorShader.js +0 -91
  104. package/shaders/BasicPBRLightShader.js +0 -238
  105. package/shaders/DebugRenderShader.js +0 -79
  106. package/shaders/DepthRenderShader.js +0 -69
  107. package/shaders/IrradianceMapCubeShader.js +0 -99
  108. package/shaders/PBRLightIBLShader.js +0 -380
  109. package/shaders/PickSelectionShader.js +0 -75
  110. package/shaders/PresentDebugFramebufferShader.js +0 -90
  111. package/shaders/PresentTextureShader.js +0 -73
  112. package/shaders/SelectionHighlightShader.js +0 -98
  113. package/shaders/ShaderFunction.js +0 -72
  114. package/shaders/SkyCubeShader.js +0 -78
  115. package/shaders/SkySphereShader.js +0 -77
  116. package/shaders/SpecularMapCubeShader.js +0 -145
  117. package/shaders/TextureMergerShader.js +0 -127
  118. package/shaders/webgl_shader_lib.js +0 -187
  119. package/tools/BinaryResourceProvider.js +0 -15
  120. package/tools/ImageResourceProvider.js +0 -65
  121. package/tools/MaterialModifier.js +0 -228
  122. package/tools/Resource.js +0 -177
  123. package/tools/ResourceProvider.js +0 -56
  124. package/tools/TextResourceProvider.js +0 -24
  125. package/tools/TextureCache.js +0 -44
  126. package/tools/TextureResourceDatabase.js +0 -87
  127. package/tools/UserAgent.js +0 -294
  128. package/tools/VideoResourceProvider.js +0 -51
  129. package/tools/WriteStrategy.js +0 -22
  130. package/tools/base64.js +0 -15
  131. package/tools/crypto.js +0 -15
  132. package/tools/endiantess.js +0 -15
  133. package/tools/image.js +0 -15
  134. package/tools/index.js +0 -33
  135. package/tools/processType.js +0 -56
@@ -1,380 +0,0 @@
1
- import Shader from "../render/Shader";
2
- import { pbrPointLight, pbrDirectionalLight, pbrAmbientLight, getShadowColor } from './webgl_shader_lib';
3
- import ShaderFunction from "./ShaderFunction";
4
- import ShaderProgram from "../render/webgl/ShaderProgram";
5
- import Mat4 from "../math/Mat4";
6
- import Vec from "../math/Vec";
7
- import { LightType } from "../base/Light";
8
- import { createNormalTexture, normalTexture, createBRDFIntegrationTexture } from "../tools/TextureResourceDatabase";
9
- import LightComponent from "../scene/LightComponent";
10
-
11
- function getShaderProgramForLights(renderer, numLights) {
12
- if (this._programs[numLights]) {
13
- return this._programs[numLights];
14
- }
15
-
16
- const vshader = ShaderFunction.GetShaderCode(`precision mediump float;
17
- attribute vec3 inPosition;
18
- attribute vec3 inNormal;
19
- attribute vec2 inTexCoord;
20
- attribute vec2 inTexCoord2;
21
- attribute vec3 inTangent;
22
-
23
- uniform mat4 uWorld;
24
- uniform mat4 uView;
25
- uniform mat4 uProj;
26
- uniform mat3 uNormMatrix;
27
-
28
- varying vec3 fragPos;
29
- varying vec3 fragNorm;
30
- varying vec2 fragTexCoord;
31
- varying vec2 fragTexCoord2;
32
- varying vec3 fragTangent;
33
- varying vec3 fragBitangent;
34
- varying vec3 fragLightPositions[${numLights}];
35
-
36
- uniform vec3 uLightPositions[${numLights}];
37
- uniform mat4 uLightTransforms[${numLights}];
38
-
39
- // Used to calculate shadow from depth texture
40
- uniform mat4 uLightPovMvp;
41
- varying vec4 fragPositionFromLightPov;
42
-
43
- `,
44
- [
45
- new ShaderFunction('void','main','',`{
46
- fragPos = (uWorld * vec4(inPosition, 1.0)).xyz;
47
- fragNorm = normalize(uNormMatrix * inNormal);
48
- fragTangent = normalize(uNormMatrix * inTangent);
49
- fragBitangent = normalize(fragNorm * fragTangent);
50
- fragTexCoord = inTexCoord;
51
- fragTexCoord2 = inTexCoord2;
52
-
53
- for (int i = 0; i < ${numLights}; ++i)
54
- {
55
- fragLightPositions[i] = (uLightTransforms[i] * vec4(uLightPositions[i], 1.0)).xyz;
56
- }
57
-
58
- fragPositionFromLightPov = uLightPovMvp * vec4(fragPos, 1.0);
59
- gl_Position = uProj * uView * uWorld * vec4(inPosition,1.0);
60
- }`)
61
- ]);
62
-
63
- const fshader = ShaderFunction.GetShaderCode(`precision mediump float;
64
- varying vec3 fragPos;
65
- varying vec3 fragNorm;
66
- varying vec2 fragTexCoord;
67
- varying vec2 fragTexCoord2;
68
- varying vec3 fragTangent;
69
- varying vec3 fragBitangent;
70
- varying vec3 fragLightPositions[${numLights}];
71
-
72
- uniform vec3 uCameraPos;
73
-
74
- uniform sampler2D uAlbedoTexture;
75
- uniform sampler2D uNormalTexture;
76
- uniform sampler2D uMetallicRoughnessHeightAOTexture;
77
-
78
- uniform vec4 uAlbedo;
79
- uniform float uMetallic;
80
- uniform float uRoughness;
81
- uniform float uLightEmission;
82
-
83
- uniform vec4 uFresnel;
84
-
85
- uniform vec2 uAlbedoScale;
86
- uniform vec2 uNormalScale;
87
- uniform vec2 uMetallicScale;
88
- uniform vec2 uRoughnessScale;
89
- uniform vec2 uLightEmissionScale;
90
-
91
- uniform float uAlphaTresshold;
92
-
93
- uniform int uLightTypes[${numLights}];
94
- uniform vec3 uLightDirections[${numLights}];
95
- uniform vec3 uLightColors[${numLights}];
96
- uniform float uLightIntensities[${numLights}];
97
-
98
-
99
- uniform samplerCube uEnvMap;
100
- uniform samplerCube uSpecularMap;
101
- uniform samplerCube uIrradianceMap;
102
- uniform sampler2D uBRDFIntegrationMap;
103
- uniform float uAmbientIntensity;
104
-
105
- uniform sampler2D uShadowMap;
106
- uniform float uShadowBias;
107
- varying vec4 fragPositionFromLightPov;
108
- uniform float uShadowStrength;
109
-
110
- uniform int uAOMap;
111
- uniform int uMetallicMap;
112
- uniform int uRoughnessMap;
113
- uniform int uLightemissionMap;
114
- `,
115
- [
116
- new ShaderFunction('void','main','',`{
117
- vec3 N = normalize(fragNorm);
118
- if (!gl_FrontFacing) {
119
- N = -N;
120
- }
121
- vec3 T = normalize(fragTangent);
122
- vec3 B = normalize(fragBitangent);
123
- mat3 TBN = mat3(T,B,N);
124
-
125
- float gamma = 1.8;
126
- vec4 albedoRGBA = texture2D(uAlbedoTexture, fragTexCoord * uAlbedoScale);
127
- vec3 albedo = albedoRGBA.rgb * uAlbedo.rgb;
128
- albedo = pow(albedo, vec3(gamma));
129
- float alpha = albedoRGBA.a * uAlbedo.a;
130
- vec3 normal = normalize(texture2D(uNormalTexture, fragTexCoord * uNormalScale).rgb * 2.0 - 1.0);
131
-
132
- vec2 metallicUV = fragTexCoord;
133
- vec2 roughnessUV = fragTexCoord;
134
- vec2 lightEmissionUV = fragTexCoord;
135
- if (uMetallicMap == 1) {
136
- metallicUV = fragTexCoord2;
137
- }
138
- if (uRoughnessMap == 1) {
139
- roughnessUV = fragTexCoord2;
140
- }
141
- if (uLightemissionMap == 1) {
142
- lightEmissionUV = fragTexCoord2;
143
- }
144
- float metallic = texture2D(uMetallicRoughnessHeightAOTexture, metallicUV * uMetallicScale).r * uMetallic;
145
- float roughness = max(texture2D(uMetallicRoughnessHeightAOTexture, roughnessUV * uRoughnessScale).g * uRoughness, 0.01);
146
- float lightEmission = min(texture2D(uMetallicRoughnessHeightAOTexture, lightEmissionUV * uLightEmissionScale).b + uLightEmission, 1.0);
147
- vec3 fresnel = uFresnel.rgb;
148
-
149
- if (alpha < uAlphaTresshold) {
150
- discard;
151
- }
152
- else {
153
- N = normalize(TBN * normal);
154
- vec3 V = normalize(uCameraPos - fragPos);
155
-
156
- vec3 shadowColor = getShadowColor(fragPositionFromLightPov, uShadowMap, uShadowBias, uShadowStrength);
157
-
158
- vec3 Lo = vec3(0.0);
159
- for (int i = 0; i < ${numLights}; ++i)
160
- {
161
- float lightIntensity = uLightIntensities[i];
162
- if (uLightTypes[i] == ${ LightType.POINT }) {
163
- Lo += pbrPointLight(
164
- fragLightPositions[i], uLightColors[i] * lightIntensity, fragPos, N, V,
165
- albedo, roughness, metallic, fresnel);
166
- }
167
- else if (uLightTypes[i] == ${ LightType.DIRECTIONAL }) {
168
-
169
- vec3 dirColor = pbrDirectionalLight(
170
- -uLightDirections[i], uLightColors[i] * lightIntensity, fragPos, N, V,
171
- albedo, roughness, metallic, fresnel, shadowColor);
172
-
173
- Lo += clamp(dirColor + vec3(lightEmission) * albedo, 0.0, 1.0);
174
- }
175
- }
176
-
177
- vec3 ambient = pbrAmbientLight(
178
- fragPos, N, V, albedo, metallic, roughness, uIrradianceMap, uSpecularMap, uEnvMap, uBRDFIntegrationMap, fresnel, shadowColor
179
- ) * uAmbientIntensity;
180
-
181
- vec2 aoUV = fragTexCoord;
182
- if (uAOMap == 1) {
183
- aoUV = fragTexCoord2;
184
- }
185
- float ao = texture2D(uMetallicRoughnessHeightAOTexture, aoUV).a;
186
- vec3 color = (ambient + Lo) * ao;
187
-
188
- color = pow(color, vec3(1.0 / gamma));
189
-
190
- gl_FragColor = vec4(color,alpha);
191
- }
192
- }`, [pbrPointLight, pbrDirectionalLight, pbrAmbientLight, getShadowColor])
193
- ]);
194
-
195
- this._programs[numLights] = ShaderProgram.Create(renderer.gl,"PBRLightIBL",vshader,fshader);
196
- return this._programs[numLights];
197
- }
198
- export default class PBRLightIBLShader extends Shader {
199
- constructor(renderer) {
200
- super(renderer);
201
-
202
- this._lights = [];
203
- this._lightTransforms = [];
204
-
205
- if (renderer.typeId !== "WebGL") {
206
- throw Error("PresentTextureShader is only compatible with WebGL renderer");
207
- }
208
-
209
- this._programs = {};
210
- }
211
-
212
- async load() {
213
- await createNormalTexture(this.renderer);
214
-
215
- this._brdfIntegrationTexture = await createBRDFIntegrationTexture(this.renderer);
216
- }
217
-
218
- set cameraPosition(p) {
219
- this._cameraPosition = p;
220
- }
221
-
222
- set environment(env) {
223
- this._environment = env;
224
- }
225
-
226
- get environmentMap() {
227
- return this._environment.environmentMap;
228
- }
229
-
230
- get specularMap() {
231
- return this._environment.specularMap;
232
- }
233
-
234
- get irradianceMap() {
235
- return this._environment.irradianceMap;
236
- }
237
-
238
- set lights(l) {
239
- if (!l.length) {
240
- throw new Error("BasicPBRLightShader: Invalid light array set.");
241
- }
242
- this._lights = l;
243
- this._lightTypes = [];
244
- this._lightPositions = [];
245
- this._lightDirections = [];
246
- this._lightColors = [];
247
- this._lightIntensities = [];
248
- this._lights.forEach((light,i) => {
249
- this._lightTypes.push(light.type);
250
- const trx = this._lightTransforms[i];
251
- const rot = trx && Mat4.GetRotation(trx);
252
- const position = new Vec(light.position);
253
- const direction = new Vec(light.direction);
254
- this._lightPositions.push(trx ? trx.multVector(position).xyz : position);
255
- this._lightDirections.push(rot ? rot.multVector(direction).xyz.normalize() : direction);
256
- this._lightColors.push(new Vec(light.color));
257
- this._lightIntensities.push(light.intensity);
258
- });
259
- this._program = getShaderProgramForLights.apply(this, [this.renderer, this._lights.length]);
260
- }
261
-
262
- get lights() {
263
- return this._lights;
264
- }
265
-
266
- set lightTransforms(lt) {
267
- this._lightTransforms = lt;
268
- }
269
-
270
- get lightTransforms() {
271
- return this._lightTransforms;
272
- }
273
-
274
- updateLight(light,index) {
275
- if (light >= this._lights.length) {
276
- throw new Error("BasicPBRLightShader: Invalid light index updating light data");
277
- }
278
- this._lightTypes[index] = light.type;
279
- this._lightPositions[index] = new Vec(light.position);
280
- this._lightDirections[index] = new Vec(light.direction);
281
- this._lightColors[index] = new Vec(light.color);
282
- this._lightIntensities[index] = light.intensity;
283
- }
284
-
285
- updateLights(lights) {
286
- if (this._lights.length !== lights.length) {
287
- this.lights = lights;
288
- }
289
- else {
290
- lights.forEach((l,i) => this.updateLight(l,i));
291
- }
292
- }
293
-
294
- setup(plistRenderer,materialRenderer,modelMatrix,viewMatrix,projectionMatrix) {
295
- if (!this._program) {
296
- throw new Error("BasicPBRLightShader: lights array not specified");
297
- }
298
-
299
- const material = materialRenderer.material;
300
- materialRenderer.mergeTextures();
301
- this.renderer.state.shaderProgram = this._program;
302
-
303
- const normMatrix = Mat4.GetNormalMatrix(modelMatrix);
304
- this._program.bindMatrix('uNormMatrix', normMatrix);
305
- this._program.bindMatrix('uWorld', modelMatrix);
306
- this._program.bindMatrix('uView', viewMatrix);
307
- this._program.bindMatrix('uProj', projectionMatrix);
308
-
309
- if (!this._cameraPosition) {
310
- console.warn("Serious performance warning: camera position not set in BasicPBRLightShader. Extracting the camera position from the view matrix involves inverting the matrix.");
311
- this._program.bindVector('uCameraPos',Mat4.GetPosition(Mat4.GetInverted(viewMatrix)));
312
- }
313
- else {
314
- this._program.bindVector('uCameraPos',this._cameraPosition);
315
- }
316
-
317
- materialRenderer.bindTexture(this._program, 'diffuse', 'uAlbedoTexture', 0);
318
- materialRenderer.bindTexture(this._program, 'normal', 'uNormalTexture', 1, normalTexture(this.renderer));
319
- materialRenderer.bindMetallicRoughnessHeightAOTexture(this._program, 'uMetallicRoughnessHeightAOTexture', 2);
320
- this._program.uniform1f('uAlphaTresshold', material.alphaCutoff);
321
-
322
- materialRenderer.bindColor(this._program, 'diffuse', 'uAlbedo');
323
- materialRenderer.bindValue(this._program, 'metallic', 'uMetallic');
324
- materialRenderer.bindValue(this._program, 'roughness', 'uRoughness');
325
- materialRenderer.bindValue(this._program, 'lightEmission', 'uLightEmission', 0);
326
-
327
- this._program.uniform1i('uAOMap', material.ambientOcclussionUV);
328
- this._program.uniform1i('uMetallicMap', material.metallicChannel);
329
- this._program.uniform1i('uRoughnessMap', material.roughnessChannel);
330
- this._program.uniform1i('uLightemissionMap', material.lightEmissionChannel);
331
-
332
- this._program.bindVector("uAlbedoScale", material.diffuseScale);
333
- this._program.bindVector("uNormalScale", material.normalScale);
334
- this._program.bindVector("uMetallicScale", material.metallicScale);
335
- this._program.bindVector("uRoughnessScale", material.roughnessScale);
336
- this._program.bindVector("uLightEmissionScale", material.lightEmissionScale);
337
- this._program.bindVector("uFresnel", material.fresnel);
338
-
339
- this._program.bindTexture("uIrradianceMap", this.renderer.factory.texture(this.irradianceMap), 3);
340
- this._program.bindTexture("uSpecularMap", this.renderer.factory.texture(this.specularMap), 4);
341
- this._program.bindTexture("uEnvMap", this.renderer.factory.texture(this.environmentMap), 5);
342
- this._program.bindTexture("uBRDFIntegrationMap", this.renderer.factory.texture(this._brdfIntegrationTexture), 6);
343
-
344
- // TODO: Get the ambient intensity from environment
345
- this._program.uniform1f("uAmbientIntensity", 1.0);
346
-
347
- let shadowLight = null;
348
- this._lights.forEach((light,i) => {
349
- if (light._depthTexture) {
350
- shadowLight = light;
351
- }
352
- this._program.uniform1i(`uLightTypes[${i}]`, this._lightTypes[i]);
353
- this._program.bindVector(`uLightPositions[${i}]`, this._lightPositions[i]);
354
- this._program.bindVector(`uLightDirections[${i}]`, this._lightDirections[i]);
355
- this._program.bindVector(`uLightColors[${i}]`, this._lightColors[i].rgb);
356
- this._program.uniform1f(`uLightIntensities[${i}]`, this._lightIntensities[i]);
357
- this._program.bindMatrix(`uLightTransforms[${i}]`, this._lightTransforms[i]);
358
- });
359
-
360
- if (shadowLight) {
361
- this._program.bindTexture("uShadowMap", this.renderer.factory.texture(shadowLight.depthTexture), 7);
362
- const projectionViewMatrix = Mat4.Mult(shadowLight.projection, shadowLight.viewMatrix);
363
- this._program.bindMatrix("uLightPovMvp", projectionViewMatrix);
364
- this._program.uniform1f("uShadowBias", shadowLight.shadowBias * 30);
365
- this._program.uniform1f("uShadowStrength", shadowLight.shadowStrength);
366
- }
367
-
368
- this._program.bindAttribs(plistRenderer, {
369
- position: "inPosition",
370
- normal: "inNormal",
371
- tex0: "inTexCoord",
372
- tex1: "inTexCoord2",
373
- tangent: "inTangent"
374
- });
375
- }
376
-
377
- destroy() {
378
- ShaderProgram.Delete(this._program);
379
- }
380
- }
@@ -1,75 +0,0 @@
1
- import Shader from "../render/Shader";
2
- import ShaderProgram from "../render/webgl/ShaderProgram";
3
-
4
- const g_code = {
5
- webgl: {
6
- vertex: `precision mediump float;
7
-
8
- attribute vec3 vertPosition;
9
-
10
- uniform mat4 mWorld;
11
- uniform mat4 mView;
12
- uniform mat4 mProj;
13
-
14
- void main() {
15
- gl_Position = mProj * mView * mWorld * vec4(vertPosition, 1.0);
16
- }`,
17
-
18
- fragment: `precision mediump float;
19
-
20
- uniform vec4 uPickColor;
21
- uniform bool uSelected;
22
-
23
- void main() {
24
- if (uSelected) {
25
- gl_FragColor = vec4(uPickColor);
26
- }
27
- else {
28
- discard;
29
- }
30
- }`
31
- }
32
- }
33
-
34
- export default class PickSelectionShader extends Shader {
35
- constructor(renderer) {
36
- super(renderer);
37
-
38
- if (renderer.typeId !== "WebGL") {
39
- throw Error("PickSelectionShdaer is only compatible with WebGL renderer");
40
- }
41
- }
42
-
43
- async load() {
44
- const { gl } = this.renderer;
45
-
46
- this._program = new ShaderProgram(gl, "PickSelectionShader");
47
- this._program.attachVertexSource(g_code.webgl.vertex);
48
- this._program.attachFragmentSource(g_code.webgl.fragment);
49
- this._program.link();
50
-
51
- this._forceDraw = true;
52
- }
53
-
54
- set forceDraw(d) {
55
- this._forceDraw = d;
56
- }
57
-
58
- get forceDraw() {
59
- return this._forceDraw;
60
- }
61
-
62
- setup(plistRenderer, materialRenderer, modelMatrix, viewMatrix, projectionMatrix) {
63
- this.renderer.state.shaderProgram = this._program;
64
- this._program.uniformMatrix4fv('mWorld', false, modelMatrix);
65
- this._program.uniformMatrix4fv('mView', false, viewMatrix);
66
- this._program.uniformMatrix4fv('mProj', false, projectionMatrix);
67
- this._program.uniform1i('uSelected', this._forceDraw || plistRenderer.polyList.isSelected);
68
-
69
- const { polyList } = plistRenderer;
70
- this._program.uniform4fv('uPickColor', polyList.colorCode);
71
-
72
- this._program.positionAttribPointer(plistRenderer.positionAttribParams("vertPosition"));
73
- }
74
- }
75
-
@@ -1,90 +0,0 @@
1
-
2
- import Texture, { TextureTargetName } from '../base/Texture';
3
- import Shader from '../render/Shader';
4
- import ShaderProgram from '../render/webgl/ShaderProgram';
5
- import ShaderFunction from './ShaderFunction';
6
- import { applyConvolution } from './webgl_shader_lib';
7
- import Vec from '../math/Vec';
8
-
9
- const g_code = {
10
- webgl: {
11
- vertex: `precision mediump float;
12
-
13
- attribute vec3 position;
14
- attribute vec2 texCoord;
15
-
16
- varying vec2 fragTexCoord;
17
-
18
- void main() {
19
- fragTexCoord = texCoord;
20
- gl_Position = vec4(position, 1.0);
21
- }`,
22
-
23
- fragment: ShaderFunction.GetShaderCode(`precision mediump float;
24
- varying vec2 fragTexCoord;
25
-
26
- uniform sampler2D uTexture;
27
- `,
28
- [
29
- new ShaderFunction('void','main','',`{
30
- vec3 color = texture2D(uTexture, fragTexCoord).rgb;
31
- if (color.r!=0.0 || color.g!=0.0 || color.b!=0.0) {
32
- gl_FragColor = vec4(color, 1.0);
33
- }
34
- else {
35
- discard;
36
- }
37
- }`)
38
- ])
39
- }
40
- }
41
-
42
- export default class PresentDebugFramebufferShader extends Shader {
43
- constructor(renderer) {
44
- super(renderer);
45
-
46
- if (renderer.typeId !== "WebGL") {
47
- throw Error("PresentDebugFramebufferShader is only compatible with WebGL renderer");
48
- }
49
- }
50
-
51
- async load() {
52
- const { gl } = this.renderer;
53
-
54
- this._program = new ShaderProgram(gl, "PresentDebugFramebufferShader");
55
- this._program.attachVertexSource(g_code.webgl.vertex);
56
- this._program.attachFragmentSource(g_code.webgl.fragment);
57
- this._program.link();
58
-
59
- this._borderWidth = 3;
60
- this._borderColor = new Vec([0.0, 0.7, 1, 1.0]);
61
- this._convMatrix = [
62
- 0, 1, 0,
63
- 1,-4, 1,
64
- 0, 1, 0
65
- ];
66
- }
67
-
68
- setup(plistRenderer, materialRenderer, modelMatrix, viewMatrix, projectionMatrix) {
69
- const { gl, viewport } = this.renderer;
70
-
71
- this.renderer.state.shaderProgram = this._program;
72
-
73
- gl.activeTexture(gl.TEXTURE0);
74
- this._program.uniform1i('uTexture', 0);
75
-
76
- const material = materialRenderer.material;
77
- if (material.diffuse instanceof Texture) {
78
- const webglTexture = materialRenderer.getTextureRenderer('diffuse').getApiObject();
79
- const target = TextureTargetName[material.diffuse.target];
80
- gl.bindTexture(gl[target], webglTexture);
81
-
82
- }
83
- else {
84
- throw new Error("PresentDebugFramebufferShader: invalid material setup. The diffuse material attribute must to be a texture");
85
- }
86
-
87
- this._program.positionAttribPointer(plistRenderer.positionAttribParams("position"));
88
- this._program.texCoordAttribPointer(plistRenderer.texCoord0AttribParams("texCoord"));
89
- }
90
- }
@@ -1,73 +0,0 @@
1
-
2
- import Texture, { TextureTargetName } from '../base/Texture';
3
- import Shader from '../render/Shader';
4
- import ShaderProgram from '../render/webgl/ShaderProgram';
5
-
6
- const g_code = {
7
- webgl: {
8
- vertex: `precision mediump float;
9
-
10
- attribute vec3 position;
11
- attribute vec2 texCoord;
12
-
13
- varying vec2 fragTexCoord;
14
-
15
- void main() {
16
- fragTexCoord = texCoord;
17
- gl_Position = vec4(position, 1.0);
18
- }`,
19
-
20
- fragment: `precision mediump float;
21
-
22
- varying vec2 fragTexCoord;
23
-
24
- uniform sampler2D uTexture;
25
-
26
- void main() {
27
- vec4 texColor = texture2D(uTexture, fragTexCoord);
28
- gl_FragColor = vec4(texColor.rgb, 1.0);
29
- }`
30
- }
31
- }
32
-
33
- export default class PresentTextureShader extends Shader {
34
- constructor(renderer) {
35
- super(renderer);
36
-
37
- if (renderer.typeId !== "WebGL") {
38
- throw Error("PresentTextureShader is only compatible with WebGL renderer");
39
- }
40
- }
41
-
42
- async load() {
43
- const { gl } = this.renderer;
44
-
45
- this._program = new ShaderProgram(gl, "DefaultPresentTextureShader");
46
- this._program.attachVertexSource(g_code.webgl.vertex);
47
- this._program.attachFragmentSource(g_code.webgl.fragment);
48
- this._program.link();
49
- }
50
-
51
- setup(plistRenderer, materialRenderer, modelMatrix, viewMatrix, projectionMatrix) {
52
- const { gl } = this.renderer;
53
-
54
- this.renderer.state.shaderProgram = this._program;
55
-
56
- gl.activeTexture(gl.TEXTURE0);
57
- this._program.uniform1i('uTexture', 0);
58
-
59
- const material = materialRenderer.material;
60
- if (material.diffuse instanceof Texture) {
61
- const webglTexture = materialRenderer.getTextureRenderer('diffuse').getApiObject();
62
- const target = TextureTargetName[material.diffuse.target];
63
- gl.bindTexture(gl[target], webglTexture);
64
-
65
- }
66
- else {
67
- throw new Error("PresentTextureShader: invalid material setup. The diffuse material attribute must to be a texture");
68
- }
69
-
70
- this._program.positionAttribPointer(plistRenderer.positionAttribParams("position"));
71
- this._program.texCoordAttribPointer(plistRenderer.texCoord0AttribParams("texCoord"));
72
- }
73
- }