cf_make_shader¶
Category: graphics
GitHub: cute_graphics.h
Creates a shader from glsl source code.
Parameters | Description |
---|---|
vertex_path | A virtual path to the shader. See Virtual File System. |
Remarks¶
The shader paths must be in the shader directory. See cf_shader_directory. For example, if you call cf_shader_directory with
the path "/assets/shaders"
, you should then supply paths to cf_make_shader relative to the shader directory, and
simply pass in paths such as "/shader.vert
" or "shader.frag"
. This also applies to #include
between shaders.
Note the expected glsl version is 450.
You must setup shader inputs (max of 32 inputs, e.g. in
keyword) and resources sets in a specific way. Use the
following resource sets and ordering in your shaders:
For VERTEX shaders:
For FRAGMENT shaders:
Example VERTEX shader:
layout (set = 0, binding = 0) uniform sampler2D u_image;
layout (set = 1, binding = 0) uniform uniform_block {
vec2 u_texture_size;
};
Example FRAGMENT shader:
layout (set = 2, binding = 0) uniform sampler2D u_image;
layout (set = 3, binding = 0) uniform uniform_block {
vec2 u_texture_size;
};
For uniforms you only have one uniform block available, and it must be named uniform_block
. However, if your
shader is make from the draw api (cf_make_draw_shader) uniform blocks must be named user_uniforms.
Shaders that sit in the shader directory may be #include
'd into another shader. Though, it doesn't work
quite exactly like a C/C++ include, it's very similar -- each shader may be included into another
shader only once. If you try to include a file multiple times (such as circular dependencies,
or if two files try to include the same file) subsequent includes will be ignored.