Skip to content

cf_make_shader

Category: graphics
GitHub: cute_graphics.h


Creates a shader from glsl source code.

CF_Shader cf_make_shader(const char* vertex_path, const char* fragment_path);
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:

    0: Sampled textures, followed by storage textures, followed by storage buffers
    1: Uniform buffers

For FRAGMENT shaders:

    2: Sampled textures, followed by storage textures, followed by storage buffers
    3: Uniform buffers

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.

CF_Shader
CF_Material
cf_shader_directory
cf_apply_shader