|
53 | 53 | return ret; |
54 | 54 | } |
55 | 55 |
|
56 | | - function flatten(arr) { |
| 56 | + function flatten(arr, padding) { |
| 57 | + function zeros(n) { |
| 58 | + return Array.apply(null, Array(n)).map(Number.prototype.valueOf,0); |
| 59 | + } |
| 60 | + function concatWithPadding(a, b) { |
| 61 | + return [].concat(a, zeros(padding), b); |
| 62 | + } |
| 63 | + |
57 | 64 | if (Array.isArray(arr[0])) { |
58 | | - return [].concat.apply([], arr); |
| 65 | + if (padding) { |
| 66 | + return (concatWithPadding.apply([], arr)).concat(zeros(padding)); |
| 67 | + } else { |
| 68 | + return [].concat.apply([], arr); |
| 69 | + } |
59 | 70 | } else { |
60 | 71 | return arr; |
61 | 72 | } |
|
272 | 283 | 'vec3 threadId;', |
273 | 284 | '', |
274 | 285 | 'vec3 indexTo3D(float idx, vec3 texDim) {', |
| 286 | + ' idx = floor(idx + 0.5);', |
275 | 287 | ' float z = floor(idx / (texDim.x * texDim.y));', |
276 | 288 | ' idx -= z * texDim.x * texDim.y;', |
277 | 289 | ' float y = floor(idx / texDim.x);', |
|
283 | 295 | ' vec3 xyz = vec3(floor(x + 0.5), floor(y + 0.5), floor(z + 0.5));', |
284 | 296 | (opt.wraparound ? ' xyz = mod(xyz, texDim);' : ''), |
285 | 297 | ' float index = (xyz.z * texDim.x * texDim.y) + (xyz.y * texDim.x) + xyz.x;', |
286 | | - ' float t = (floor(index / texSize.x) + 0.5) / texSize.y;', |
287 | | - ' float s = (mod(index, texSize.x) + 0.5) / texSize.x;', |
288 | | - ' return decode32(texture2D(tex, vec2(s, t)));', |
| 298 | + ' float t = (floor(index / texSize.x) + 0.5);', |
| 299 | + ' float s = mod(index, texSize.x);', |
| 300 | + ' s = (s < 0.5) ? 0.0 : s + 0.5;', |
| 301 | + ' return decode32(texture2D(tex, vec2(s / texSize.x, t / texSize.y)));', |
289 | 302 | '}', |
290 | 303 | '', |
291 | 304 | 'float get(sampler2D tex, vec2 texSize, vec3 texDim, float y, float x) {', |
|
311 | 324 | builder.webglString("kernel", opt), |
312 | 325 | '', |
313 | 326 | 'void main(void) {', |
314 | | - ' index = floor(vTexCoord.s * float(uTexSize.x)) + floor(vTexCoord.t * float(uTexSize.y)) * uTexSize[0];', |
| 327 | + ' index = floor(vTexCoord.s * float(uTexSize.x)) + floor(vTexCoord.t * float(uTexSize.y)) * uTexSize.x;', |
315 | 328 | ' threadId = indexTo3D(index, uOutputDim);', |
316 | 329 | ' vec4 outputColor = encode32(kernel());', |
317 | 330 | ' if (outputToColor == true) {', |
|
403 | 416 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST); |
404 | 417 | gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST); |
405 | 418 |
|
| 419 | + |
406 | 420 | var paramArray = flatten(arguments[textureCount]); |
407 | 421 | while (paramArray.length < paramSize[0] * paramSize[1]) { |
408 | 422 | paramArray.push(0); |
|
0 commit comments