$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
light_probes.c File Reference
#include <glad/glad.h>
#include "light_probes.h"
#include "log.h"
#include "perf_timer.h"
#include "profiler.h"
#include "render_utils.h"
#include "shader.h"
#include "utils.h"
#include <float.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
Include dependency graph for light_probes.c:

Data Structures

struct  CachedSphere
 

Macros

#define M_PI   3.14159265358979323846
 
#define USE_SH_BAKE_FACTORS   1
 
#define SH_COEFF_COUNT   9
 
#define GI_BOUNCE_SCALE   2.0F
 
#define GI_MIN_DIST_RADII   1.05F
 
#define GI_MAX_DIST_RADII   3.0F
 
#define GI_EPSILON   0.000001F
 
#define GI_HALF   0.5F
 
#define GI_ZERO   0.0F
 

Enumerations

enum  { GI_DEBUG_PROBE_VERTICES = 6 , GI_WIRE_CUBE_VERTICES = 24 , GI_LOG_BUF_SIZE = 128 , GI_SMALL_LOG_BUF_SIZE = 64 }
 

Functions

static void get_sphere_pos (const SphereInstance_POD *sphere, vec3 dest)
 
static float get_sphere_radius (const SphereInstance_POD *sphere)
 
void light_probe_grid_compute_aabb (LightProbeGrid *grid, const void *spheres, int count, size_t stride, float padding)
 Computes the AABB for the grid based on sphere instances. More...
 
void light_probe_grid_init_cpu (LightProbeGrid *grid, int dim_x, int dim_y, int dim_z)
 Initializes the grid structure (CPU only). More...
 
void light_probe_grid_free_cpu (LightProbeGrid *grid)
 Cleans up CPU resources. More...
 
static void compute_probe_sh (const CachedSphere *cached_scene, int local_count, vec3 probe_pos, SH9 *sh_data)
 
static int is_probe_inside_sphere (vec3 probe_pos, const CachedSphere *cached_scene, int local_count)
 
static void light_probe_worker_compute_probe (LightProbeGrid *grid, int grid_x, int grid_y, int grid_z, const CachedSphere *cached_scene, int local_count)
 
static void * precompute_cached_spheres (SphereInstance_POD *local_scene, int local_count)
 
static void * light_probe_worker (void *arg)
 
void light_probe_grid_init (LightProbeGrid *grid, int dim_x, int dim_y, int dim_z)
 Initializes the grid structure, creates SSBO, and starts worker thread. More...
 
void light_probe_grid_set_bounds (LightProbeGrid *grid, vec3 aabb_min, vec3 aabb_max)
 Sets the grid AABB and computes cell sizes from dimensions. More...
 
void light_probe_grid_set_scene (LightProbeGrid *grid, const void *spheres, int count, size_t stride)
 Updates the scene data used by the grid (copies it). More...
 
void light_probe_grid_update_async (LightProbeGrid *grid)
 Signals the worker thread to perform an SH update. More...
 
void light_probe_grid_sync (LightProbeGrid *grid)
 Checks if results are ready and uploads to GPU. Should be called on main thread. More...
 
void light_probe_grid_cleanup (LightProbeGrid *grid)
 Cleans up all resources (CPU, GPU, Threads). More...
 
void light_probe_render_debug (LightProbeGrid *grid, mat4 view, mat4 proj)
 Renders debug spheres for the probes. More...
 

Macro Definition Documentation

◆ GI_BOUNCE_SCALE

#define GI_BOUNCE_SCALE   2.0F

◆ GI_EPSILON

#define GI_EPSILON   0.000001F

◆ GI_HALF

#define GI_HALF   0.5F

◆ GI_MAX_DIST_RADII

#define GI_MAX_DIST_RADII   3.0F

◆ GI_MIN_DIST_RADII

#define GI_MIN_DIST_RADII   1.05F

◆ GI_ZERO

#define GI_ZERO   0.0F

◆ M_PI

#define M_PI   3.14159265358979323846

◆ SH_COEFF_COUNT

#define SH_COEFF_COUNT   9

◆ USE_SH_BAKE_FACTORS

#define USE_SH_BAKE_FACTORS   1

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
GI_DEBUG_PROBE_VERTICES 
GI_WIRE_CUBE_VERTICES 
GI_LOG_BUF_SIZE 
GI_SMALL_LOG_BUF_SIZE 

Function Documentation

◆ compute_probe_sh()

static void compute_probe_sh ( const CachedSphere cached_scene,
int  local_count,
vec3  probe_pos,
SH9 sh_data 
)
static
Here is the call graph for this function:

◆ get_sphere_pos()

static void get_sphere_pos ( const SphereInstance_POD sphere,
vec3  dest 
)
static

◆ get_sphere_radius()

static float get_sphere_radius ( const SphereInstance_POD sphere)
static

◆ is_probe_inside_sphere()

static int is_probe_inside_sphere ( vec3  probe_pos,
const CachedSphere cached_scene,
int  local_count 
)
static

◆ light_probe_grid_cleanup()

void light_probe_grid_cleanup ( LightProbeGrid grid)

Cleans up all resources (CPU, GPU, Threads).

Here is the call graph for this function:

◆ light_probe_grid_compute_aabb()

void light_probe_grid_compute_aabb ( LightProbeGrid grid,
const void *  spheres,
int  count,
size_t  stride,
float  padding 
)

Computes the AABB for the grid based on sphere instances.

Parameters
gridPointer to grid.
spheresArray of sphere instances (generic pointer to avoid GL dep in header if needed).
countNumber of spheres.
strideStride between spheres.
paddingPadding to add to the AABB.
Here is the call graph for this function:

◆ light_probe_grid_free_cpu()

void light_probe_grid_free_cpu ( LightProbeGrid grid)

Cleans up CPU resources.

◆ light_probe_grid_init()

void light_probe_grid_init ( LightProbeGrid grid,
int  dim_x,
int  dim_y,
int  dim_z 
)

Initializes the grid structure, creates SSBO, and starts worker thread.

Here is the call graph for this function:

◆ light_probe_grid_init_cpu()

void light_probe_grid_init_cpu ( LightProbeGrid grid,
int  dim_x,
int  dim_y,
int  dim_z 
)

Initializes the grid structure (CPU only).

Parameters
gridPointer to grid.
dim_xGrid dimension X.
dim_yGrid dimension Y.
dim_zGrid dimension Z.

◆ light_probe_grid_set_bounds()

void light_probe_grid_set_bounds ( LightProbeGrid grid,
vec3  aabb_min,
vec3  aabb_max 
)

Sets the grid AABB and computes cell sizes from dimensions.

◆ light_probe_grid_set_scene()

void light_probe_grid_set_scene ( LightProbeGrid grid,
const void *  spheres,
int  count,
size_t  stride 
)

Updates the scene data used by the grid (copies it).

Here is the call graph for this function:

◆ light_probe_grid_sync()

void light_probe_grid_sync ( LightProbeGrid grid)

Checks if results are ready and uploads to GPU. Should be called on main thread.

◆ light_probe_grid_update_async()

void light_probe_grid_update_async ( LightProbeGrid grid)

Signals the worker thread to perform an SH update.

◆ light_probe_render_debug()

void light_probe_render_debug ( LightProbeGrid grid,
mat4  view,
mat4  proj 
)

Renders debug spheres for the probes.

Parameters
gridPointer to grid.
viewView matrix.
projProjection matrix.
Here is the call graph for this function:

◆ light_probe_worker()

static void* light_probe_worker ( void *  arg)
static
Here is the call graph for this function:

◆ light_probe_worker_compute_probe()

static void light_probe_worker_compute_probe ( LightProbeGrid grid,
int  grid_x,
int  grid_y,
int  grid_z,
const CachedSphere cached_scene,
int  local_count 
)
static
Here is the call graph for this function:

◆ precompute_cached_spheres()

static void* precompute_cached_spheres ( SphereInstance_POD local_scene,
int  local_count 
)
static
Here is the call graph for this function: