Antoine
08-31-2010, 02:58 AM
Hi,
I'm trying to create a program, based on 2 shaders:
- The first one contains a list of functions that use the content of a uniform block.
- The second one, which contains the main() method, also uses the same uniform block.
My shaders look like this:
layout (shared) uniform camera { // layout should not be necessary
mat4 localToScreen;
mat4 localToWorld;
vec3 worldCameraPos;
};
layout(location = 0) in vec3 vertex;
void projection() {
gl_Position = localToScreen * vec4(vertex, 1.0);
}
And the second shader:
layout (shared) uniform camera { // layout should not be necessary
mat4 localToScreen;
mat4 localToWorld;
vec3 worldCameraPos;
};
layout(location = 0) in vec3 vertex;
void projection(vec3 normal, out vec3 worldPos, out vec3 worldNormal);
void main() {
//shading stuff here that uses projection()
}
This worked fine when just using uniforms, but when trying to use UniformBlocks, i get a linker error that says that declaration of camera conflicts with previous declaration (C1038)...
So i checked what uniforms were available (By replacing uniform names with "camera1" and "camera2"), and it appears that every uniform in the block from the first shader gets optimized out, despite the shared layout specifier.
Also, members of a block can be optimized out if they are found by the implementation to not affect the result of the shader.
Is this because there is no main() in the first shader to affect?
Is this the correct behavior? Am I doing something wrong here?
Thanks in advance...
Antoine B.
Edit : I am using GLSL #version 400
I'm trying to create a program, based on 2 shaders:
- The first one contains a list of functions that use the content of a uniform block.
- The second one, which contains the main() method, also uses the same uniform block.
My shaders look like this:
layout (shared) uniform camera { // layout should not be necessary
mat4 localToScreen;
mat4 localToWorld;
vec3 worldCameraPos;
};
layout(location = 0) in vec3 vertex;
void projection() {
gl_Position = localToScreen * vec4(vertex, 1.0);
}
And the second shader:
layout (shared) uniform camera { // layout should not be necessary
mat4 localToScreen;
mat4 localToWorld;
vec3 worldCameraPos;
};
layout(location = 0) in vec3 vertex;
void projection(vec3 normal, out vec3 worldPos, out vec3 worldNormal);
void main() {
//shading stuff here that uses projection()
}
This worked fine when just using uniforms, but when trying to use UniformBlocks, i get a linker error that says that declaration of camera conflicts with previous declaration (C1038)...
So i checked what uniforms were available (By replacing uniform names with "camera1" and "camera2"), and it appears that every uniform in the block from the first shader gets optimized out, despite the shared layout specifier.
Also, members of a block can be optimized out if they are found by the implementation to not affect the result of the shader.
Is this because there is no main() in the first shader to affect?
Is this the correct behavior? Am I doing something wrong here?
Thanks in advance...
Antoine B.
Edit : I am using GLSL #version 400