|
17 | 17 | } |
18 | 18 |
|
19 | 19 | function dimToTexSize(gl, dimensions) { |
| 20 | + if (dimensions.length == 2) { |
| 21 | + return dimensions; |
| 22 | + } |
| 23 | + |
20 | 24 | var numTexels = dimensions[0]; |
21 | 25 | for (var i=1; i<dimensions.length; i++) { |
22 | 26 | numTexels *= dimensions[i]; |
|
296 | 300 | ' return get(tex, texSize, texDim, 0.0, 0.0, x);', |
297 | 301 | '}', |
298 | 302 | '', |
299 | | - 'float color(float r, float g, float b) {', |
300 | | - ' return decode32(vec4(r,g,b,1.0));', |
| 303 | + 'const bool outputToColor = ' + (opt.graphical? 'true' : 'false') + ';', |
| 304 | + 'vec4 actualColor;', |
| 305 | + 'void color(float r, float g, float b, float a) {', |
| 306 | + ' actualColor = vec4(r,g,b,a);', |
301 | 307 | '}', |
302 | 308 | '', |
303 | | - 'float color(float r, float g, float b, float a) {', |
304 | | - ' return decode32(vec4(r,g,b,a));', |
| 309 | + 'void color(float r, float g, float b) {', |
| 310 | + ' color(r,g,b,1.0);', |
305 | 311 | '}', |
306 | 312 | '', |
307 | 313 | paramStr, |
|
311 | 317 | 'void main(void) {', |
312 | 318 | ' index = floor(vTexCoord.s * float(uTexSize.x)) + floor(vTexCoord.t * float(uTexSize.y)) * uTexSize[0];', |
313 | 319 | ' threadId = indexTo3D(index, uOutputDim);', |
314 | | - ' gl_FragColor = kernel();', |
| 320 | + ' vec4 outputColor = kernel();', |
| 321 | + ' if (outputToColor == true) {', |
| 322 | + ' gl_FragColor = actualColor;', |
| 323 | + ' } else {', |
| 324 | + ' gl_FragColor = outputColor;', |
| 325 | + ' }', |
315 | 326 | '}' |
316 | 327 | ].join('\n'); |
317 | 328 |
|
|
335 | 346 | throw "Error compiling fragment shader"; |
336 | 347 | } |
337 | 348 |
|
| 349 | + if (opt.debug) { |
| 350 | + console.log(fragShaderSrc); |
| 351 | + } |
| 352 | + |
338 | 353 | program = gl.createProgram(); |
339 | 354 | gl.attachShader(program, vertShader); |
340 | 355 | gl.attachShader(program, fragShader); |
|
0 commit comments