gatperdut

08-01-2017, 09:59 PM

Hi all!

Both my fragment and vertex shaders contain the following two guys:

struct Light {

mat4 view;

mat4 proj;

vec4 fragPos;

};

layout (std430, binding = 0) buffer Lights {

Light lights[];

};

My problem is that that last field, fragPos, is computed by the vertex shader like this, but the fragment shader does not see the changes made by the vertex shader in fragPos (or any changes at all):

aLight.fragPos = bias * aLight.proj * aLight.view * vec4(vs_frag_pos, 1.0);

... where aLight is lights[i] in a loop. As you can imagine I'm computing the position of the vertex in the coordinate systems of each light present to be used in shadow mapping. Any idea what's wrong here? Am I doing a fundamentally wrong thing?

Here is how I initialize my storage:

struct LightData {

glm::mat4 view;

glm::mat4 proj;

glm::vec4 fragPos;

};

glGenBuffers(1, &BBO);

glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, BBO);

glNamedBufferStorage(BBO, lights.size() * sizeof(LightData), NULL, GL_DYNAMIC_STORAGE_BIT);

// lights is a vector of a wrapper class for LightData.

for (unsigned int i = 0; i < lights.size(); i++) {

glNamedBufferSubData(BBO, i * sizeof(LightData), sizeof(LightData), &(lights[i]->data));

}

It may be worth noting that if I move fragPos to a fixed-size array out variable in the vertex shader out fragPos[2], leave the results there and then add the fragment shader counterpart in fragPos[2] and use that for the rest of my stuff then things are OK. So what I want to know more about here is why my fragment shader does not see the numbers crunched down by the vertex shader.

Can any of you guy shed some light (heh) on this? Thanks!!

Both my fragment and vertex shaders contain the following two guys:

struct Light {

mat4 view;

mat4 proj;

vec4 fragPos;

};

layout (std430, binding = 0) buffer Lights {

Light lights[];

};

My problem is that that last field, fragPos, is computed by the vertex shader like this, but the fragment shader does not see the changes made by the vertex shader in fragPos (or any changes at all):

aLight.fragPos = bias * aLight.proj * aLight.view * vec4(vs_frag_pos, 1.0);

... where aLight is lights[i] in a loop. As you can imagine I'm computing the position of the vertex in the coordinate systems of each light present to be used in shadow mapping. Any idea what's wrong here? Am I doing a fundamentally wrong thing?

Here is how I initialize my storage:

struct LightData {

glm::mat4 view;

glm::mat4 proj;

glm::vec4 fragPos;

};

glGenBuffers(1, &BBO);

glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, BBO);

glNamedBufferStorage(BBO, lights.size() * sizeof(LightData), NULL, GL_DYNAMIC_STORAGE_BIT);

// lights is a vector of a wrapper class for LightData.

for (unsigned int i = 0; i < lights.size(); i++) {

glNamedBufferSubData(BBO, i * sizeof(LightData), sizeof(LightData), &(lights[i]->data));

}

It may be worth noting that if I move fragPos to a fixed-size array out variable in the vertex shader out fragPos[2], leave the results there and then add the fragment shader counterpart in fragPos[2] and use that for the rest of my stuff then things are OK. So what I want to know more about here is why my fragment shader does not see the numbers crunched down by the vertex shader.

Can any of you guy shed some light (heh) on this? Thanks!!