I have been working on a shader project using the Processing Java Library. I need to be able to use PShader.set() to pass a 3D array of integers into my GLSL shader.
I tried all of the present set() methods that they have, and none work. It seems processing only supports sending 1D arrays. I cannot find any way of sending a 3D array as a uniform into my GLSL shader.
My only other idea is maybe I can acess the lower level JOGL class and update my uniform variable there.
Also, is there a way that i can update just a few of the items in the array instead of having to pass the entire array to the shader over and over again? The data that i am passing as a uniform is thousands of elements in size. Having to keep and resend the entire thing takes up a lot of RAM and CPU.
If you want to stick with Processing’s calls, you could put your data in an image, pass it to the shader as a texture, do the 3D coordinate index math yourself, and read out the values with texelFetch().
I am fine sending data via jogl, i just need to know how to do it.
Also, is it possible to update a piece of a variable? I only need to change little parts of my uniform, and the fact that it is thousands of values makes it computationally intensive when i just want to update a few of those values
If you’re willing to use direct OpenGL calls, then there are (too) many different buffering mechanisms you can try and at least some of them support sub-buffer updating. I haven’t used any of them other than textures and vertex buffers, though.
You haven’t said what you’re doing with your 3D volume of data, so I just contrived this example for my own amusement and edification.
This code creates a 144x144x144 volume of integer data with noise() scaled up to 1,000,000 and stores it in a texture. The fragment shader shows xy-plane slices of the volume looping from bottom to top. The fetchData() function converts the 3D ijk coordinates into 2D texture coordinates, fetches the data as ARGB, and converts it into an integer.
You haven’t said what you’re doing with your 3D volume of data
I am making a Minecraft style Voxel game. Each element of the 3D array represents a light value (0-15) for that voxel (-1 if the voxel is opaque), since the shader is applied to individual chunks, I need to send the all the light values of the loaded chunks to the shader as if they were connected.
The reason why I wanted to know how to use direct OpenGL Calls and “sub-buffer updating” is so that I dont have to send the entire lightmap array to the shader every time I set a block.
In order to do this, I’m guessing I would need to access processing’s JOGL object (wherever that is) and then update the shader’s uniforms there. Would you be so kind as to show me a code example of how I could do this?
PGL is Processing’s wrapper around JOGL, which, in turn, is a Java wrapper around OpenGL. If you are doing GL calls up to around version 3.3, you can probably use PGL. Otherwise, you’ll want to use gl directly. Nearly all of the tutorials out there are written for C/C++ or for webgl. JOGL mostly works the same except when it comes to passing data as you have to convert Java’s data types into native formats.
I haven’t done anything with creating my own textures which is probably what you would prefer to do, so I don’t have any wisdom to offer there.
In the Processing IDE, bring up the File: examples menu - Demos - Graphics - LowLevelGLVboInterleaved and start from their code. The meat of it is here:
It makes little difference whether you use pgl or gl. pgl is just a wrapper. It simply doesn’t have much of the more modern opengl calls. So you might as well just use gl instead and don’t bother with pgl.