$darkmode
Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
trail_renderer.h File Reference

GPU-accelerated ribbon trail renderer for N-body simulation. More...

#include "gl_common.h"
#include "nbody.h"
#include <cglm/types.h>
#include <stdbool.h>
Include dependency graph for trail_renderer.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  TrailVertex
 Per-vertex data for the ribbon triangle strip. More...
 
struct  TrailRing
 Ring buffer of recorded positions for one body. More...
 
struct  TrailNeonParams
 Runtime-adjustable neon glow profile parameters. More...
 
struct  TrailRenderer
 Manages trail state and GPU resources for all bodies. More...
 

Enumerations

enum  { TRAIL_MAX_POINTS = 256 }
 
enum  TrailNeonParam { TRAIL_NEON_PARAM_INTENSITY = 0 , TRAIL_NEON_PARAM_CORE , TRAIL_NEON_PARAM_WIDTH , TRAIL_NEON_PARAM_COUNT }
 Identifies which neon parameter is being adjusted. More...
 

Functions

bool trail_renderer_init (TrailRenderer *tr, int body_count)
 Initializes trail renderer resources. More...
 
void trail_renderer_set_color (TrailRenderer *tr, int body_index, const vec3 color)
 Sets the trail color for a specific body. More...
 
void trail_renderer_record (TrailRenderer *tr, const NBodySim *sim, float delta_time)
 Records current positions from the simulation. More...
 
float trail_renderer_get_duration (const TrailRenderer *tr)
 Returns the current trail duration in seconds. More...
 
void trail_renderer_set_duration (TrailRenderer *tr, float duration)
 Sets the trail duration in seconds (clamped to valid range). More...
 
void trail_renderer_draw (TrailRenderer *tr, mat4 view, mat4 proj, vec3 cam_pos)
 Builds ribbon geometry and renders all trails. More...
 
void trail_renderer_clear (TrailRenderer *tr)
 Clears all recorded trail data (e.g., on simulation reset). More...
 
void trail_renderer_cleanup (TrailRenderer *tr)
 Releases all GPU resources. More...
 

Variables

static const float TRAIL_HDR_INTENSITY = 5.0F
 
static const float TRAIL_MAX_WIDTH = 0.24F
 
static const float TRAIL_SAMPLE_INTERVAL = 1.0F / 60.0F
 
static const float TRAIL_DURATION_DEFAULT = 4.0F
 
static const float TRAIL_DURATION_MIN = 0.5F
 
static const float TRAIL_DURATION_MAX = 30.0F
 
static const float TRAIL_DURATION_STEP = 0.5F
 
static const float TRAIL_NEON_INTENSITY_DEFAULT = 5.0F
 
static const float TRAIL_NEON_CORE_EXP_DEFAULT = 12.0F
 
static const float TRAIL_NEON_WIDTH_DEFAULT = 0.24F
 
static const float TRAIL_NEON_INTENSITY_STEP = 0.5F
 
static const float TRAIL_NEON_CORE_STEP = 2.0F
 
static const float TRAIL_NEON_WIDTH_STEP = 0.02F
 
static const float TRAIL_NEON_INTENSITY_MIN = 0.5F
 
static const float TRAIL_NEON_CORE_MIN = 2.0F
 
static const float TRAIL_NEON_WIDTH_MIN = 0.04F
 

Detailed Description

GPU-accelerated ribbon trail renderer for N-body simulation.

Records positions over time for each body and renders camera-facing ribbon geometry with:

  • Width tapering (thick at head, zero at tail)
  • Soft anti-aliased edges via fragment shader smoothstep
  • HDR emissive colors for bloom integration
  • Additive blending for glow accumulation

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Maximum trail sample points per body.

Enumerator
TRAIL_MAX_POINTS 

◆ TrailNeonParam

Identifies which neon parameter is being adjusted.

Enumerator
TRAIL_NEON_PARAM_INTENSITY 
TRAIL_NEON_PARAM_CORE 
TRAIL_NEON_PARAM_WIDTH 
TRAIL_NEON_PARAM_COUNT 

Function Documentation

◆ trail_renderer_cleanup()

void trail_renderer_cleanup ( TrailRenderer *  tr)

Releases all GPU resources.

Parameters
trPointer to the trail renderer.
Here is the call graph for this function:

◆ trail_renderer_clear()

void trail_renderer_clear ( TrailRenderer *  tr)

Clears all recorded trail data (e.g., on simulation reset).

Parameters
trPointer to the trail renderer.

◆ trail_renderer_draw()

void trail_renderer_draw ( TrailRenderer *  tr,
mat4  view,
mat4  proj,
vec3  cam_pos 
)

Builds ribbon geometry and renders all trails.

Must be called while the HDR framebuffer is active (before post-process). Sets up additive blending and depth-read-no-write internally.

Parameters
trPointer to the trail renderer.
viewView matrix.
projProjection matrix.
cam_posCamera world position.
Here is the call graph for this function:

◆ trail_renderer_get_duration()

float trail_renderer_get_duration ( const TrailRenderer *  tr)

Returns the current trail duration in seconds.

◆ trail_renderer_init()

bool trail_renderer_init ( TrailRenderer *  tr,
int  body_count 
)

Initializes trail renderer resources.

Parameters
trPointer to the trail renderer.
body_countNumber of bodies to track.
Returns
true on success, false on failure.
Here is the call graph for this function:

◆ trail_renderer_record()

void trail_renderer_record ( TrailRenderer *  tr,
const NBodySim *  sim,
float  delta_time 
)

Records current positions from the simulation.

Should be called every frame. Internally rate-limits sampling.

Parameters
trPointer to the trail renderer.
simPointer to the N-body simulation.
delta_timeFrame delta time.
Here is the call graph for this function:

◆ trail_renderer_set_color()

void trail_renderer_set_color ( TrailRenderer *  tr,
int  body_index,
const vec3  color 
)

Sets the trail color for a specific body.

Parameters
trPointer to the trail renderer.
body_indexBody index.
colorHDR emissive color (values > 1.0 are valid for bloom).

◆ trail_renderer_set_duration()

void trail_renderer_set_duration ( TrailRenderer *  tr,
float  duration 
)

Sets the trail duration in seconds (clamped to valid range).

Variable Documentation

◆ TRAIL_DURATION_DEFAULT

const float TRAIL_DURATION_DEFAULT = 4.0F
static

Default trail duration in seconds (how long a trail persists).

◆ TRAIL_DURATION_MAX

const float TRAIL_DURATION_MAX = 30.0F
static

◆ TRAIL_DURATION_MIN

const float TRAIL_DURATION_MIN = 0.5F
static

Minimum / maximum trail duration for runtime adjustment.

◆ TRAIL_DURATION_STEP

const float TRAIL_DURATION_STEP = 0.5F
static

◆ TRAIL_HDR_INTENSITY

const float TRAIL_HDR_INTENSITY = 5.0F
static

HDR intensity multiplier — drives bloom for neon glow effect.

◆ TRAIL_MAX_WIDTH

const float TRAIL_MAX_WIDTH = 0.24F
static

Maximum ribbon half-width in world units.

◆ TRAIL_NEON_CORE_EXP_DEFAULT

const float TRAIL_NEON_CORE_EXP_DEFAULT = 12.0F
static

◆ TRAIL_NEON_CORE_MIN

const float TRAIL_NEON_CORE_MIN = 2.0F
static

◆ TRAIL_NEON_CORE_STEP

const float TRAIL_NEON_CORE_STEP = 2.0F
static

◆ TRAIL_NEON_INTENSITY_DEFAULT

const float TRAIL_NEON_INTENSITY_DEFAULT = 5.0F
static

Default neon parameter values.

◆ TRAIL_NEON_INTENSITY_MIN

const float TRAIL_NEON_INTENSITY_MIN = 0.5F
static

◆ TRAIL_NEON_INTENSITY_STEP

const float TRAIL_NEON_INTENSITY_STEP = 0.5F
static

◆ TRAIL_NEON_WIDTH_DEFAULT

const float TRAIL_NEON_WIDTH_DEFAULT = 0.24F
static

◆ TRAIL_NEON_WIDTH_MIN

const float TRAIL_NEON_WIDTH_MIN = 0.04F
static

◆ TRAIL_NEON_WIDTH_STEP

const float TRAIL_NEON_WIDTH_STEP = 0.02F
static

◆ TRAIL_SAMPLE_INTERVAL

const float TRAIL_SAMPLE_INTERVAL = 1.0F / 60.0F
static

Minimum time between trail samples (seconds).