THREE.js - large array of int as Uniform -


i want write fragment shader three.js needs large array of 10000 integers. when try declare such array in shader's glsl code:

uniform int colorgrid[10000]; 

then shader renderer throws

error: many uniform 

what other choices have - how can pass such large chunk of data fragment shader?

textures large arrays. passing integers in textures little harder not impossible. either need split integer values across red, green, blue, , alpha channels of texture or float textures give integer values 2^24th

to pack integer texture might this

// assumes unsigned ints setpixelfromint(pixels, width, x, y, intvalue) {    var r = (intvalue >> 24) & 0xff;    var g = (intvalue >> 16) & 0xff;    var b = (intvalue >>  8) & 0xff;    var = (intvalue >>  0) & 0xff;    var offset = (y * width + x) * 4;    pixels[offset + 0] = r;    pixels[offset + 1] = g;    pixels[offset + 2] = b;    pixels[offset + 3] = a; }  var width = 100; var height = 100; var pixels = new uint8array(width * height * 4);  ... 

to values out in shader this?

uniform vec2 texturedimensions; uniform sampler2d arraytexture;  int getvaluefromtexture(sampler2d arraytexture, vec2 texturedimensions, int index) {   float x = mod(float(index), texturedimensions.x);   float y = floor(float(index) / texturedimensions.y);   vec2 uv = vec2(x + 0.5, y + 0.5) / texturedimensions;   vec4 color = texture2d(arraytexture, uv);   return int(color.r * 256.0 * 256.0 * 256.0 +              color.b * 256.0 * 256.0 +              color.g * 256.0 +              color.a); } 

be sure set filtering gl.nearest

ps: didn't run code illustrates idea


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -