bg2e-js 2.0.0 → 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 (132) 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.js +0 -32
  5. package/app/Canvas.js +0 -98
  6. package/app/EventBase.js +0 -8
  7. package/app/KeyboardEvent.js +0 -51
  8. package/app/MainLoop.js +0 -251
  9. package/app/MouseEvent.js +0 -77
  10. package/app/TouchEvent.js +0 -15
  11. package/base/Color.js +0 -131
  12. package/base/Environment.js +0 -78
  13. package/base/Light.js +0 -176
  14. package/base/Material.js +0 -619
  15. package/base/PolyList.js +0 -336
  16. package/base/Texture.js +0 -545
  17. package/db/Bg2LoaderPlugin.js +0 -113
  18. package/db/DBPluginApi.js +0 -40
  19. package/db/Loader.js +0 -91
  20. package/db/LoaderPlugin.js +0 -26
  21. package/db/MtlParser.js +0 -7
  22. package/db/ObjLoaderPlugin.js +0 -51
  23. package/db/ObjParser.js +0 -233
  24. package/db/ObjWriterPlugin.js +0 -18
  25. package/db/VitscnjLoaderPlugin.js +0 -87
  26. package/db/Writer.js +0 -49
  27. package/db/WriterPlugin.js +0 -20
  28. package/debug/DebugRenderer.js +0 -138
  29. package/debug/WebGLTextureViewer.js +0 -67
  30. package/manipulation/SelectionBuffer.js +0 -65
  31. package/manipulation/SelectionHighlight.js +0 -69
  32. package/manipulation/SelectionIdAssignVisitor.js +0 -86
  33. package/manipulation/SelectionManager.js +0 -134
  34. package/manipulation/SelectionMode.js +0 -6
  35. package/math/Mat3.js +0 -248
  36. package/math/Mat4.js +0 -694
  37. package/math/MatrixStrategy.js +0 -23
  38. package/math/Quat.js +0 -60
  39. package/math/Vec.js +0 -728
  40. package/math/constants.js +0 -44
  41. package/math/functions.js +0 -104
  42. package/math/index.js +0 -74
  43. package/phsics/joint.js +0 -124
  44. package/primitives/arrow.js +0 -58
  45. package/primitives/cone.js +0 -137
  46. package/primitives/cube.js +0 -59
  47. package/primitives/cylinder.js +0 -215
  48. package/primitives/index.js +0 -13
  49. package/primitives/plane.js +0 -31
  50. package/primitives/sphere.js +0 -808
  51. package/render/BRDFIntegrationMap.js +0 -4
  52. package/render/Environment.js +0 -105
  53. package/render/EnvironmentRenderer.js +0 -12
  54. package/render/FrameBuffer.js +0 -26
  55. package/render/MaterialRenderer.js +0 -28
  56. package/render/Pipeline.js +0 -83
  57. package/render/PolyListRenderer.js +0 -42
  58. package/render/RenderBuffer.js +0 -189
  59. package/render/RenderQueue.js +0 -162
  60. package/render/RenderState.js +0 -82
  61. package/render/Renderer.js +0 -202
  62. package/render/SceneAppController.js +0 -208
  63. package/render/SceneRenderer.js +0 -310
  64. package/render/Shader.js +0 -21
  65. package/render/ShadowRenderer.js +0 -159
  66. package/render/SkyCube.js +0 -77
  67. package/render/SkySphere.js +0 -94
  68. package/render/TextureMergerRenderer.js +0 -58
  69. package/render/TextureRenderer.js +0 -29
  70. package/render/webgl/FrameBuffer.js +0 -9
  71. package/render/webgl/MaterialRenderer.js +0 -99
  72. package/render/webgl/Pipeline.js +0 -82
  73. package/render/webgl/PolyListRenderer.js +0 -224
  74. package/render/webgl/RenderBuffer.js +0 -244
  75. package/render/webgl/Renderer.js +0 -239
  76. package/render/webgl/SceneRenderer.js +0 -43
  77. package/render/webgl/ShaderProgram.js +0 -348
  78. package/render/webgl/ShadowRenderer.js +0 -6
  79. package/render/webgl/SkyCube.js +0 -15
  80. package/render/webgl/SkySphere.js +0 -14
  81. package/render/webgl/State.js +0 -149
  82. package/render/webgl/TextureRenderer.js +0 -167
  83. package/render/webgl/VertexBuffer.js +0 -128
  84. package/scene/Camera.js +0 -378
  85. package/scene/Chain.js +0 -43
  86. package/scene/ChainJoint.js +0 -55
  87. package/scene/Component.js +0 -146
  88. package/scene/ComponentMap.js +0 -99
  89. package/scene/Drawable.js +0 -130
  90. package/scene/EnvironmentComponent.js +0 -123
  91. package/scene/FindNodeVisitor.js +0 -55
  92. package/scene/LightComponent.js +0 -146
  93. package/scene/MatrixState.js +0 -39
  94. package/scene/Node.js +0 -300
  95. package/scene/NodeVisitor.js +0 -12
  96. package/scene/OrbitCameraController.js +0 -407
  97. package/scene/SmoothOrbitCameraController.js +0 -92
  98. package/scene/Transform.js +0 -74
  99. package/scene/index.js +0 -24
  100. package/shaders/BasicDiffuseColorShader.js +0 -91
  101. package/shaders/BasicPBRLightShader.js +0 -238
  102. package/shaders/DebugRenderShader.js +0 -79
  103. package/shaders/DepthRenderShader.js +0 -69
  104. package/shaders/IrradianceMapCubeShader.js +0 -99
  105. package/shaders/PBRLightIBLShader.js +0 -380
  106. package/shaders/PickSelectionShader.js +0 -75
  107. package/shaders/PresentDebugFramebufferShader.js +0 -90
  108. package/shaders/PresentTextureShader.js +0 -73
  109. package/shaders/SelectionHighlightShader.js +0 -98
  110. package/shaders/ShaderFunction.js +0 -72
  111. package/shaders/SkyCubeShader.js +0 -78
  112. package/shaders/SkySphereShader.js +0 -77
  113. package/shaders/SpecularMapCubeShader.js +0 -145
  114. package/shaders/TextureMergerShader.js +0 -127
  115. package/shaders/webgl_shader_lib.js +0 -187
  116. package/tools/BinaryResourceProvider.js +0 -15
  117. package/tools/ImageResourceProvider.js +0 -65
  118. package/tools/MaterialModifier.js +0 -228
  119. package/tools/Resource.js +0 -177
  120. package/tools/ResourceProvider.js +0 -56
  121. package/tools/TextResourceProvider.js +0 -24
  122. package/tools/TextureCache.js +0 -44
  123. package/tools/TextureResourceDatabase.js +0 -87
  124. package/tools/UserAgent.js +0 -294
  125. package/tools/VideoResourceProvider.js +0 -51
  126. package/tools/WriteStrategy.js +0 -22
  127. package/tools/base64.js +0 -15
  128. package/tools/crypto.js +0 -15
  129. package/tools/endiantess.js +0 -15
  130. package/tools/image.js +0 -15
  131. package/tools/index.js +0 -33
  132. package/tools/processType.js +0 -56
@@ -1,238 +0,0 @@
1
- import Shader from "../render/Shader";
2
- import { pbrPointLight, pbrDirectionalLight } 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 } from "../tools/TextureResourceDatabase";
9
-
10
- function getShaderProgramForLights(renderer, numLights) {
11
- if (this._programs[numLights]) {
12
- return this._programs[numLights];
13
- }
14
-
15
- const vshader = ShaderFunction.GetShaderCode(`precision mediump float;
16
- attribute vec3 inPosition;
17
- attribute vec3 inNormal;
18
- attribute vec2 inTexCoord;
19
- attribute vec3 inTangent;
20
-
21
- uniform mat4 uWorld;
22
- uniform mat4 uView;
23
- uniform mat4 uProj;
24
- uniform mat3 uNormMatrix;
25
-
26
- varying vec3 fragPos;
27
- varying vec3 fragNorm;
28
- varying vec2 fragTexCoord;
29
- varying vec3 fragTangent;
30
- varying vec3 fragBitangent;
31
- `,
32
- [
33
- new ShaderFunction('void','main','',`{
34
- fragPos = (uWorld * vec4(inPosition, 1.0)).xyz;
35
- fragNorm = normalize(uNormMatrix * inNormal);
36
- fragTangent = normalize(uNormMatrix * inTangent);
37
- fragBitangent = normalize(fragNorm * fragTangent);
38
- fragTexCoord = inTexCoord;
39
- gl_Position = uProj * uView * uWorld * vec4(inPosition,1.0);
40
- }`)
41
- ]);
42
-
43
- const fshader = ShaderFunction.GetShaderCode(`precision mediump float;
44
- varying vec3 fragPos;
45
- varying vec3 fragNorm;
46
- varying vec2 fragTexCoord;
47
- varying vec3 fragTangent;
48
- varying vec3 fragBitangent;
49
-
50
- uniform vec3 uCameraPos;
51
-
52
- uniform sampler2D uAlbedoTexture;
53
- uniform sampler2D uNormalTexture;
54
- uniform sampler2D uMetallicTexture;
55
- uniform sampler2D uRoughnessTexture;
56
-
57
- uniform vec4 uAlbedo;
58
- uniform float uMetallic;
59
- uniform float uRoughness;
60
-
61
- uniform vec2 uAlbedoScale;
62
- uniform vec2 uNormalScale;
63
- uniform vec2 uMetallicScale;
64
- uniform vec2 uRoughnessScale;
65
-
66
- uniform int uLightTypes[${numLights}];
67
- uniform vec3 uLightPositions[${numLights}];
68
- uniform vec3 uLightDirections[${numLights}];
69
- uniform vec3 uLightColors[${numLights}];
70
- uniform float uLightIntensities[${numLights}];
71
- `,
72
- [
73
- new ShaderFunction('void','main','',`{
74
- vec3 N = normalize(fragNorm);
75
- if (!gl_FrontFacing) {
76
- N = -N;
77
- }
78
- vec3 T = normalize(fragTangent);
79
- vec3 B = normalize(fragBitangent);
80
- mat3 TBN = mat3(T,B,N);
81
-
82
- vec3 albedo = texture2D(uAlbedoTexture, fragTexCoord * uAlbedoScale).rgb * uAlbedo.rgb;
83
- vec3 normal = texture2D(uNormalTexture, fragTexCoord * uNormalScale).rgb * 2.0 - 1.0;
84
- float metallic = texture2D(uMetallicTexture, fragTexCoord * uMetallicScale).r * uMetallic;
85
- float roughness = max(texture2D(uRoughnessTexture, fragTexCoord * uRoughnessScale).r * uRoughness, 0.05);
86
-
87
- N = normalize(TBN * normal);
88
- vec3 V = normalize(uCameraPos - fragPos);
89
-
90
- vec3 Lo = vec3(0.0);
91
- for (int i = 0; i < ${numLights}; ++i)
92
- {
93
- if (uLightTypes[i] == ${ LightType.POINT }) {
94
- Lo += pbrPointLight(
95
- uLightPositions[i], uLightColors[i] * uLightIntensities[i], fragPos, N, V,
96
- albedo, roughness, metallic);
97
- }
98
- else if (uLightTypes[i] == ${ LightType.DIRECTIONAL }) {
99
- Lo += pbrDirectionalLight(
100
- uLightDirections[i], uLightColors[i] * uLightIntensities[i], fragPos, N, V,
101
- albedo, roughness, metallic);
102
- }
103
- }
104
-
105
- vec3 ambient = vec3(0.03) * albedo;
106
- vec3 color = ambient + Lo;
107
- color = color / (color + vec3(1.0));
108
- color = pow(color, vec3(1.0/2.2));
109
-
110
- gl_FragColor = vec4(color,1.0);
111
- }`, [pbrPointLight, pbrDirectionalLight])
112
- ]);
113
-
114
- this._programs[numLights] = ShaderProgram.Create(renderer.gl,"PBRBasicLight",vshader,fshader);
115
- return this._programs[numLights];
116
- }
117
- export default class BasicPBRLightShader extends Shader {
118
- constructor(renderer) {
119
- super(renderer);
120
-
121
- this._lights = [];
122
-
123
- if (renderer.typeId !== "WebGL") {
124
- throw Error("PresentTextureShader is only compatible with WebGL renderer");
125
- }
126
-
127
- this._programs = {};
128
- }
129
-
130
- async load() {
131
- await createNormalTexture(this.renderer);
132
- }
133
-
134
- set cameraPosition(p) {
135
- this._cameraPosition = p;
136
- }
137
-
138
- set lights(l) {
139
- if (!l.length) {
140
- throw new Error("BasicPBRLightShader: Invalid light array set.");
141
- }
142
- this._lights = l;
143
- this._lightTypes = [];
144
- this._lightPositions = [];
145
- this._lightDirections = [];
146
- this._lightColors = [];
147
- this._lightIntensities = [];
148
- this._lights.forEach(light => {
149
- this._lightTypes.push(light.type);
150
- this._lightPositions.push(new Vec(light.position));
151
- this._lightDirections.push(new Vec(light.direction));
152
- this._lightColors.push(new Vec(light.color));
153
- this._lightIntensities.push(light.intensity);
154
- });
155
- this._program = getShaderProgramForLights.apply(this, [this.renderer, this._lights.length]);
156
- }
157
-
158
- get lights() {
159
- return this._lights;
160
- }
161
-
162
- updateLight(light,index) {
163
- if (light >= this._lights.length) {
164
- throw new Error("BasicPBRLightShader: Invalid light index updating light data");
165
- }
166
- this._lightTypes[index] = light.type;
167
- this._lightPositions[index] = new Vec(light.position);
168
- this._lightDirections[index] = new Vec(light.direction);
169
- this._lightColors[index] = new Vec(light.color);
170
- this._lightIntensities[index] = light.intensity;
171
- }
172
-
173
- updateLights(lights) {
174
- if (this._lights.length !== lights.length) {
175
- this.lights = lights;
176
- }
177
- else {
178
- lights.forEach((l,i) => this.updateLight(l,i));
179
- }
180
- }
181
-
182
- setup(plistRenderer,materialRenderer,modelMatrix,viewMatrix,projectionMatrix) {
183
- if (!this._program) {
184
- throw new Error("BasicPBRLightShader: lights array not specified");
185
- }
186
-
187
- const material = materialRenderer.material;
188
- this.renderer.state.shaderProgram = this._program;
189
-
190
- const normMatrix = Mat4.GetNormalMatrix(modelMatrix);
191
- this._program.bindMatrix('uNormMatrix', normMatrix);
192
- this._program.bindMatrix('uWorld', modelMatrix);
193
- this._program.bindMatrix('uView', viewMatrix);
194
- this._program.bindMatrix('uProj', projectionMatrix);
195
-
196
- if (!this._cameraPosition) {
197
- console.warn("Serious performance warning: camera position not set in BasicPBRLightShader. Extracting the camera position from the view matrix involves inverting the matrix.");
198
- this._program.bindVector('uCameraPos',Mat4.GetPosition(Mat4.GetInverted(viewMatrix)));
199
- }
200
- else {
201
- this._program.bindVector('uCameraPos',this._cameraPosition);
202
- }
203
-
204
- materialRenderer.bindTexture(this._program, 'diffuse', 'uAlbedoTexture', 0);
205
- materialRenderer.bindTexture(this._program, 'normal', 'uNormalTexture', 1, normalTexture(this.renderer));
206
- materialRenderer.bindTexture(this._program, 'metallic', 'uMetallicTexture', 2);
207
- materialRenderer.bindTexture(this._program, 'roughness', 'uRoughnessTexture', 3);
208
-
209
- materialRenderer.bindColor(this._program, 'diffuse', 'uAlbedo');
210
- materialRenderer.bindValue(this._program, 'metallic', 'uMetallic');
211
- materialRenderer.bindValue(this._program, 'roughness', 'uRoughness');
212
-
213
-
214
- this._program.bindVector("uAlbedoScale", material.diffuseScale);
215
- this._program.bindVector("uNormalScale", material.normalScale);
216
- this._program.bindVector("uMetallicScale", material.metallicScale);
217
- this._program.bindVector("uRoughnessScale", material.roughnessScale);
218
-
219
- this._lights.forEach((light,i) => {
220
- this._program.uniform1i(`uLightTypes[${i}]`, this._lightTypes[i]);
221
- this._program.bindVector(`uLightPositions[${i}]`, this._lightPositions[i]);
222
- this._program.bindVector(`uLightDirections[${i}]`, this._lightDirections[i]);
223
- this._program.bindVector(`uLightColors[${i}]`, this._lightColors[i].rgb);
224
- this._program.uniform1f(`uLightIntensities[${i}]`, this._lightIntensities[i]);
225
- });
226
-
227
- this._program.bindAttribs(plistRenderer, {
228
- position: "inPosition",
229
- normal: "inNormal",
230
- tex0: "inTexCoord",
231
- tangent: "inTangent"
232
- });
233
- }
234
-
235
- destroy() {
236
- ShaderProgram.Delete(this._program);
237
- }
238
- }
@@ -1,79 +0,0 @@
1
- import Vec from "../math/Vec";
2
- import Shader from "../render/Shader";
3
- import ShaderFunction from "./ShaderFunction";
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
- uniform mat4 uModelMatrix;
14
- uniform mat4 uViewMatrix;
15
- uniform mat4 uProjMatrix;
16
-
17
- varying vec2 fragTexCoord;
18
-
19
- void main() {
20
- fragTexCoord = texCoord;
21
- gl_Position = uProjMatrix * uViewMatrix * uModelMatrix * vec4(position, 1.0);
22
- }`,
23
-
24
- fragment: ShaderFunction.GetShaderCode(
25
- `precision mediump float;
26
-
27
- varying vec2 fragTexCoord;
28
- uniform vec4 uColor;
29
- uniform sampler2D uTexture;
30
- `,
31
- [
32
- new ShaderFunction('void','main','',`{
33
- vec4 color = texture2D(uTexture, fragTexCoord);
34
- gl_FragColor = uColor;
35
- }`)
36
- ])
37
- }
38
- }
39
-
40
- export default class DebugRenderShader extends Shader {
41
- constructor(renderer) {
42
- super(renderer);
43
-
44
- if (renderer.typeId !== "WebGL") {
45
- throw Error("DebugRenderShader is only compatible with WebGL renderer");
46
- }
47
- }
48
-
49
- async load() {
50
- const { gl } = this.renderer;
51
-
52
- this._program = new ShaderProgram(gl, "DebugRenderShader");
53
- this._program.attachVertexSource(g_code.webgl.vertex);
54
- this._program.attachFragmentSource(g_code.webgl.fragment);
55
- this._program.link();
56
- }
57
-
58
- setup(plistRenderer, materialRenderer, modelMatrix, viewMatrix, projMatrix) {
59
- const { gl } = this.renderer;
60
- const { material } = materialRenderer;
61
-
62
- this.renderer.state.shaderProgram = this._program;
63
- this._program.uniform1i("uTexture", 0);
64
- this._program.bindMatrix("uModelMatrix", modelMatrix);
65
- this._program.bindMatrix("uViewMatrix", viewMatrix);
66
- this._program.bindMatrix("uProjMatrix", projMatrix);
67
-
68
- if (material.diffuse instanceof Vec) {
69
- this._program.bindVector("uColor", material.diffuse);
70
- }
71
- else {
72
- console.warning("DebugRenderShader: material.diffuse is a Texture. This shader only supports as diffuse color.");
73
- }
74
-
75
- this._program.positionAttribPointer(plistRenderer.positionAttribParams("position"));
76
- this._program.texCoordAttribPointer(plistRenderer.texCoord0AttribParams("texCoord"));
77
-
78
- }
79
- }
@@ -1,69 +0,0 @@
1
- import Shader from "../render/Shader";
2
- import ShaderFunction from "./ShaderFunction";
3
- import ShaderProgram from "../render/webgl/ShaderProgram";
4
-
5
- const g_code = {
6
- webgl: {
7
- vertex: `precision mediump float;
8
- attribute vec3 position;
9
- attribute vec2 texCoord;
10
-
11
- uniform mat4 uModelMatrix;
12
- uniform mat4 uViewMatrix;
13
- uniform mat4 uProjMatrix;
14
-
15
- varying vec2 fragTexCoord;
16
-
17
- void main() {
18
- fragTexCoord = texCoord;
19
- gl_Position = uProjMatrix * uViewMatrix * uModelMatrix * vec4(position, 1.0);
20
- }`,
21
-
22
- fragment: ShaderFunction.GetShaderCode(
23
- `precision mediump float;
24
-
25
- varying vec2 fragTexCoord;
26
- `,
27
- [
28
- new ShaderFunction('void','main','',`{
29
- float d = gl_FragCoord.z / gl_FragCoord.w;
30
- gl_FragColor = vec4(d, d, d, 1.0);
31
- }`)
32
- ])
33
- }
34
- }
35
-
36
- export default class DepthRenderShader extends Shader {
37
- constructor(renderer) {
38
- super(renderer);
39
-
40
- if (renderer.typeId !== "WebGL") {
41
- throw Error("DepthRenderShader is only compatible with WebGL renderer");
42
- }
43
- }
44
-
45
- async load() {
46
- const { gl } = this.renderer;
47
-
48
- this._program = new ShaderProgram(gl, "DepthRenderShader");
49
- this._program.attachVertexSource(g_code.webgl.vertex);
50
- this._program.attachFragmentSource(g_code.webgl.fragment);
51
- this._program.link();
52
- }
53
-
54
- setup(plistRenderer, materialRenderer, modelMatrix, viewMatrix, projMatrix) {
55
- const { gl } = this.renderer;
56
- const { material } = materialRenderer;
57
-
58
- this.renderer.state.shaderProgram = this._program;
59
-
60
- this._program.bindMatrix("uModelMatrix", modelMatrix);
61
- this._program.bindMatrix("uViewMatrix", viewMatrix);
62
- this._program.bindMatrix("uProjMatrix", projMatrix);
63
-
64
- this._program.positionAttribPointer(plistRenderer.positionAttribParams("position"));
65
- this._program.texCoordAttribPointer(plistRenderer.texCoord0AttribParams("texCoord"));
66
- }
67
- }
68
-
69
-
@@ -1,99 +0,0 @@
1
-
2
- import Shader from "../render/Shader";
3
- import ShaderProgram from "../render/webgl/ShaderProgram";
4
- import Mat4 from "../math/Mat4";
5
- import Vec from "../math/Vec";
6
-
7
- const g_code = {
8
- webgl: {
9
- vertex: `precision mediump float;
10
-
11
- attribute vec3 vertPosition;
12
-
13
- uniform mat4 uMVP;
14
-
15
- varying vec3 fragNormal;
16
-
17
- void main() {
18
- gl_Position = uMVP * vec4(vertPosition, 1.0);
19
- fragNormal = normalize(vertPosition);
20
- }
21
- `,
22
-
23
- fragment: (sampleDelta) => `precision mediump float;
24
- varying vec3 fragNormal;
25
-
26
- uniform samplerCube uCubemap;
27
-
28
- void main() {
29
- vec3 normal = normalize(fragNormal);
30
- vec3 irradiance = vec3(0.0);
31
-
32
- vec3 up = vec3(0.0, 1.0, 0.0);
33
- vec3 right = cross(up, normal);
34
- up = cross(normal,right);
35
-
36
- float nrSamples = 0.0;
37
- for (float phi = 0.0; phi < ${ 2 * Math.PI }; phi += ${ sampleDelta })
38
- {
39
- for (float theta = 0.0; theta < ${ 0.5 * Math.PI }; theta += ${ sampleDelta })
40
- {
41
- // Spherical to cartesian
42
- vec3 tangentSample = vec3(sin(theta) * cos(phi), sin(theta) * sin(phi), cos(theta));
43
-
44
- // tangent space to world space
45
- vec3 sampleVec = tangentSample.x * right + tangentSample.y * up + tangentSample.z * normal;
46
-
47
- irradiance += textureCube(uCubemap, sampleVec).rgb * cos(theta) * sin(theta);
48
- nrSamples++;
49
- }
50
- }
51
- irradiance = ${ Math.PI } * irradiance * (1.0 / float(nrSamples));
52
-
53
- gl_FragColor = vec4(irradiance, 1.0);
54
- }`
55
- }
56
- };
57
-
58
- export default class IrradianceMapCubeShader extends Shader {
59
- constructor(renderer) {
60
- super(renderer);
61
-
62
- if (renderer.typeId !== "WebGL") {
63
- throw Error("PresentTextureShader is only compatible with WebGL renderer");
64
- }
65
- }
66
-
67
- async load() {
68
- const { gl } = this.renderer;
69
-
70
- this._program = new ShaderProgram(gl, "IrradianceMapCubeShader");
71
- this._program.attachVertexSource(g_code.webgl.vertex);
72
- this._program.attachFragmentSource(g_code.webgl.fragment(0.1));
73
- this._program.link();
74
- }
75
-
76
- setup(plistRenderer, materialRenderer, modelMatrix, viewMatrix, projectionMatrix) {
77
- const { material } = materialRenderer;
78
- const { gl } = this.renderer;
79
- this.renderer.state.shaderProgram = this._program;
80
-
81
- const mvp = Mat4.Mult(projectionMatrix, viewMatrix);
82
- this._program.uniformMatrix4fv('uMVP', false, mvp);
83
-
84
- gl.activeTexture(gl.TEXTURE0);
85
- this._program.uniform1i('uCubemap', 0);
86
- if (material.diffuse instanceof Vec) {
87
- throw new Error("Invalid material configuration in IrradianceMapCubeShader: diffuse component must be a cube map texture");
88
- }
89
- const webglTexture = materialRenderer.getTextureRenderer('diffuse').getApiObject();
90
- gl.bindTexture(gl.TEXTURE_CUBE_MAP, webglTexture);
91
-
92
- this._program.positionAttribPointer(plistRenderer.positionAttribParams("vertPosition"));
93
- }
94
-
95
- destroy() {
96
- ShaderProgram.Delete(this._program);
97
- this._program = null;
98
- }
99
- }