Skip to content
modkitv0.2

lighting.h

#include <modkit/lighting.h>14 functions · 2 structs · 4 enums · 6 typedefs · 3 macros

Frame-level lighting environment (separate from materials).

Materials own no lights. Lighting is a persistent, transactionally replaced list snapshotted at frame begin. A default directional headlight remains active until the application explicitly mutates the direct-light list.

Functions

mk_light_distance_attenuationfunction

float mk_light_distance_attenuation(float distance, float range)

CPU mirrors of the shader's glTF punctual attenuation rules.

ParameterTypeDescription
distancefloatValue for distance.
rangefloatValue for range.

Returns The resulting value.

mk_light_spot_attenuationfunction

float mk_light_spot_attenuation(float actual_cosine, float inner_cone_angle, float outer_cone_angle)

Perform the light spot attenuation operation.

ParameterTypeDescription
actual_cosinefloatValue for actual cosine.
inner_cone_anglefloatValue for inner cone angle.
outer_cone_anglefloatValue for outer cone angle.

Returns The resulting value.

mk_lighting_applyfunction

void mk_lighting_apply(struct mk_draw_desc *out)

Apply lighting.

ParameterTypeDescription
outstruct mk_draw_desc *Value for out.

mk_lighting_frame_beginfunction

void mk_lighting_frame_begin(void)

Begin lighting frame.

mk_lighting_get_statsfunction

void mk_lighting_get_stats(mk_lighting_stats *out)

Copy current lighting statistics.

ParameterTypeDescription
outmk_lighting_stats *Value for out.

mk_lighting_system_initfunction

void mk_lighting_system_init(void)

Initialize the lighting system.

mk_lighting_system_shutdownfunction

void mk_lighting_system_shutdown(void)

Perform the lighting system shutdown operation.

mk_lights_effective_forward_capacityfunction

uint32_t mk_lights_effective_forward_capacity(void)

Effective bounded-forward capacity for this build/backend profile.

Returns The resulting value.

mk_lights_setfunction

bool mk_lights_set(const mk_light_desc *lights, uint16_t count)

Transactionally replace the persistent direct-light list.

This function is thread-safe; the new generation becomes visible at the next frame begin. Passing NULL, 0 explicitly disables direct lighting.

ParameterTypeDescription
lightsconst mk_light_desc *Value for lights.
countuint16_tNumber of entries.

Returns True when the operation succeeds.

mk_set_ambientfunction

void mk_set_ambient(uint32_t ambient)

Set just the ambient term (0xRRGGBBAA, alpha ignored).

ParameterTypeDescription
ambientuint32_tValue for ambient.

mk_set_clearcoat_enabledfunction

void mk_set_clearcoat_enabled(bool enabled)

Frame-global toggle for the PBR clearcoat lobe (KHR_materials_clearcoat).

Default on; disabling zeroes the effective clearcoat factor in-shader for ALL materials,

ParameterTypeDescription
enabledboolWhether the feature is enabled. so you can A/B the coating without editing assets. A viewer/debug aid.

mk_set_debug_viewfunction

void mk_set_debug_view(int channel)

Frame-global debug visualization channel (0 = off / normal shading).

The PBR shader interprets the value to render a single surface input (base color, normal, metallic, roughness, AO, the IBL terms, etc.) instead of the lit result a glTF-viewer-style inspector. Channel IDs are in pbr.h

ParameterTypeDescription
channelintValue for channel. (mk_pbr_debug_channel). Materials that don't implement debug ignore it.

mk_set_lightfunction

void mk_set_light(mk_vec3 dir, uint32_t color, uint32_t ambient)

Set the directional light.

dir is the direction the light travels (e.g. pointing down/forward). color/ambient are packed 0xRRGGBBAA (the modkit color

ParameterTypeDescription
dirmk_vec3Value for dir.
coloruint32_tValue for color.
ambientuint32_tValue for ambient. convention); the alpha byte is ignored, so white is 0xFFFFFFFF.

mk_set_sheen_enabledfunction

void mk_set_sheen_enabled(bool enabled)

Frame-global toggle for KHR_materials_sheen.

ParameterTypeDescription
enabledboolWhether the feature is enabled.

Structs

mk_light_descstruct

World-space punctual light.

A range of zero means infinite/omitted.

FieldTypeDescription
typemk_light_typeThe type.
flagsuint32_tThe flags.
colorfloatThe color.
intensityfloatThe intensity.
positionfloatThe position.
rangefloatThe range.
directionfloatThe direction.
inner_cone_anglefloatThe inner cone angle.
outer_cone_anglefloatThe outer cone angle.
priorityint32_tThe priority.

mk_lighting_statsstruct

Data for lighting stats.

FieldTypeDescription
staged_generationuint64_tThe staged generation.
frame_generationuint64_tThe frame generation.
shadow_light_generationuint64_tThe shadow light generation.
submitted_lightsuint32_tThe submitted lights.
enabled_lightsuint32_tThe enabled lights.
effective_forward_capacityuint32_tThe effective forward capacity.
forward_selecteduint32_tThe forward selected.
forward_truncateduint32_tThe forward truncated.
shadow_requesteduint32_tThe shadow requested.
shadow_rendereduint32_tThe shadow rendered.
shadow_downscaleduint32_tThe shadow downscaled.
shadow_droppeduint32_tThe shadow dropped.
shadow_stale_keyuint32_tThe shadow stale key.
shadow_sampler_limiteduint32_tThe shadow sampler limited.
shadow_missing_distanceuint32_tThe shadow missing distance.
cluster_overflow_clustersuint32_tThe cluster overflow clusters.
cluster_dropped_indicesuint32_tThe cluster dropped indices.
legacy_pbr_downgradesuint32_tThe legacy PBR downgrades.
pathmk_lighting_pathThe path.
fallback_reasonmk_lighting_fallback_reasonThe fallback reason.
shadow_depth_modeuint8_tThe shadow depth mode.
implicit_default_headlightboolThe implicit default headlight.
shadow_reusedboolThe shadow reused.

Enums

mk_light_flagsenum

Values for light flags.

ValueDescription
MK_LIGHT_ENABLEDSelects enabled.
MK_LIGHT_CAST_SHADOWSSelects cast shadows.

mk_light_typeenum

Values for light type.

ValueDescription
MK_LIGHT_DIRECTIONALSelects directional.
MK_LIGHT_POINTSelects point.
MK_LIGHT_SPOTSelects spot.

mk_lighting_fallback_reasonenum

Values for lighting fallback reason.

ValueDescription
MK_LIGHTING_FALLBACK_NONESelects none.
MK_LIGHTING_FALLBACK_UNSUPPORTEDSelects unsupported.
MK_LIGHTING_FALLBACK_ALLOCATIONSelects allocation.
MK_LIGHTING_FALLBACK_SHADERSelects shader.
MK_LIGHTING_FALLBACK_CAMERASelects camera.
MK_LIGHTING_FALLBACK_DISPATCHSelects dispatch.
MK_LIGHTING_FALLBACK_CAPACITYSelects capacity.

mk_lighting_pathenum

Values for lighting path.

ValueDescription
MK_LIGHTING_PATH_FORWARDSelects forward.
MK_LIGHTING_PATH_CLUSTEREDSelects clustered.

Typedefs

mk_light_desctypedef

typedef struct mk_light_desc mk_light_desc

World-space punctual light.

A range of zero means infinite/omitted.

mk_light_flagstypedef

typedef enum mk_light_flags mk_light_flags

Values for light flags.

mk_light_typetypedef

typedef enum mk_light_type mk_light_type

Values for light type.

mk_lighting_fallback_reasontypedef

typedef enum mk_lighting_fallback_reason mk_lighting_fallback_reason

Values for lighting fallback reason.

mk_lighting_pathtypedef

typedef enum mk_lighting_path mk_lighting_path

Values for lighting path.

mk_lighting_statstypedef

typedef struct mk_lighting_stats mk_lighting_stats

Data for lighting stats.

Macros

MODKIT_GL21_FORWARD_LIGHTSdefine

MODKIT_GL21_FORWARD_LIGHTS

Constant for modkit gl21 forward lights.

MODKIT_MAX_FORWARD_LIGHTSdefine

MODKIT_MAX_FORWARD_LIGHTS

Maximum supported modkit forward lights.

MODKIT_MAX_LIGHTSdefine

MODKIT_MAX_LIGHTS

Maximum supported modkit lights.