@woosh/meep-engine 2.75.8 → 2.76.0

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 (107) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +784 -982
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +784 -982
  5. package/editor/actions/concrete/ModifyPatchSampler2DAction.js +6 -3
  6. package/editor/actions/concrete/PatchTerrainTextureAction.js +6 -3
  7. package/editor/process/EditorProcess.js +12 -16
  8. package/editor/process/ProcessEngine.js +9 -10
  9. package/package.json +1 -1
  10. package/src/core/binary/dec2hex.js +1 -1
  11. package/src/{engine/ecs/ik/IKMath.js → core/geom/vec3/v3_computeOffsetVector.js} +1 -1
  12. package/src/core/math/newton_solver_1d.js +13 -4
  13. package/src/{engine/graphics → core/math/random}/generate_halton_jitter.js +2 -2
  14. package/src/core/math/solveQuadratic.js +5 -3
  15. package/src/core/math/spline/catmull_rom_compute_T.js +19 -0
  16. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSpline.js +3 -3
  17. package/src/{engine/navigation/ecs/components → core/math/spline}/computeCatmullRomSplineUniformDistance.js +3 -3
  18. package/src/core/math/spline/computeNonuniformCatmullRomSplineSample.js +109 -0
  19. package/src/core/math/spline/interpolate_bicubic.js +12 -0
  20. package/src/core/math/spline/spline_catmullrom_1d.js +120 -0
  21. package/src/engine/control/ControlContext.js +25 -27
  22. package/src/engine/ecs/EntityManager.js +12 -9
  23. package/src/engine/ecs/EntityObserver.js +26 -22
  24. package/src/engine/ecs/binding/ComponentPropertyPath.js +12 -12
  25. package/src/engine/ecs/components/Motion.js +5 -7
  26. package/src/engine/ecs/components/SerializationMetadata.js +5 -3
  27. package/src/engine/ecs/dynamic_actions/actions/definition/AbstractActionDescription.js +0 -2
  28. package/src/engine/ecs/dynamic_actions/actions/definition/ActionSequenceDescription.js +7 -9
  29. package/src/engine/ecs/dynamic_actions/actions/definition/DelayActionDescription.js +3 -5
  30. package/src/engine/ecs/dynamic_actions/actions/definition/SendRequestActionDescription.js +6 -8
  31. package/src/engine/ecs/dynamic_actions/actions/definition/SpeakLineActionDescription.js +14 -17
  32. package/src/engine/ecs/dynamic_actions/actions/definition/WeightedRandomActionDescription.js +8 -11
  33. package/src/engine/ecs/dynamic_actions/actions/definition/WriteToBlackboardActionDescription.js +15 -18
  34. package/src/engine/ecs/ik/OneBoneSurfaceAlignmentSolver.js +7 -7
  35. package/src/engine/ecs/ik/TwoBoneInverseKinematicsSolver.js +6 -6
  36. package/src/engine/ecs/parent/EntityNode.js +39 -37
  37. package/src/engine/ecs/speaker/VoiceSystem.js +36 -39
  38. package/src/engine/ecs/system/SystemEntityContext.js +25 -23
  39. package/src/engine/ecs/tag/find_entities_with_tag.js +18 -0
  40. package/src/engine/ecs/terrain/TerrainClouds.js +23 -24
  41. package/src/engine/ecs/terrain/ecs/splat/SplatMapMaterialPatch.js +5 -2
  42. package/src/engine/ecs/terrain/overlay/TerrainOverlay.js +15 -14
  43. package/src/engine/ecs/tooltip/TooltipComponent.js +6 -7
  44. package/src/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  45. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +1 -5
  46. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +2 -6
  47. package/src/engine/graphics/ecs/water2/shader/testWaterShader.js +12 -14
  48. package/src/engine/graphics/material/optimization/MaterialOptimizationContext.js +22 -20
  49. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +3 -4
  50. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -4
  51. package/src/engine/graphics/render/buffer/simple-fx/taa/TemporalSupersamplingRenderPlugin.js +1 -1
  52. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +0 -4
  53. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -4
  54. package/src/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  55. package/src/engine/graphics/texture/atlas/TextureAtlas.js +13 -11
  56. package/src/engine/graphics/texture/sampler/Sampler2D.js +15 -366
  57. package/src/engine/graphics/texture/sampler/Sampler2D.spec.js +0 -31
  58. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.js +166 -0
  59. package/src/engine/graphics/texture/sampler/sampler2d_copy_with_margins.spec.js +31 -0
  60. package/src/engine/graphics/texture/sampler/sampler2d_paint.js +81 -0
  61. package/src/engine/graphics/texture/sampler/sampler2d_sub_copy_same_item_size.js +50 -0
  62. package/src/engine/graphics/texture/virtual/VirtualTextureUsageUpdater.js +1 -1
  63. package/src/engine/navigation/ecs/components/Path.js +10 -9
  64. package/src/engine/physics/computeInterceptPoint.js +44 -0
  65. package/src/engine/plugin/EnginePlugin.js +1 -2
  66. package/src/engine/ecs/components/AlignToVelocity.js +0 -9
  67. package/src/engine/ecs/components/CharacterController.js +0 -31
  68. package/src/engine/ecs/components/PhysicalBody.js +0 -51
  69. package/src/engine/ecs/components/Steering.js +0 -111
  70. package/src/engine/ecs/components/SteeringSerializationAdapter.js +0 -34
  71. package/src/engine/ecs/systems/AlignToVelocitySystem.js +0 -51
  72. package/src/engine/ecs/systems/CharacterControlSystem.js +0 -134
  73. package/src/engine/ecs/systems/PhysicsSystem.js +0 -89
  74. package/src/engine/ecs/systems/PropertySetSystem.js +0 -18
  75. package/src/engine/ecs/systems/SteeringSystem.js +0 -171
  76. package/src/engine/ecs/systems/TagSystem.d.ts +0 -5
  77. package/src/engine/ecs/systems/TagSystem.js +0 -31
  78. package/src/engine/graphics/CanvasBlur.js +0 -599
  79. package/src/engine/graphics/material/LoadMaterial.js +0 -199
  80. package/src/engine/graphics/material/getTextureImmediate.js +0 -21
  81. package/src/engine/graphics/render/buffer/RenderGraph.js +0 -177
  82. package/src/engine/graphics/render/buffer/RenderGraphUtils.js +0 -32
  83. package/src/engine/graphics/render/buffer/buffers/DepthFrameBuffer.js +0 -101
  84. package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnection.js +0 -43
  85. package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnectionEndpoint.js +0 -39
  86. package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnectionValidator.js +0 -30
  87. package/src/engine/graphics/render/buffer/executor/FrameBufferPool.js +0 -127
  88. package/src/engine/graphics/render/buffer/executor/RenderGraphExecutor.js +0 -261
  89. package/src/engine/graphics/render/buffer/executor/RenderProgramCommandType.js +0 -5
  90. package/src/engine/graphics/render/buffer/node/DeferredRenderProgramDefinition.js +0 -142
  91. package/src/engine/graphics/render/buffer/node/RenderProgramDefinition.js +0 -21
  92. package/src/engine/graphics/render/buffer/node/RenderProgramInstance.js +0 -30
  93. package/src/engine/graphics/render/buffer/node/ScreenSpaceRenderProgramDefinition.js +0 -118
  94. package/src/engine/graphics/render/staged/PostProcessingEffect.js +0 -32
  95. package/src/engine/graphics/render/staged/PostProcessingEffectInputCoupling.js +0 -41
  96. package/src/engine/graphics/render/staged/PostProcessingStack.js +0 -29
  97. package/src/engine/graphics/render/staged/StagedRenderer.js +0 -161
  98. package/src/engine/graphics/render/staged/StandardRenderOutputs.js +0 -20
  99. package/src/engine/graphics/texture/CanvasClone.js +0 -28
  100. package/src/engine/graphics/texture/sampler/bicubic.js +0 -59
  101. package/src/engine/graphics/texture/sampler/bicubic.spec.js +0 -13
  102. package/src/engine/graphics/texture/sampler/differenceSampler.js +0 -36
  103. package/src/engine/graphics/texture/sampler/loadSampler2D.js +0 -41
  104. package/src/engine/graphics/texture/sampler/mergeSampler2D.js +0 -96
  105. package/src/engine/graphics/texture/sampler/rgbaData2valueSampler2D.js +0 -38
  106. package/src/engine/navigation/ecs/components/computeNonuniformCatmullRomSplineSample.js +0 -242
  107. /package/src/{engine/graphics/texture → core/math/noise}/noise_octaves.js +0 -0
@@ -1,127 +0,0 @@
1
- import { WebGLRenderTarget } from "three";
2
- import { RenderTargetParameters } from "../slot/parameter/RenderTargetParameters.js";
3
-
4
- /**
5
- *
6
- * @param {ProgramValueSlotParameterSet} parameters
7
- * @returns {WebGLRenderTarget}
8
- */
9
- function makeRenderTarget(parameters) {
10
- const options = {};
11
-
12
- const pFormat = parameters.getParameterByName(RenderTargetParameters.Format);
13
-
14
- if (pFormat !== undefined) {
15
- options.format = pFormat.value;
16
- }
17
-
18
- const pDataType = parameters.getParameterByName(RenderTargetParameters.DataType);
19
-
20
- if (pDataType !== undefined) {
21
- options.type = pDataType.value;
22
- }
23
-
24
- const pEncoding = parameters.getParameterByName(RenderTargetParameters.Encoding);
25
-
26
- if (pEncoding !== undefined) {
27
- options.encoding = pEncoding.value;
28
- }
29
-
30
- const result = new WebGLRenderTarget(0, 0, options);
31
-
32
- return result;
33
- }
34
-
35
- class PoolEntry {
36
- /**
37
- *
38
- * @param {ProgramValueSlotParameterSet} parameters
39
- * @param {number} parametersHash
40
- */
41
- constructor({ parameters, parametersHash }) {
42
- this.inUse = false;
43
- /**
44
- *
45
- * @type {ProgramValueSlotParameterSet}
46
- */
47
- this.parameters = parameters;
48
- this.parametersHash = parametersHash;
49
- /**
50
- *
51
- * @type {WebGLRenderTarget}
52
- */
53
- this.buffer = makeRenderTarget(parameters);
54
- }
55
- }
56
-
57
-
58
- export class FrameBufferPool {
59
- constructor() {
60
- /**
61
- *
62
- * @type {PoolEntry[]}
63
- */
64
- this.buffers = [];
65
- }
66
-
67
- /**
68
- *
69
- * @param {ProgramValueSlotParameterSet} parameters
70
- * @returns {WebGLRenderTarget}
71
- */
72
- get(parameters) {
73
- //compute hash
74
- const parametersHash = parameters.hash();
75
-
76
- //try to find one
77
- let poolEntry = this.buffers.find(e => !e.inUse && e.parametersHash === parametersHash);
78
-
79
- if (poolEntry === undefined) {
80
- //doesn't exist, make one
81
- poolEntry = new PoolEntry({ parameters, parametersHash });
82
-
83
- }
84
-
85
- //mark as being in use
86
- poolEntry.inUse = true;
87
-
88
- return poolEntry.buffer;
89
- }
90
-
91
- /**
92
- *
93
- * @param {WebGLRenderTarget} buffer
94
- * @returns {boolean}
95
- */
96
- release(buffer) {
97
- for (let i = 0; i < this.buffers.length; i++) {
98
- const poolEntry = this.buffers[i];
99
-
100
- if (poolEntry.buffer === buffer) {
101
- if (poolEntry.inUse === false) {
102
- console.error('Attempting to release buffer that is not registered as being in use', poolEntry);
103
- return false;
104
- }
105
-
106
- poolEntry.inUse = false;
107
- return true;
108
- }
109
- }
110
-
111
- console.error('Attempted to release buffer that is not registered');
112
- return false;
113
- }
114
-
115
- reset() {
116
- while (this.buffers.length > 0) {
117
- const poolEntry = this.buffers.pop();
118
- //release resources
119
- poolEntry.buffer.dispose()
120
- }
121
- }
122
-
123
- destroy() {
124
- //release all render targets
125
- this.buffers.forEach(e => e.buffer.dispose());
126
- }
127
- }
@@ -1,261 +0,0 @@
1
- import { assert } from "../../../../../core/assert.js";
2
- import { ProgramValueDirectionKind } from "../slot/ProgramValueDirectionKind.js";
3
- import { ProgramValueType } from "../slot/ProgramValueType.js";
4
- import { FrameBufferPool } from "./FrameBufferPool.js";
5
-
6
- /**
7
- *
8
- * @param {ProgramSlotValue} slot
9
- * @param {function(ProgramValueSlotConnectionEndpoint)} visitor
10
- */
11
- function traverseInputBufferUsers(slot, visitor) {
12
- let i, il, j, jl;
13
-
14
- const connections0 = slot.connections;
15
-
16
- for (i = 0, il = connections0.length; i < il; i++) {
17
- const c0 = connections0[i];
18
-
19
- const sourceSlot = c0.source.node.getSlotValue(c0.source.slot);
20
-
21
- const connections1 = sourceSlot.connections;
22
-
23
- for (j = 0, jl = connections1.length; j < jl; j++) {
24
-
25
- const c1 = connections1[j];
26
-
27
- if (c1 === c0) {
28
- //ignore own connection
29
- return;
30
- }
31
-
32
- const continueFlag = visitor(c1.target);
33
-
34
- if (continueFlag === false) {
35
- //stop traversal
36
- return;
37
- }
38
- }
39
- }
40
- }
41
-
42
- /**
43
- *
44
- * @param {RenderGraph} graph
45
- * @returns {RenderProgramInstance[]}
46
- */
47
- function computeExecutionOrder(graph) {
48
-
49
- const terminalNode = graph.getTerminalNode();
50
-
51
- assert.notEqual(terminalNode, null, 'terminal node must not be null');
52
-
53
- const closedNodeList = [];
54
- const openSet = [terminalNode];
55
-
56
- while (openSet.length > 0) {
57
- const head = openSet.shift();
58
-
59
- closedNodeList.push(head);
60
-
61
- const predecessorNodes = graph.getPredecessorNodes(head);
62
-
63
- predecessorNodes.forEach(n => {
64
- if (openSet.indexOf(n) === -1) {
65
- openSet.push(n);
66
- }
67
-
68
- if (closedNodeList.indexOf(n) !== -1) {
69
- //a loop exists
70
- throw new Error(`A loop was detected, graph is not an DAG`);
71
- }
72
- });
73
- }
74
-
75
- //reverse the order
76
- closedNodeList.reverse();
77
-
78
- return closedNodeList;
79
- }
80
-
81
- export class RenderGraphExecutor {
82
- constructor() {
83
- /**
84
- *
85
- * @type {RenderGraph|null}
86
- */
87
- this.graph = null;
88
-
89
- /**
90
- *
91
- * @type {FrameBufferPool}
92
- */
93
- this.frameBufferPool = new FrameBufferPool();
94
- }
95
-
96
- /**
97
- *
98
- * @param {RenderGraph} graph
99
- */
100
- initialize(graph) {
101
- /**
102
- *
103
- * @type {RenderGraph}
104
- */
105
- this.graph = graph;
106
-
107
- //clear frame buffers
108
- this.frameBufferPool.reset();
109
- }
110
-
111
- build() {
112
- //find screen output slot
113
- const graph = this.graph;
114
-
115
- const executionOrder = computeExecutionOrder(graph);
116
-
117
- // At this point we have the execution order for nodes
118
-
119
-
120
- }
121
-
122
- execute(renderer, scene, camera) {
123
- const frameBufferPool = this.frameBufferPool;
124
- const graph = this.graph;
125
-
126
- const executed = [];
127
- //put all nodes into open set
128
- const open = graph.nodes.slice();
129
- //
130
- const scheduled = [];
131
-
132
- function attemptScheduling() {
133
- let i, j, numOpenNodes;
134
-
135
- numOpenNodes = open.length;
136
-
137
- open_loop:for (i = 0; i < numOpenNodes; i++) {
138
- const node = open[i];
139
- const predecessorNodes = graph.getPredecessorNodes(node);
140
-
141
- const numPredecessors = predecessorNodes.length;
142
- for (j = 0; j < numPredecessors; j++) {
143
- const predecessorNode = predecessorNodes[j];
144
-
145
- if (executed.indexOf(predecessorNode) === -1) {
146
- //predecessor has not been executed yet
147
- continue open_loop;
148
- }
149
- }
150
-
151
- //all predecessors have been satisfied, schedule node
152
- open.splice(i, 1);
153
-
154
- i--;
155
- numOpenNodes--;
156
-
157
- //add to scheduled set
158
- scheduled.push(node);
159
- }
160
- }
161
-
162
-
163
- /**
164
- *
165
- * @param {RenderProgramInstance} n
166
- */
167
- function executeNode(n) {
168
- //assign output buffers to slots
169
-
170
- /**
171
- *
172
- * @type {RenderProgramDefinition}
173
- */
174
- const programDefinition = n.definition;
175
-
176
- /**
177
- *
178
- * @type {ProgramSlotValue[]}
179
- */
180
- const outputBufferValues = [];
181
- /**
182
- *
183
- * @type {ProgramSlotValue[]}
184
- */
185
- const inputBufferValues = [];
186
-
187
- n.slotValues.forEach(s => {
188
- if (s.definition.type !== ProgramValueType.FrameBuffer) {
189
- return;
190
- }
191
- if (s.definition.direction === ProgramValueDirectionKind.Out) {
192
- outputBufferValues.push(s);
193
- } else {
194
- inputBufferValues.push(s);
195
- }
196
- });
197
-
198
- outputBufferValues.forEach(v => {
199
- /**
200
- *
201
- * @type {ProgramValueSlotDefinition}
202
- */
203
- const valueSlotDefinition = v.definition;
204
-
205
- const renderTarget = frameBufferPool.get(valueSlotDefinition.parameters);
206
-
207
- v.setValue(renderTarget);
208
- });
209
-
210
- programDefinition.execute(n, renderer, camera, scene);
211
-
212
- //write slot values along the connections
213
- n.slotValues
214
- .filter(s => s.definition.direction === ProgramValueDirectionKind.Out)
215
- .forEach(s => {
216
- s.connections.forEach(c => {
217
- const targetSlot = c.target.node.getSlotValue(c.target.slot);
218
-
219
- targetSlot.setValue(s.getValue());
220
- });
221
- });
222
-
223
-
224
- //release buffers that may have become unnecessary
225
- inputBufferValues.forEach(i => {
226
- let stillInUse = false;
227
- traverseInputBufferUsers(i, endpoint => {
228
- if (executed.indexOf(endpoint.node) === -1) {
229
- //has not yet been executed
230
- stillInUse = true;
231
-
232
- //signal to stop traversal
233
- return false;
234
- }
235
- });
236
-
237
- if (!stillInUse) {
238
- //release buffer so it can be reused
239
- frameBufferPool.release(i.getValue());
240
- }
241
- });
242
- }
243
-
244
- while (open.length > 0) {
245
- attemptScheduling();
246
-
247
- if (scheduled.length <= 0) {
248
- throw new Error(`no nodes scheduled from open set (length=${open.length})`);
249
- }
250
-
251
- while (scheduled.length > 0) {
252
- const node = scheduled.pop();
253
-
254
- executeNode(node);
255
-
256
- //move to executed set
257
- executed.push(node);
258
- }
259
- }
260
- }
261
- }
@@ -1,5 +0,0 @@
1
- /**
2
- *
3
- * @enum {number}
4
- */
5
- export const RenderProgramCommandType = {};
@@ -1,142 +0,0 @@
1
- import { RenderProgramDefinition } from "./RenderProgramDefinition.js";
2
- import { ProgramValueSlotDefinition } from "../slot/ProgramValueSlotDefinition.js";
3
- import { ProgramValueType } from "../slot/ProgramValueType.js";
4
- import { ProgramValueDirectionKind } from "../slot/ProgramValueDirectionKind.js";
5
- import { ProgramValueSlotParameter } from "../slot/parameter/ProgramValueSlotParameter.js";
6
- import { RenderTargetParameters } from "../slot/parameter/RenderTargetParameters.js";
7
- import { ProgramValueSlotParameterType } from "../slot/parameter/ProgramValueSlotParameterType.js";
8
- import { FrontSide, MeshDepthMaterial, NoBlending, RGBADepthPacking, RGBAFormat } from "three";
9
-
10
- const DepthOutput = new ProgramValueSlotDefinition({
11
- type: ProgramValueType.FrameBuffer,
12
- name: 'depth',
13
- direction: ProgramValueDirectionKind.Out
14
- });
15
-
16
- DepthOutput.parameters.add(new ProgramValueSlotParameter({
17
- name: RenderTargetParameters.Format,
18
- type: ProgramValueSlotParameterType.UnsignedInteger,
19
- value: RGBAFormat
20
- }));
21
-
22
- const ColorOutput = new ProgramValueSlotDefinition({
23
- type: ProgramValueType.FrameBuffer,
24
- name: 'color',
25
- direction: ProgramValueDirectionKind.Out
26
- });
27
-
28
- ColorOutput.parameters.add(new ProgramValueSlotParameter({
29
- name: RenderTargetParameters.Format,
30
- type: ProgramValueSlotParameterType.UnsignedInteger,
31
- value: RGBAFormat
32
- }));
33
-
34
-
35
- function makeDepthRenderer() {
36
- const depthMaterialSkinned = new MeshDepthMaterial();
37
- depthMaterialSkinned.depthPacking = RGBADepthPacking;
38
- depthMaterialSkinned.blending = NoBlending;
39
- depthMaterialSkinned.side = FrontSide;
40
- depthMaterialSkinned.skinning = true;
41
-
42
- const depthMaterialStatic = new MeshDepthMaterial();
43
- depthMaterialStatic.depthPacking = RGBADepthPacking;
44
- depthMaterialStatic.blending = NoBlending;
45
- depthMaterialStatic.side = FrontSide;
46
-
47
-
48
- const materialMap = [];
49
-
50
- function renderMethod(renderer, camera, scene, renderTarget) {
51
-
52
- const currentVrEnabled = renderer.vr.enabled;
53
- const currentShadowAutoUpdate = renderer.shadowMap.autoUpdate;
54
-
55
- renderer.vr.enabled = false; // Avoid camera modification and recursion
56
- renderer.shadowMap.autoUpdate = false; // Avoid re-computing shadows
57
-
58
- scene.overrideMaterial = null;
59
-
60
- //replace materials in the scene
61
- scene.traverse(function (object) {
62
- const material = object.material;
63
- if (material !== undefined && material.depthWrite) {
64
- //remember old material
65
- materialMap[object.id] = material;
66
-
67
- //set new material
68
- if (material.customDepthMaterial !== undefined) {
69
- object.material = material.customDepthMaterial;
70
- } else if (material.skinning) {
71
- object.material = depthMaterialSkinned;
72
- } else {
73
- object.material = depthMaterialStatic;
74
- }
75
- }
76
- });
77
-
78
- renderer.render(scene, camera, renderTarget, true);
79
-
80
- //restore materials
81
- scene.traverse(function (object) {
82
- const material = object.material;
83
- if (material !== undefined) {
84
- const id = object.id;
85
- const m = materialMap[id];
86
- if (m !== undefined) {
87
- object.material = m;
88
-
89
- delete materialMap[id];
90
- }
91
- }
92
- });
93
-
94
- scene.overrideMaterial = null;
95
-
96
- renderer.vr.enabled = currentVrEnabled;
97
- renderer.shadowMap.autoUpdate = currentShadowAutoUpdate;
98
- }
99
-
100
- return renderMethod;
101
- }
102
-
103
- export class DeferredRenderProgramDefinition extends RenderProgramDefinition {
104
- constructor() {
105
- super();
106
-
107
- const slots = this.slots;
108
-
109
- slots.push(ColorOutput);
110
- slots.push(DepthOutput);
111
-
112
- this.__depthRenderMethod = makeDepthRenderer();
113
- }
114
-
115
- /**
116
- *
117
- * @param {RenderProgramInstance} instance
118
- * @param {WebGLRenderer} renderer
119
- * @param {PerspectiveCamera|OrthographicCamera} camera
120
- * @param {Scene} scene
121
- */
122
- execute(instance, renderer, camera, scene) {
123
- const sColor = instance.getSlotValue(ColorOutput);
124
- const sDepth = instance.getSlotValue(DepthOutput);
125
-
126
- const rtColor = sColor.getValue();
127
- const rtDepth = sDepth.getValue();
128
-
129
- //disable stencil
130
- rtDepth.stencilBuffer = false;
131
-
132
- //draw depth
133
- this.__depthRenderMethod(renderer, camera, scene, rtDepth);
134
-
135
- //draw color
136
- renderer.render(scene, camera, rtColor);
137
-
138
- }
139
- }
140
-
141
- DeferredRenderProgramDefinition.OutputColor = ColorOutput;
142
- DeferredRenderProgramDefinition.OutputDepth = DepthOutput;
@@ -1,21 +0,0 @@
1
- export class RenderProgramDefinition {
2
- constructor() {
3
- /**
4
- *
5
- * @type {ProgramValueSlotDefinition[]}
6
- */
7
- this.slots = [];
8
- }
9
-
10
- build() {
11
-
12
- }
13
-
14
- /**
15
- *
16
- * @param {RenderProgramInstance} instance
17
- */
18
- execute(instance) {
19
- throw new Error(`Not implemented. Needs to be overridden`);
20
- }
21
- }
@@ -1,30 +0,0 @@
1
- import { ProgramSlotValue } from "../slot/ProgramSlotValue.js";
2
-
3
- export class RenderProgramInstance {
4
- /**
5
- *
6
- * @param {RenderProgramDefinition} definition
7
- */
8
- constructor({ definition }) {
9
- /**
10
- *
11
- * @type {RenderProgramDefinition}
12
- */
13
- this.definition = definition;
14
-
15
- /**
16
- *
17
- * @type {ProgramSlotValue[]}
18
- */
19
- this.slotValues = definition.slots.map(s => new ProgramSlotValue(s));
20
- }
21
-
22
- /**
23
- *
24
- * @param {ProgramValueSlotDefinition} definition
25
- * @return {ProgramSlotValue}
26
- */
27
- getSlotValue(definition) {
28
- return this.slotValues.find(v => v.definition === definition);
29
- }
30
- }
@@ -1,118 +0,0 @@
1
- import { RenderProgramDefinition } from "./RenderProgramDefinition.js";
2
- import { Mesh, OrthographicCamera, PlaneBufferGeometry, Scene, ShaderMaterial, Vector2, Vector3, Vector4 } from "three";
3
- import { ProgramValueDirectionKind } from "../slot/ProgramValueDirectionKind.js";
4
- import { ProgramValueType } from "../slot/ProgramValueType.js";
5
-
6
- /**
7
- * Three.js uniform types
8
- * @enum {string}
9
- */
10
- export const ThreeUniformType = {
11
- Texture: 't',
12
- Float: 'f',
13
- Vector2: 'v2',
14
- Vector3: 'v3',
15
- Vector4: 'v4',
16
- Matrix4: 'm4'
17
- };
18
-
19
- /**
20
- *
21
- * @param {ProgramValueType} t
22
- * @returns {ThreeUniformType}
23
- */
24
- function slotType2ThreeUniormType(t) {
25
- switch (t) {
26
- case ProgramValueType.FrameBuffer:
27
- return ThreeUniformType.Texture;
28
- case ProgramValueType.Scalar:
29
- return ThreeUniformType.Float;
30
- case ProgramValueType.Vector2:
31
- return ThreeUniformType.Vector2;
32
- case ProgramValueType.Vector3:
33
- return ThreeUniformType.Vector3;
34
- case ProgramValueType.Vector4:
35
- return ThreeUniformType.Vector4;
36
- default:
37
- throw new TypeError(`Unsupported slot type: '${t}'`);
38
- }
39
- }
40
-
41
- /**
42
- *
43
- * @param {ProgramValueType} t
44
- */
45
- function slotTpe2InitialValue(t) {
46
- switch (t) {
47
- case ProgramValueType.FrameBuffer:
48
- return null;
49
- case ProgramValueType.Scalar:
50
- return 0.0;
51
- case ProgramValueType.Vector2:
52
- return new Vector2();
53
- case ProgramValueType.Vector3:
54
- return new Vector3();
55
- case ProgramValueType.Vector4:
56
- return new Vector4();
57
- default:
58
- throw new TypeError(`Unsupported slot type: '${t}'`);
59
- }
60
- }
61
-
62
- export class ScreenSpaceRenderProgramDefinition extends RenderProgramDefinition {
63
- /**
64
- *
65
- * @param {string} vertexShader
66
- * @param {string} fragmentShader
67
- */
68
- constructor({ vertexShader, fragmentShader }) {
69
- super();
70
-
71
- this.fragmentShader = fragmentShader;
72
- this.vertexShader = vertexShader;
73
- }
74
-
75
- build() {
76
-
77
- const uniforms = {};
78
-
79
- //Build uniforms
80
- this.slots.forEach(s => {
81
- if (s.direction !== ProgramValueDirectionKind.In) {
82
- return;
83
- }
84
-
85
- const slotName = s.name;
86
-
87
- const slotType = s.type;
88
-
89
- const uniformType = slotType2ThreeUniormType(slotType);
90
- const uniformValue = slotTpe2InitialValue(slotType);
91
-
92
- uniforms[slotName] = {
93
- type: uniformType,
94
- value: uniformValue
95
- };
96
-
97
- });
98
-
99
- this.uniforms = uniforms;
100
-
101
- //build material
102
- this.material = new ShaderMaterial({
103
-
104
- defines: {},
105
- uniforms: this.uniforms,
106
- vertexShader: this.vertexShader,
107
- fragmentShader: this.fragmentShader
108
-
109
- });
110
-
111
-
112
- this.camera = new OrthographicCamera(-1, 1, 1, -1, 0, 1);
113
- this.scene = new Scene();
114
-
115
- this.quad = new Mesh(new PlaneBufferGeometry(2, 2), this.material);
116
- this.scene.add(this.quad);
117
- }
118
- }