Kohi Game Engine
light_system.h File Reference

This file contains the implementation of the light system, which manages all lighting objects within the engine. More...

#include <defines.h>
#include <math/math_types.h>
#include "core/engine.h"
#include "core/frame_data.h"
#include "core_resource_types.h"
#include "renderer/renderer_types.h"
#include "utils/kcolour.h"

Go to the source code of this file.

Data Structures

struct  klight_attenuation
 
struct  klight_data
 
struct  klight_render_data
 
struct  kdirectional_light_data
 
struct  light_shader_data
 
struct  light_global_ssbo_data
 
struct  light_system_state
 

Macros

#define KRENDERBUFFER_NAME_LIGHTING_GLOBAL   "Kohi.StorageBuffer.LightingGlobal"
 
#define KLIGHT_INVALID   INVALID_ID_U8
 
#define MAX_GLOBAL_SSBO_LIGHTS   256
 

Typedefs

typedef struct klight_attenuation klight_attenuation
 
typedef enum klight_type klight_type
 
typedef struct klight_data klight_data
 
typedef u8 klight
 
typedef struct klight_render_data klight_render_data
 
typedef struct kdirectional_light_data kdirectional_light_data
 
typedef struct light_shader_data light_shader_data
 
typedef struct light_global_ssbo_data light_global_ssbo_data
 
typedef struct light_system_state light_system_state
 

Enumerations

enum  klight_type { KLIGHT_TYPE_UNDEFINED , KLIGHT_TYPE_POINT , KLIGHT_TYPE_DIRECTIONAL }
 

Functions

b8 light_system_initialize (u64 *memory_requirement, light_system_state *memory, void *config)
 Initializes the light system. As with most systems, this should be called twice, the first time to obtain the memory requirement (where memory=0), and a second time passing allocated memory the size of memory_requirement. More...
 
void light_system_shutdown (light_system_state *state)
 Shuts down the light system, releasing all resources. More...
 
void light_system_frame_prepare (light_system_state *state, frame_data *p_frame_data)
 
KAPI klight point_light_create (light_system_state *state, vec3 position, colour3 colour, f32 constant_f, f32 linear, f32 quadratic)
 
KAPI klight directional_light_create (light_system_state *state, vec3 direction, colour3 colour)
 
KAPI vec3 directional_light_get_direction (light_system_state *state, klight light)
 
KAPI colour3 directional_light_get_colour (light_system_state *state, klight light)
 
KAPI vec3 point_light_get_position (light_system_state *state, klight light)
 
KAPI colour3 point_light_get_colour (light_system_state *state, klight light)
 
KAPI void directional_light_set_direction (light_system_state *state, klight light, vec3 direction)
 
KAPI void point_light_set_position (light_system_state *state, klight light, vec3 position)
 
KAPI void point_light_set_colour (light_system_state *state, klight light, colour3 colour)
 
KAPI f32 point_light_radius_get (light_system_state *state, klight light)
 
KAPI void light_destroy (light_system_state *state, klight light)
 
KAPI klight_data light_get_data (light_system_state *state, klight light)
 

Detailed Description

This file contains the implementation of the light system, which manages all lighting objects within the engine.

Author
Travis Vroman (travi.nosp@m.s@ko.nosp@m.hieng.nosp@m.ine..nosp@m.com)
Version
1.0
Date
2023-03-02

Macro Definition Documentation

◆ KLIGHT_INVALID

#define KLIGHT_INVALID   INVALID_ID_U8

◆ KRENDERBUFFER_NAME_LIGHTING_GLOBAL

#define KRENDERBUFFER_NAME_LIGHTING_GLOBAL   "Kohi.StorageBuffer.LightingGlobal"

◆ MAX_GLOBAL_SSBO_LIGHTS

#define MAX_GLOBAL_SSBO_LIGHTS   256

Typedef Documentation

◆ kdirectional_light_data

◆ klight

typedef u8 klight

◆ klight_attenuation

◆ klight_data

typedef struct klight_data klight_data

◆ klight_render_data

◆ klight_type

typedef enum klight_type klight_type

◆ light_global_ssbo_data

◆ light_shader_data

◆ light_system_state

Enumeration Type Documentation

◆ klight_type

Enumerator
KLIGHT_TYPE_UNDEFINED 
KLIGHT_TYPE_POINT 
KLIGHT_TYPE_DIRECTIONAL 

Function Documentation

◆ directional_light_create()

KAPI klight directional_light_create ( light_system_state state,
vec3  direction,
colour3  colour 
)

◆ directional_light_get_colour()

KAPI colour3 directional_light_get_colour ( light_system_state state,
klight  light 
)

◆ directional_light_get_direction()

KAPI vec3 directional_light_get_direction ( light_system_state state,
klight  light 
)

◆ directional_light_set_direction()

KAPI void directional_light_set_direction ( light_system_state state,
klight  light,
vec3  direction 
)

◆ light_destroy()

KAPI void light_destroy ( light_system_state state,
klight  light 
)

◆ light_get_data()

KAPI klight_data light_get_data ( light_system_state state,
klight  light 
)

◆ light_system_frame_prepare()

void light_system_frame_prepare ( light_system_state state,
frame_data p_frame_data 
)

◆ light_system_initialize()

b8 light_system_initialize ( u64 memory_requirement,
light_system_state memory,
void *  config 
)

Initializes the light system. As with most systems, this should be called twice, the first time to obtain the memory requirement (where memory=0), and a second time passing allocated memory the size of memory_requirement.

Parameters
memory_requirementA pointer to hold the memory requirement.
memoryBlock of allocated memory, or 0 if requesting memory requirement.
configConfiguration for this system. Currently unused.
Returns
True on success; otherwise false.

◆ light_system_shutdown()

void light_system_shutdown ( light_system_state state)

Shuts down the light system, releasing all resources.

Parameters
stateThe state/memory block for the system.

◆ point_light_create()

KAPI klight point_light_create ( light_system_state state,
vec3  position,
colour3  colour,
f32  constant_f,
f32  linear,
f32  quadratic 
)

◆ point_light_get_colour()

KAPI colour3 point_light_get_colour ( light_system_state state,
klight  light 
)

◆ point_light_get_position()

KAPI vec3 point_light_get_position ( light_system_state state,
klight  light 
)

◆ point_light_radius_get()

KAPI f32 point_light_radius_get ( light_system_state state,
klight  light 
)

◆ point_light_set_colour()

KAPI void point_light_set_colour ( light_system_state state,
klight  light,
colour3  colour 
)

◆ point_light_set_position()

KAPI void point_light_set_position ( light_system_state state,
klight  light,
vec3  position 
)