Skip to content

cf_make_draw3d_shape_shader

Category: draw3d
GitHub: cute_draw3d.h


Compiles a user shape shader from a file, for customizing built-in 3d shape rendering.

CF_Shader cf_make_draw3d_shape_shader(const char* virtual_path);
Parameters Description
virtual_path A virtual path to the shader snippet (see the Virtual File System topic).

Remarks

The 3d analog of the 2d draw shader contract: your snippet defines

vec4 shader(vec4 color, ShapeParams params)

which post-processes the built-in result of every shape drawn while the shader is pushed (cf_draw3d_push_shader). Strokes arrive premultiplied with local AA and thin-line fading already applied -- scale the whole vec4 or lerp with mix(color, tint * color.a, t) to stay premultiplied-safe; solids arrive hemisphere-lit with straight alpha. ShapeParams provides:

struct ShapeParams
{
    vec3 world_pos;   // Fragment world position on the stroke ribbon / solid surface.
    vec3 eye;         // Camera world position.
    vec3 normal;      // Solid surface normal; camera-facing for strokes.
    float sdf;        // Strokes: signed world-space distance to the stroke edge. Solids: 0.
    float fade;       // Thin-stroke fade already baked into color. Solids: 1.
    float kind;       // 0 line/arc body, 1 ring, 2 filled disc, 3 solid.
    vec4 attributes;  // cf_draw3d_push_mesh_attributes, captured per shape.
};

Declare samplers at set = 2 and your uniform block at set = 3, binding = 1 (binding 0 belongs to the built-ins), named shd_uniforms -- exactly like 2d draw shaders. Values flow through cf_draw3d_set_uniform and cf_draw3d_set_texture as usual. Destroy the returned shader with cf_destroy_shader. Snippets under cf_shader_directory hot-reload in place while you edit, exactly like 2d draw shaders.

cf_make_draw3d_shape_shader_from_source
cf_draw3d_push_shader
cf_draw3d_set_uniform
cf_draw3d_push_mesh_attributes