Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shaders in same file can't have different slot assignment? #28

Open
mattiasljungstrom opened this issue Dec 11, 2019 · 0 comments
Open

Comments

@mattiasljungstrom
Copy link
Contributor

mattiasljungstrom commented Dec 11, 2019

If a shader file contains two shaders which use the same sampler name, but is assigned to different slots, the compilation will fail. I'm not sure if this is a bug or not, but I don't understand why it's required. It makes it hard to re-use code with blocks.

The same applies to uniform block names in different shaders in same file.

Example:

@vs vs
@glsl_options flip_vert_y
layout(location=0) in vec2 a_position;
out vec2 v_uv;

void main() {
    gl_Position = vec4(a_position, 0., 1.);
    v_uv = a_position * vec2(.5, -.5) + vec2(.5, .5);
}
@end

@fs fs_1
in vec2 v_uv;
out vec4 out_color;

layout(binding=0) uniform sampler2D s_texture;

void main() {
    vec3 color = texture(s_texture, v_uv).rgb;
    out_color = vec4(color, 1.0);
}
@end

@fs fs_2
in vec2 v_uv;
out vec4 out_color;

layout(binding=0) uniform sampler2D s_background;
layout(binding=1) uniform sampler2D s_texture;                      // error here

void main() {
    vec3 color = texture(s_background, v_uv).rgb + texture(s_texture, v_uv).rgb;
    out_color = vec4(color, 1.0);
}
@end

@program shader1 vs fs_1
@program shader2 vs fs_2

Error:

conflicting texture definitions found for 's_texture'

This example can be fixed trivially by switching s_background and s_texture slots, but it's not always that simple if you have more than two variants of the shader which uses different nr of textures. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant