I have a 3D array dataset of scientific data that is to be rendered using WebGL. This is the code that I have wrote and this is the result that I have achieved so far.
I am clueless for two things that are happening to the output canvas:
gl.clearcolor(0.4, 0.4, 0.5, 1); is not working when screen render the output
sometimes on drawScene call the code throws error and warning. I believe that warning is vocal to that error but I couldn't debug that is causing that:
warning: WebGL: INVALID_OPERATION: texImage3D: ArrayBufferView not big enough for the request
error : error in texImage3D(TEXTURE_3D{WebGLTexture("unnamed")}, 0, R8, 64, 64, 64, 0, RED, UNSIGNED_BYTE, Uint8Array(65536)): INVALID_OPERATION
3)The expected output of the rendered output is:
and
but the rendered output is not showing the required colormap output.
This is a live demo:
This is the output if this snippet does not load for any case:

PS: if the snippet does not load slide the slider on the top right.


First issue
R8 with 64 * 64 * 64 = 262144 bytes but the array you are passing is only 65536 bytes big.
Second issue
When the code uploads the lookup map it only takes red
You probably wanted
Third issue
As for the clear color, WebGL by default, clears the canvas every time it composites it with the page. Because you clear the canvas, then load data asynchronously, then draw the data the flow is
This is why you see it flicker. If you move the call to
gl.clearintoloadDatait will work.