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

Support for Vertex/Fragment layout blocks #205

Open
Nielsbishere opened this issue May 27, 2023 · 0 comments
Open

Support for Vertex/Fragment layout blocks #205

Nielsbishere opened this issue May 27, 2023 · 0 comments

Comments

@Nielsbishere
Copy link

I think it would be really nice and useful to have the ability to define in vertex blocks and out fragment blocks, so GLSL could function somewhat like HLSL. The following syntax would be very handy:

#version 450
layout(location=0) in Vertex {
 	vec2 pos, uv;
 	vec4 col;
} v; 

layout(location=0) out Fragment {
 	vec2 uv;
 	vec4 col; 
} f; 

layout(binding=0, std140) uniform GUIInfo {
 	vec2 res;
 };

 void vert() {
 	f.uv = v.uv;
 	f.col = v.col;
 	gl_Position = vec4(v.pos / res - 1, 0, 1); 
} 

layout(binding=0) uniform sampler2D tex; 
layout(location=0) out Buffer {
 	vec4 col; 
} b; 

void frag() {
 	b.col = f.col * texture(tex, f.uv); 
}

Which could be compiled in two stages or in one. It just reduces code duplication and in big projects that's one of the reasons HLSL is used; because it is easy to write shaders with multiple entrypoints in them. It doesn't matter if you have to compile this in two stages, because with HLSL that's the case as well. Even the renaming 'vert' to 'main' and 'frag' to 'main' would be fine using glslangValidator if this would be supported. I think this would be great; especially if you have multiple compute shaders that are similar but do different things, you could make two separate files and use includes for the majority, but that might make it less clear (especially since these files are finally linked together). Or for something like raytracing shaders it would definitely be a huge relief.

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