|
210 | 210 | var paramDim = getDimensions(arguments[i], true); |
211 | 211 | var paramSize = dimToTexSize(gl, paramDim); |
212 | 212 |
|
213 | | - paramStr += 'uniform sampler2D user_' + paramNames[i] + ';\n'; |
214 | | - paramStr += 'vec2 user_' + paramNames[i] + 'Size = vec2(' + paramSize[0] + ',' + paramSize[1] + ');\n'; |
215 | | - paramStr += 'vec3 user_' + paramNames[i] + 'Dim = vec3(' + paramDim[0] + ', ' + paramDim[1] + ', ' + paramDim[2] + ');\n'; |
| 213 | + paramStr += 'uniform highp sampler2D user_' + paramNames[i] + ';\n'; |
| 214 | + paramStr += 'highp vec2 user_' + paramNames[i] + 'Size = vec2(' + paramSize[0] + '.0, ' + paramSize[1] + '.0);\n'; |
| 215 | + paramStr += 'highp vec3 user_' + paramNames[i] + 'Dim = vec3(' + paramDim[0] + '.0, ' + paramDim[1] + '.0, ' + paramDim[2] + '.0);\n'; |
| 216 | + } else if (argType == "Number" && Number.isInteger(arguments[i])) { |
| 217 | + paramStr += 'highp float user_' + paramNames[i] + ' = ' + arguments[i] + '.0;\n'; |
216 | 218 | } else if (argType == "Number") { |
217 | | - paramStr += 'float user_' + paramNames[i] + ' = ' + arguments[i] + ';\n'; |
| 219 | + paramStr += 'highp float user_' + paramNames[i] + ' = ' + arguments[i] + ';\n'; |
218 | 220 | } |
219 | 221 | } else { |
220 | 222 | if (argType == "Array" || argType == "Texture") { |
221 | | - paramStr += 'uniform sampler2D user_' + paramNames[i] + ';\n'; |
222 | | - paramStr += 'uniform vec2 user_' + paramNames[i] + 'Size;\n'; |
223 | | - paramStr += 'uniform vec3 user_' + paramNames[i] + 'Dim;\n'; |
| 223 | + paramStr += 'uniform highp sampler2D user_' + paramNames[i] + ';\n'; |
| 224 | + paramStr += 'uniform highp vec2 user_' + paramNames[i] + 'Size;\n'; |
| 225 | + paramStr += 'uniform highp vec3 user_' + paramNames[i] + 'Dim;\n'; |
224 | 226 | } else if (argType == "Number") { |
225 | | - paramStr += 'uniform float user_' + paramNames[i] + ';\n'; |
| 227 | + paramStr += 'uniform highp float user_' + paramNames[i] + ';\n'; |
226 | 228 | } |
227 | 229 | } |
228 | 230 | } |
|
238 | 240 | 'precision highp int;', |
239 | 241 | 'precision highp sampler2D;', |
240 | 242 | '', |
241 | | - 'attribute vec2 aPos;', |
242 | | - 'attribute vec2 aTexCoord;', |
| 243 | + 'attribute highp vec2 aPos;', |
| 244 | + 'attribute highp vec2 aTexCoord;', |
243 | 245 | '', |
244 | | - 'varying vec2 vTexCoord;', |
| 246 | + 'varying highp vec2 vTexCoord;', |
245 | 247 | '', |
246 | 248 | 'void main(void) {', |
247 | 249 | ' gl_Position = vec4(aPos, 0, 1);', |
|
252 | 254 | var fragShaderSrc = [ |
253 | 255 | 'precision highp float;', |
254 | 256 | 'precision highp int;', |
| 257 | + 'precision highp sampler2D;', |
255 | 258 | '', |
256 | 259 | '#define LOOP_MAX '+ (opt.loopMaxIterations ? parseInt(opt.loopMaxIterations)+'.0' : '100.0'), |
257 | 260 | '#define EPSILON 0.0000001', |
258 | 261 | '', |
259 | | - opt.hardcodeConstants ? 'vec3 uOutputDim = vec3('+threadDim[0]+','+threadDim[1]+', '+ threadDim[2]+');' : 'uniform vec3 uOutputDim;', |
260 | | - opt.hardcodeConstants ? 'vec2 uTexSize = vec2('+texSize[0]+','+texSize[1]+');' : 'uniform vec2 uTexSize;', |
261 | | - 'varying vec2 vTexCoord;', |
| 262 | + opt.hardcodeConstants ? 'highp vec3 uOutputDim = vec3('+threadDim[0]+','+threadDim[1]+', '+ threadDim[2]+');' : 'uniform highp vec3 uOutputDim;', |
| 263 | + opt.hardcodeConstants ? 'highp vec2 uTexSize = vec2('+texSize[0]+','+texSize[1]+');' : 'uniform highp vec2 uTexSize;', |
| 264 | + 'varying highp vec2 vTexCoord;', |
262 | 265 | '', |
263 | | - 'float integerMod(float x, float y) {', |
264 | | - ' float res = floor(x - y * floor(x/y));', |
265 | | - ' if (res > y - 0.5) res = 0.0;', |
| 266 | + 'highp float integerMod(highp float x, highp float y) {', |
| 267 | + ' highp float res = floor(mod(x, y));', |
| 268 | + ' if (res > floor(y) - 1.0) res = 0.0;', |
266 | 269 | ' return res;', |
267 | 270 | '}', |
268 | 271 | '', |
269 | | - 'int integerMod(int x, int y) {', |
| 272 | + 'highp int integerMod(highp int x, highp int y) {', |
270 | 273 | ' return int(integerMod(float(x), float(y)));', |
271 | 274 | '}', |
272 | 275 | '', |
|
278 | 281 | (endianness == 'LE' ? '' : ' rgba.rgba = rgba.abgr;'), |
279 | 282 | ' rgba *= 255.0;', |
280 | 283 | ' rgba = floor(rgba+0.5);', |
281 | | - ' float sign = rgba.a > 127.0 ? -1.0 : 1.0;', |
282 | | - ' float exponent = 2.0 * integerMod(rgba.a, 128.0) + (rgba.b > 127.0 ? 1.0 : 0.0);', |
283 | | - ' float res;', |
| 284 | + ' highp float sign = rgba.a > 127.0 ? -1.0 : 1.0;', |
| 285 | + ' highp float exponent = 2.0 * integerMod(rgba.a, 128.0) + (rgba.b > 127.0 ? 1.0 : 0.0);', |
| 286 | + ' highp float res;', |
284 | 287 | ' if (abs(exponent) < EPSILON) {', |
285 | 288 | ' res = sign * 0.0;', |
286 | 289 | ' } else {', |
|
297 | 300 | 'highp vec4 encode32(highp float f) {', |
298 | 301 | ' if (f == 0.0) return vec4(0.0);', |
299 | 302 | ' highp float F = abs(f);', |
300 | | - ' float sign = f < 0.0 ? 1.0 : 0.0;', |
301 | | - ' float log2F = log2(F);', |
302 | | - ' highp float exponentF = floor(log2F); ', |
303 | | - ' highp float mantissaF = (exp2(-exponentF) * F);', |
304 | | - ' exponentF = floor(log2F + 127.0) + floor(log2(mantissaF));', |
305 | | - ' float exponent;', |
306 | | - ' if (f > 1000.0) {', |
307 | | - ' exponent = log2F < 0.0 ? floor(log2F)-1.0 : floor(log2F);', |
308 | | - ' } else {', |
309 | | - ' exponent = exponentF - 127.0;', |
310 | | - ' }', |
311 | | - ' float mantissa_part1 = integerMod(F * exp2(23.0-exponent), 256.0);', |
312 | | - ' float mantissa_part2 = integerMod(F * exp2(15.0-exponent), 256.0);', |
313 | | - ' float mantissa_part3 = integerMod(F * exp2(7.0-exponent), 128.0);', |
314 | | - ' float test = exp2(exponent);', |
315 | | - ' test += mantissa_part3 * exp2(exponent-7.0);', |
316 | | - ' test += mantissa_part2 * exp2(exponent-15.0);', |
317 | | - ' test += mantissa_part1 * exp2(exponent-23.0);', |
318 | | - ' float error = log2(test) - log2F;', |
319 | | - ' if (abs(error) >= 1.0) {', |
320 | | - ' exponent -= floor(error);', |
321 | | - ' mantissa_part1 = integerMod(F * exp2(23.0-exponent), 256.0);', |
322 | | - ' mantissa_part2 = integerMod(F * exp2(15.0-exponent), 256.0);', |
323 | | - ' mantissa_part3 = integerMod(F * exp2(7.0-exponent), 128.0);', |
324 | | - ' } else if (abs(error) > 0.0) {', |
325 | | - ' mantissa_part1 = 0.0;', |
326 | | - ' mantissa_part2 = 0.0;', |
327 | | - ' mantissa_part3 = 0.0;', |
328 | | - ' }', |
| 303 | + ' highp float sign = f < 0.0 ? 1.0 : 0.0;', |
| 304 | + ' highp float log2F = log2(F);', |
| 305 | + ' highp float exponent = floor(log2F);', |
| 306 | + ' highp float mantissa = (exp2(-exponent) * F);', |
| 307 | + ' exponent = floor(log2F) + floor(log2(mantissa));', |
| 308 | + ' highp float mantissa_part1 = integerMod(F * exp2(23.0-exponent), 256.0);', |
| 309 | + ' highp float mantissa_part2 = integerMod(F * exp2(15.0-exponent), 256.0);', |
| 310 | + ' highp float mantissa_part3 = integerMod(F * exp2(7.0-exponent), 128.0);', |
329 | 311 | ' exponent += 127.0;', |
330 | 312 | ' vec4 rgba;', |
331 | 313 | ' rgba.a = 128.0 * sign + floor(exponent/2.0);', |
|
338 | 320 | '}', |
339 | 321 | '// Dragons end here', |
340 | 322 | '', |
341 | | - 'float index;', |
342 | | - 'vec3 threadId;', |
| 323 | + 'highp float index;', |
| 324 | + 'highp vec3 threadId;', |
343 | 325 | '', |
344 | | - 'vec3 indexTo3D(float idx, vec3 texDim) {', |
| 326 | + 'highp vec3 indexTo3D(highp float idx, highp vec3 texDim) {', |
345 | 327 | ' idx = floor(idx + 0.5);', |
346 | | - ' float z = floor(idx / (texDim.x * texDim.y));', |
| 328 | + ' highp float z = floor(idx / (texDim.x * texDim.y));', |
347 | 329 | ' idx -= z * texDim.x * texDim.y;', |
348 | | - ' float y = floor(idx / texDim.x);', |
349 | | - ' float x = integerMod(idx, texDim.x);', |
| 330 | + ' highp float y = floor(idx / texDim.x);', |
| 331 | + ' highp float x = integerMod(idx, texDim.x);', |
350 | 332 | ' return vec3(x, y, z);', |
351 | 333 | '}', |
352 | 334 | '', |
353 | | - 'float get(sampler2D tex, vec2 texSize, vec3 texDim, float z, float y, float x) {', |
354 | | - ' vec3 xyz = vec3(floor(x + 0.5), floor(y + 0.5), floor(z + 0.5));', |
| 335 | + 'highp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float z, highp float y, highp float x) {', |
| 336 | + ' highp vec3 xyz = vec3(floor(x + 0.5), floor(y + 0.5), floor(z + 0.5));', |
355 | 337 | (opt.wraparound ? ' xyz = mod(xyz, texDim);' : ''), |
356 | | - ' float index = floor((xyz.z * texDim.x * texDim.y) + (xyz.y * texDim.x) + xyz.x + 0.5);', |
357 | | - ' float w = floor(texSize.x + 0.5);', |
358 | | - ' float s = integerMod(index, w);', |
359 | | - ' float t = float(int(index) / int(w));', |
| 338 | + ' highp float index = floor((xyz.z * texDim.x * texDim.y) + (xyz.y * texDim.x) + xyz.x + 0.5);', |
| 339 | + ' highp float w = floor(texSize.x + 0.5);', |
| 340 | + ' highp float s = integerMod(index, w);', |
| 341 | + ' highp float t = float(int(index) / int(w));', |
360 | 342 | ' s += 0.5;', |
361 | 343 | ' t += 0.5;', |
362 | 344 | ' return decode32(texture2D(tex, vec2(s / texSize.x, t / texSize.y)));', |
363 | 345 | '}', |
364 | 346 | '', |
365 | | - 'float get(sampler2D tex, vec2 texSize, vec3 texDim, float y, float x) {', |
| 347 | + 'highp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float y, highp float x) {', |
366 | 348 | ' return get(tex, texSize, texDim, 0.0, y, x);', |
367 | 349 | '}', |
368 | 350 | '', |
369 | | - 'float get(sampler2D tex, vec2 texSize, vec3 texDim, float x) {', |
| 351 | + 'highp float get(highp sampler2D tex, highp vec2 texSize, highp vec3 texDim, highp float x) {', |
370 | 352 | ' return get(tex, texSize, texDim, 0.0, 0.0, x);', |
371 | 353 | '}', |
372 | 354 | '', |
373 | 355 | 'const bool outputToColor = ' + (opt.graphical? 'true' : 'false') + ';', |
374 | | - 'vec4 actualColor;', |
| 356 | + 'highp vec4 actualColor;', |
375 | 357 | 'void color(float r, float g, float b, float a) {', |
376 | 358 | ' actualColor = vec4(r,g,b,a);', |
377 | 359 | '}', |
|
380 | 362 | ' color(r,g,b,1.0);', |
381 | 363 | '}', |
382 | 364 | '', |
383 | | - 'float kernelResult = 0.0;', |
| 365 | + 'highp float kernelResult = 0.0;', |
384 | 366 | paramStr, |
385 | 367 | constantsStr, |
386 | 368 | builder.webglString("kernel", opt), |
|
0 commit comments