@woosh/meep-engine 2.75.9 → 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.
- package/package.json +1 -1
- package/src/{engine/graphics → core/math/random}/generate_halton_jitter.js +2 -2
- package/src/engine/graphics/render/buffer/simple-fx/taa/TemporalSupersamplingRenderPlugin.js +1 -1
- package/src/engine/graphics/texture/virtual/VirtualTextureUsageUpdater.js +1 -1
- package/src/engine/graphics/CanvasBlur.js +0 -599
- package/src/engine/graphics/material/LoadMaterial.js +0 -199
- package/src/engine/graphics/material/getTextureImmediate.js +0 -21
- package/src/engine/graphics/render/buffer/RenderGraph.js +0 -177
- package/src/engine/graphics/render/buffer/RenderGraphUtils.js +0 -32
- package/src/engine/graphics/render/buffer/buffers/DepthFrameBuffer.js +0 -101
- package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnection.js +0 -43
- package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnectionEndpoint.js +0 -39
- package/src/engine/graphics/render/buffer/conection/ProgramValueSlotConnectionValidator.js +0 -30
- package/src/engine/graphics/render/buffer/executor/FrameBufferPool.js +0 -127
- package/src/engine/graphics/render/buffer/executor/RenderGraphExecutor.js +0 -261
- package/src/engine/graphics/render/buffer/executor/RenderProgramCommandType.js +0 -5
- package/src/engine/graphics/render/buffer/node/DeferredRenderProgramDefinition.js +0 -142
- package/src/engine/graphics/render/buffer/node/RenderProgramDefinition.js +0 -21
- package/src/engine/graphics/render/buffer/node/RenderProgramInstance.js +0 -30
- package/src/engine/graphics/render/buffer/node/ScreenSpaceRenderProgramDefinition.js +0 -118
- package/src/engine/graphics/render/staged/PostProcessingEffect.js +0 -32
- package/src/engine/graphics/render/staged/PostProcessingEffectInputCoupling.js +0 -41
- package/src/engine/graphics/render/staged/PostProcessingStack.js +0 -29
- package/src/engine/graphics/render/staged/StagedRenderer.js +0 -161
- package/src/engine/graphics/render/staged/StandardRenderOutputs.js +0 -20
- package/src/engine/graphics/texture/CanvasClone.js +0 -28
- package/src/engine/graphics/texture/sampler/differenceSampler.js +0 -36
- package/src/engine/graphics/texture/sampler/loadSampler2D.js +0 -41
- package/src/engine/graphics/texture/sampler/mergeSampler2D.js +0 -96
- package/src/engine/graphics/texture/sampler/rgbaData2valueSampler2D.js +0 -38
- /package/src/{engine/graphics/texture → core/math/noise}/noise_octaves.js +0 -0
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { PostProcessingEffectInputCoupling } from "./PostProcessingEffectInputCoupling.js";
|
|
2
|
-
|
|
3
|
-
class PostProcessingEffect {
|
|
4
|
-
/**
|
|
5
|
-
*
|
|
6
|
-
* @param {RenderProgramInstance} node
|
|
7
|
-
*/
|
|
8
|
-
constructor({ node }) {
|
|
9
|
-
/**
|
|
10
|
-
*
|
|
11
|
-
* @type {RenderProgramInstance}
|
|
12
|
-
*/
|
|
13
|
-
this.node = node;
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @type {PostProcessingEffectInputCoupling[]}
|
|
17
|
-
*/
|
|
18
|
-
this.inputWiring = [];
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
*
|
|
23
|
-
* @param {string} outputName
|
|
24
|
-
* @param {ProgramValueType} outputType
|
|
25
|
-
* @param {ProgramValueSlotDefinition} input
|
|
26
|
-
*/
|
|
27
|
-
couple(outputName, outputType, input) {
|
|
28
|
-
const inputCoupling = new PostProcessingEffectInputCoupling({ outputType, outputName, input });
|
|
29
|
-
|
|
30
|
-
this.inputWiring.push(inputCoupling);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ProgramValueDirectionKind } from "../buffer/slot/ProgramValueDirectionKind.js";
|
|
2
|
-
import { assert } from "../../../../core/assert.js";
|
|
3
|
-
|
|
4
|
-
export class PostProcessingEffectInputCoupling {
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @param {string} outputName
|
|
8
|
-
* @param {ProgramValueType} outputType
|
|
9
|
-
* @param {ProgramValueSlotDefinition} input
|
|
10
|
-
*/
|
|
11
|
-
constructor({ outputName, outputType, input }) {
|
|
12
|
-
assert.notEqual(input.direction, ProgramValueDirectionKind.Out, `Supplied input slot has OUT direction (not an input slot)`);
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @type {ProgramValueSlotDefinition}
|
|
17
|
-
*/
|
|
18
|
-
this.input = input;
|
|
19
|
-
/**
|
|
20
|
-
*
|
|
21
|
-
* @type {string}
|
|
22
|
-
*/
|
|
23
|
-
this.outputName = outputName;
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @type {ProgramValueType}
|
|
27
|
-
*/
|
|
28
|
-
this.outputType = outputType;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
*
|
|
33
|
-
* @param {ProgramValueSlotDefinition} output
|
|
34
|
-
* @returns {boolean}
|
|
35
|
-
*/
|
|
36
|
-
matchOutput(output) {
|
|
37
|
-
return (output.direction !== ProgramValueDirectionKind.In)
|
|
38
|
-
&& output.type === this.outputType
|
|
39
|
-
&& output.name === this.outputName;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import List from "../../../../core/collection/list/List.js";
|
|
2
|
-
|
|
3
|
-
export class PostProcessingStack {
|
|
4
|
-
constructor() {
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @type {List<RenderProgramInstance>}
|
|
8
|
-
*/
|
|
9
|
-
this.effects = new List();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @return {Set<string>}
|
|
15
|
-
*/
|
|
16
|
-
getRequiredBuffers() {
|
|
17
|
-
const result = new Set();
|
|
18
|
-
|
|
19
|
-
this.effects.forEach(e => {
|
|
20
|
-
e.getRequiredBuffers().forEach(b => result.add(b));
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
return result;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
isEmpty() {
|
|
27
|
-
this.effects.isEmpty();
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import List from "../../../../core/collection/list/List.js";
|
|
2
|
-
import { RenderGraph } from "../buffer/RenderGraph.js";
|
|
3
|
-
import { RenderProgramDefinition } from "../buffer/node/RenderProgramDefinition.js";
|
|
4
|
-
import { ProgramValueSlotConnection } from "../buffer/conection/ProgramValueSlotConnection.js";
|
|
5
|
-
import { ProgramValueSlotConnectionEndpoint } from "../buffer/conection/ProgramValueSlotConnectionEndpoint.js";
|
|
6
|
-
import { ProgramValueType } from "../buffer/slot/ProgramValueType.js";
|
|
7
|
-
import { ProgramValueDirectionKind } from "../buffer/slot/ProgramValueDirectionKind.js";
|
|
8
|
-
import { RenderGraphExecutor } from "../buffer/executor/RenderGraphExecutor.js";
|
|
9
|
-
import { DeferredRenderProgramDefinition } from "../buffer/node/DeferredRenderProgramDefinition.js";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
*
|
|
14
|
-
* @param {PostProcessingEffectInputCoupling} coupling
|
|
15
|
-
* @param {RenderGraph} graph
|
|
16
|
-
* @returns {ProgramValueSlotConnectionEndpoint}
|
|
17
|
-
*/
|
|
18
|
-
function satisfyPostProcessCoupling(coupling, graph) {
|
|
19
|
-
let bestSlot = null;
|
|
20
|
-
let bestNode = null;
|
|
21
|
-
let bestDepth = Number.NEGATIVE_INFINITY;
|
|
22
|
-
|
|
23
|
-
graph.traverseNodes(n => {
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @type {RenderProgramDefinition}
|
|
27
|
-
*/
|
|
28
|
-
const definition = n.definition;
|
|
29
|
-
|
|
30
|
-
const matchingSlot = definition.slots.find(s => coupling.matchOutput(s));
|
|
31
|
-
|
|
32
|
-
if (matchingSlot !== undefined) {
|
|
33
|
-
|
|
34
|
-
const depth = graph.computeNodeDepth(n);
|
|
35
|
-
|
|
36
|
-
if (depth > bestDepth) {
|
|
37
|
-
//get slot on the node with the longest chain
|
|
38
|
-
bestDepth = depth;
|
|
39
|
-
bestSlot = matchingSlot;
|
|
40
|
-
bestNode = n;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (bestSlot === null) {
|
|
48
|
-
//no matching slot found
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return new ProgramValueSlotConnectionEndpoint({
|
|
53
|
-
node: bestNode,
|
|
54
|
-
slot: bestSlot
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
*
|
|
60
|
-
* @param {PostProcessingEffect} effect
|
|
61
|
-
* @param {RenderGraph} graph
|
|
62
|
-
*/
|
|
63
|
-
function buildWiringForPostProcessEffect(effect, graph) {
|
|
64
|
-
const node = effect.node;
|
|
65
|
-
const inputWiring = effect.inputWiring;
|
|
66
|
-
|
|
67
|
-
const connections = inputWiring.map(c => {
|
|
68
|
-
|
|
69
|
-
const sourceEndpoint = satisfyPostProcessCoupling(c);
|
|
70
|
-
|
|
71
|
-
if (sourceEndpoint === null) {
|
|
72
|
-
throw new Error(`Input Coupling ${c} of effect ${effect} could not be satisfied`);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
const targetEndpoint = new ProgramValueSlotConnectionEndpoint({
|
|
76
|
-
node: node,
|
|
77
|
-
slot: c.input
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const connection = new ProgramValueSlotConnection({
|
|
81
|
-
source: sourceEndpoint,
|
|
82
|
-
target: targetEndpoint
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
return connection;
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
return connections;
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
export class StagedRenderer {
|
|
92
|
-
constructor() {
|
|
93
|
-
/**
|
|
94
|
-
*
|
|
95
|
-
* @type {List<PostProcessingEffect>}
|
|
96
|
-
*/
|
|
97
|
-
this.postprocess = new List();
|
|
98
|
-
|
|
99
|
-
const self = this;
|
|
100
|
-
|
|
101
|
-
function update() {
|
|
102
|
-
self.graphNeedsUpdate = true;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
this.postprocess.on.added.add(update);
|
|
106
|
-
this.postprocess.on.removed.add(update);
|
|
107
|
-
|
|
108
|
-
this.graphNeedsUpdate = true;
|
|
109
|
-
this.graphExecutor = new RenderGraphExecutor();
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
buildGraph() {
|
|
113
|
-
const graph = new RenderGraph();
|
|
114
|
-
|
|
115
|
-
const pDeferred = new DeferredRenderProgramDefinition();
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
const piDeferred = graph.createNode(pDeferred);
|
|
119
|
-
|
|
120
|
-
if (this.postprocess.isEmpty()) {
|
|
121
|
-
graph.setFinalOutput(piDeferred, DeferredRenderProgramDefinition.OutputColor);
|
|
122
|
-
} else {
|
|
123
|
-
this.postprocess.forEach(function (effect) {
|
|
124
|
-
const connections = buildWiringForPostProcessEffect(effect, graph);
|
|
125
|
-
|
|
126
|
-
//add effect node to the graph
|
|
127
|
-
graph.addNode(effect.node);
|
|
128
|
-
|
|
129
|
-
//add connections to the graph
|
|
130
|
-
connections.forEach(connection => graph.addConnection(connection));
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
const lastNode = this.postprocess.last().node;
|
|
134
|
-
const outputSlot = lastNode.definition.slots.find(s => s.type === ProgramValueType.FrameBuffer && s.direction === ProgramValueDirectionKind.Out);
|
|
135
|
-
|
|
136
|
-
graph.setFinalOutput(lastNode, outputSlot);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
//attach graph to the executor
|
|
140
|
-
this.graphExecutor.initialize(graph);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
*
|
|
145
|
-
* @param {WebGLRenderer} renderer
|
|
146
|
-
* @param {PerspectiveCamera|OrthographicCamera} camera
|
|
147
|
-
* @param {Scene} scene
|
|
148
|
-
*/
|
|
149
|
-
render(renderer, camera, scene) {
|
|
150
|
-
renderer.gammaInput = true;
|
|
151
|
-
renderer.gammaOutput = true;
|
|
152
|
-
renderer.autoClear = true;
|
|
153
|
-
renderer.clearAlpha = 0;
|
|
154
|
-
|
|
155
|
-
if (this.graphNeedsUpdate) {
|
|
156
|
-
this.buildGraph();
|
|
157
|
-
this.graphNeedsUpdate = false;
|
|
158
|
-
}
|
|
159
|
-
this.graphExecutor.execute(renderer, scene, camera);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ProgramValueSlotDefinition } from "../buffer/slot/ProgramValueSlotDefinition.js";
|
|
2
|
-
import { ProgramValueDirectionKind } from "../buffer/slot/ProgramValueDirectionKind.js";
|
|
3
|
-
import { ProgramValueType } from "../buffer/slot/ProgramValueType.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* @enum {ProgramValueSlotDefinition}
|
|
8
|
-
*/
|
|
9
|
-
export const StandardRenderOutputs = {
|
|
10
|
-
DepthBuffer: new ProgramValueSlotDefinition({
|
|
11
|
-
name: 'output',
|
|
12
|
-
direction: ProgramValueDirectionKind.Out,
|
|
13
|
-
type: ProgramValueType.FrameBuffer
|
|
14
|
-
}),
|
|
15
|
-
ColorBuffer: new ProgramValueSlotDefinition({
|
|
16
|
-
name: 'output',
|
|
17
|
-
direction: ProgramValueDirectionKind.Out,
|
|
18
|
-
type: ProgramValueType.FrameBuffer
|
|
19
|
-
})
|
|
20
|
-
};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 15/11/2014.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @param {HTMLCanvasElement} oldCanvas
|
|
9
|
-
* @return {HTMLCanvasElement}
|
|
10
|
-
*/
|
|
11
|
-
function cloneCanvas(oldCanvas) {
|
|
12
|
-
|
|
13
|
-
//create a new canvas
|
|
14
|
-
const newCanvas = document.createElement('canvas');
|
|
15
|
-
const context = newCanvas.getContext('2d');
|
|
16
|
-
|
|
17
|
-
//set dimensions
|
|
18
|
-
newCanvas.width = oldCanvas.width;
|
|
19
|
-
newCanvas.height = oldCanvas.height;
|
|
20
|
-
|
|
21
|
-
//apply the old canvas to the new one
|
|
22
|
-
context.drawImage(oldCanvas, 0, 0);
|
|
23
|
-
|
|
24
|
-
//return the new canvas
|
|
25
|
-
return newCanvas;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default cloneCanvas;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Sampler2D } from "./Sampler2D.js";
|
|
2
|
-
import { vector_nd_normalize } from "../../../../core/math/vector_nd_normalize.js";
|
|
3
|
-
import { vector_nd_dot } from "../../../../core/math/vector_nd_dot.js";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* NOTE: treats samplers as normal maps
|
|
7
|
-
* @param {Sampler2D} sampler0
|
|
8
|
-
* @param {Sampler2D} sampler1
|
|
9
|
-
* @returns {Sampler2D}
|
|
10
|
-
*/
|
|
11
|
-
export function differenceSampler(sampler0, sampler1) {
|
|
12
|
-
const dimension_count = sampler0.itemSize;
|
|
13
|
-
|
|
14
|
-
const v0 = new Float64Array(dimension_count);
|
|
15
|
-
const v1 = new Float64Array(dimension_count);
|
|
16
|
-
//
|
|
17
|
-
const width = sampler0.width;
|
|
18
|
-
const height = sampler0.height;
|
|
19
|
-
//
|
|
20
|
-
const difference = new Float32Array(width * height);
|
|
21
|
-
for (let y = 0; y < height; y++) {
|
|
22
|
-
for (let x = 0; x < width; x++) {
|
|
23
|
-
sampler0.sampleBilinear(x, y, v0);
|
|
24
|
-
sampler1.sampleBilinear(x, y, v1);
|
|
25
|
-
|
|
26
|
-
vector_nd_normalize(v0, v0, dimension_count);
|
|
27
|
-
vector_nd_normalize(v1, v1, dimension_count);
|
|
28
|
-
|
|
29
|
-
//check distance
|
|
30
|
-
difference[x + y * width] = 1 - vector_nd_dot(v0, v1, dimension_count);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
//
|
|
34
|
-
const sampleD = new Sampler2D(difference, 1, width, height);
|
|
35
|
-
return sampleD;
|
|
36
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 30/10/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { Sampler2D } from './Sampler2D.js';
|
|
5
|
-
import { GameAssetType } from "../../../asset/GameAssetType.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param {string} url
|
|
11
|
-
* @param {AssetManager} assetManager
|
|
12
|
-
* @returns {Promise<Sampler2D>}
|
|
13
|
-
*/
|
|
14
|
-
export default function loadSampler2D(url, assetManager) {
|
|
15
|
-
return new Promise(function (resolve, reject) {
|
|
16
|
-
assetManager.get({
|
|
17
|
-
path: url,
|
|
18
|
-
type: GameAssetType.Image,
|
|
19
|
-
callback: (asset) => {
|
|
20
|
-
const imageData = asset.create();
|
|
21
|
-
|
|
22
|
-
const width = imageData.width;
|
|
23
|
-
const height = imageData.height;
|
|
24
|
-
|
|
25
|
-
const data = imageData.data;
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
const bufferSize = width * height;
|
|
29
|
-
const buffer = new Float32Array(bufferSize);
|
|
30
|
-
//
|
|
31
|
-
for (let i = 0; i < bufferSize; i++) {
|
|
32
|
-
const j = (i * 4);
|
|
33
|
-
buffer[i] = (data[j] + data[j + 1] + data[j + 2]) / 765;
|
|
34
|
-
}
|
|
35
|
-
const sampler2D = new Sampler2D(buffer, 1, width, height);
|
|
36
|
-
resolve(sampler2D);
|
|
37
|
-
},
|
|
38
|
-
failure: reject
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
};
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 03/08/2016.
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import { Sampler2D } from './Sampler2D.js';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param {Array.<Sampler2D>} inputs
|
|
11
|
-
* @returns {Sampler2D}
|
|
12
|
-
*/
|
|
13
|
-
function mergeSampler2D(inputs) {
|
|
14
|
-
if (inputs.length > 4) {
|
|
15
|
-
throw new Error("Can not merge more than 4 samplers");
|
|
16
|
-
} else if (inputs.length === 0) {
|
|
17
|
-
throw new Error("No samplers to merge");
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const width = inputs[0].width;
|
|
21
|
-
const height = inputs[0].height;
|
|
22
|
-
|
|
23
|
-
//check dimensions of other inputs
|
|
24
|
-
for (let i = 1; i < inputs.length; i++) {
|
|
25
|
-
if (inputs[i].width !== width && inputs[i].height !== height) {
|
|
26
|
-
console.warn('dimensions of ' + i + " input don't match");
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const uint8Array = new Uint8Array(width * height * 4);
|
|
31
|
-
const result = new Sampler2D(uint8Array, 4, width, height);
|
|
32
|
-
|
|
33
|
-
for (let i = 0, l = inputs.length; i < l; i++) {
|
|
34
|
-
const sampler = inputs[i];
|
|
35
|
-
mergeIntoChannel(sampler, result, i);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return result;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
* @param {Sampler2D} source
|
|
44
|
-
* @param {Sampler2D} target
|
|
45
|
-
* @param {int} targetChannelIndex
|
|
46
|
-
*/
|
|
47
|
-
function mergeIntoChannel(source, target, targetChannelIndex) {
|
|
48
|
-
let sample = 0;
|
|
49
|
-
let index = 0;
|
|
50
|
-
|
|
51
|
-
const sW = source.width;
|
|
52
|
-
const sH = source.height;
|
|
53
|
-
|
|
54
|
-
const tW = target.width;
|
|
55
|
-
const tH = target.height;
|
|
56
|
-
|
|
57
|
-
let x, y;
|
|
58
|
-
|
|
59
|
-
const tData = target.data;
|
|
60
|
-
const tItemSize = target.itemSize;
|
|
61
|
-
|
|
62
|
-
if (tW === sW && tH === sH) {
|
|
63
|
-
//dimensions match exactly, no re-sampling is required
|
|
64
|
-
|
|
65
|
-
const count = sW * sH;
|
|
66
|
-
const sData = source.data;
|
|
67
|
-
|
|
68
|
-
for (index = 0; index < count; index++) {
|
|
69
|
-
sample = sData[index];
|
|
70
|
-
|
|
71
|
-
tData[index * tItemSize + targetChannelIndex] = sample * 255;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
} else {
|
|
75
|
-
//dimensions don't match, use re-sampling
|
|
76
|
-
|
|
77
|
-
//to account for 1-pixel size we force divisor to be at least 1
|
|
78
|
-
const vDivisor = Math.max(1, target.height - 1);
|
|
79
|
-
const uDivisor = Math.max(1, target.width - 1);
|
|
80
|
-
|
|
81
|
-
for (y = 0; y < tH; y++) {
|
|
82
|
-
const v = y / vDivisor;
|
|
83
|
-
for (x = 0; x < tW; x++) {
|
|
84
|
-
const u = x / uDivisor;
|
|
85
|
-
sample = source.sample(u, v, sample);
|
|
86
|
-
//
|
|
87
|
-
tData[index + targetChannelIndex] = sample * 255;
|
|
88
|
-
|
|
89
|
-
index += tItemSize;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
export { mergeSampler2D };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Created by Alex on 11/11/2014.
|
|
3
|
-
*/
|
|
4
|
-
import { Sampler2D } from './Sampler2D.js';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
*
|
|
8
|
-
* @param {ArrayLike} data
|
|
9
|
-
* @param {number} width
|
|
10
|
-
* @param {number} height
|
|
11
|
-
* @param {number} [scale=1]
|
|
12
|
-
* @param {number} [offset=0]
|
|
13
|
-
* @returns {Sampler2D}
|
|
14
|
-
*/
|
|
15
|
-
function convert(data, width, height, scale, offset) {
|
|
16
|
-
scale = scale || 1;
|
|
17
|
-
offset = offset || 0;
|
|
18
|
-
const bufferSize = width * height;
|
|
19
|
-
const buffer = new Float32Array(bufferSize);
|
|
20
|
-
|
|
21
|
-
const multiplier = scale / 765;
|
|
22
|
-
|
|
23
|
-
for (let i = 0; i < bufferSize; i++) {
|
|
24
|
-
|
|
25
|
-
const j = (i * 4);
|
|
26
|
-
|
|
27
|
-
const r = data[j];
|
|
28
|
-
const g = data[j + 1];
|
|
29
|
-
const b = data[j + 2];
|
|
30
|
-
|
|
31
|
-
buffer[i] = (r + g + b) * multiplier + offset;
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return new Sampler2D(buffer, 1, width, height);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default convert;
|
|
File without changes
|