Using Shaders to Create Tables

Using Shaders to Create Tables


I am working on a program that involves the use of both static and dynamic tables. I would like to use shaders to speed up the computations. Where each entry in the tables consists of 4 or fewer items, the data can be saved (and displayed) as part of an image. In some cases, the results will take the form of an image. Thus, I would like to implement these shaders an extension of an existing material (using the “OnBeforeCompile” method.)

Thus, I have three challenges:
(1) Making my computations in the shaders;
(2) Storing the results as an image; and
(3) Accessing the image data for use in other computations.

As shown here, I have been able to accomplish the first two challenges. I found that (1) I had to use the vertex shader to get the position of the data within the image (array); (2) I could make my computations as part of the “color” section of the fragment shader; and (3) any subroutines had to be part of the main section of the fragment shader…

[The response by Chaser_Code below is in response to my original question whether gl_FragCoord is still a valid variable. It is.]

The place where I am stuck is solving the final challenge of accessing the image data for use in other computations.

Discussions online indicate that the difficulty with accessing data in an image is that the results are stored on the GPU, not the CPU and that I might be able to access the data by creating a canvas. I have tried that and am still unable to access the data.

However, discussions online also indicate that shaders can also write to the attachments of a framebuffer, which can be textures, and that those textures can be used as inputs to a shader. So that is what I will be trying next. I believe that this approach was used in some programs that I have seen, so I am optimistic that this can be made to work.

Any thoughts or guidance would be appreciated.

gl_FragCoord in fragment shader
float depth=gl_FragCoord.z/gl_FragCoord.w; float fogFactor=smoothstep(50.0,1000.0,depth); diffuse.rgb=mix(diffuse.rgb,vec3(0.55,0.7,0.77),fogFactor);

1 Like