Hello, Firstly I’m new to the GLSL language. Right now I’m working on porting my code on the CPU side to the GLSL implementation.
[short version]
What is the best way to pass 224 of mat4 and store it in the fragment shader to be able to do calculation using them?
[long version]
In my code i’m doing matrix multiplication to project the 3D points around so I need the camera transformation and parameter which will store in mat4 (I do camera param * camera transform * 3D point). Each camera has 2 mat4 and there are 112 total cameras so there are total of 224 mat4 to be exact. Right now I’m declaring uniform of type array of mat4 in the fragment shader like so,
uniform mat4 cam_views[128];
uniform mat4 cam_params[128];
and I pass the value to the shader like so,
//cam_trans and cam_params is the array of GLfloat of size [16 * 128]
glUniformMatrix4fv(glGetUniformLocation(shaderProgramID, "cam_views"), 128, GL_TRUE, cam_trans);
glUniformMatrix4fv(glGetUniformLocation(shaderProgramID, "cam_params"), 128, GL_TRUE, cam_params);
The problem is when I try to access the uniform in my shader it seem that the value of the uniform is null. My code instantly crash with the read access violation error. Here is an example of the code that will cause the crash in fragment shader. Note if I change cam_views[current_cam] to cam_views[Any number less than 128] it works fine.
for (int current_cam = 0; current_cam < 128; current_cam++) {
vec4 pixel3D_pos_acam = cam_views[current_cam] * pixel3D_coord;
vec4 img_2d_pos = cam_params[current_cam] * pixel3D_pos_acam;
img_2d_pos.x /= img_2d_pos.z;
img_2d_pos.y /= img_2d_pos.z;
fColor = vec4(img_2d_pos.x, 0,0,1); //it run fine without this line
}
So my question is what is the best (and correct) way to pass such a huge array of mat4 to the shader? I heard of using float texture but if I use float texture how can I read the value back and create a mat4 data type? Because I need to do matrix multiplication. Or maybe a uniform buffer? I not quite get the idea how to use any of this.
Extra question: After this I also need to access many (112 arrays) huuugee array of float (360,000 elements) within the shader. I also need to access image data (112 of 600*600 images) within the shader too. So how to pass those 2 huuuge data to the shader? Everything combined needs around 800 mb of memory.
Thank you