wyldecat
wyldecat

Reputation: 15

Error loading compute shader

I'm implementing simple ray tracing with a compute shader.

But I'm stuck in linking the program object of the compute shader.

#version 440

struct triangle {
    vec3 points[3];
};

struct sphere {
    vec3 pos;
    float r;
};

struct hitinfo {
    vec2 lambda;
    int idx;
};

layout(binding = 0, rgba32f) uniform image2D framebuffer;
// wrriten by compute shader

layout (local_size_x = 1, local_size_y = 1) in;

uniform triangle triangles[2500];
uniform sphere spheres[2500];

uniform int num_triangles;
uniform int num_spheres;

uniform vec3 eye;
uniform vec3 ray00;
uniform vec3 ray10;
uniform vec3 ray01;
uniform vec3 ray11;

Here is my compute shader code and I can get a "Out of resource" error. I know the reason of this error is the size of triangles but I need that size.

Is there any way how a large number of triangles can be passed into the shader?

Upvotes: 0

Views: 102

Answers (1)

BDL
BDL

Reputation: 22170

There is just a very limited amount of uniforms a shader can have. If you need more data then what fits in your uniforms, you can either use Uniform Buffer Objects or Shader Storage Buffer Objects to back up a uniform.

In this case, you will have to define a GLSL Interface Block and bind the buffer to that uniform. This means, that you only need one uniform in order to store a large number of similar elements.

Upvotes: 1

Related Questions