$darkmode
High-level post-processing pipeline and effects. More...
#include "effects/fx_auto_exposure.h"#include "effects/fx_bloom.h"#include "effects/fx_dof.h"#include "effects/fx_lut3d.h"#include "effects/fx_lut_viz.h"#include "effects/fx_motion_blur.h"#include "gl_common.h"#include "gpu_profiler.h"#include "shader.h"#include <cglm/cglm.h>#include <cglm/types.h>Go to the source code of this file.
Data Structures | |
| struct | ColorGradingParams |
| Unreal-style color grading parameters. More... | |
| struct | VignetteParams |
| Controls for the screen-edge darkening effect. More... | |
| struct | GrainParams |
| Fine-grained controls for film noise. More... | |
| struct | ExposureParams |
| Manual exposure tuning. More... | |
| struct | ChromAbberationParams |
| Focal-length distortion simulation. More... | |
| struct | WhiteBalanceParams |
| Temperature and tint correction. More... | |
| struct | TonemapParams |
| ACES-like filmic tonemapping curve parameters. More... | |
| struct | FXAAParams |
| Parameters for Fast Approximate Anti-Aliasing. More... | |
| struct | BandingParams |
| Controls for color banding/quantization. More... | |
| struct | FogParams |
| Depth-based atmospheric fog parameters. More... | |
| struct | ShaderCacheEntry |
| Cache entry for optimized shaders. More... | |
| struct | PostProcessUBO |
| Shared Uniform Buffer structure for shaders. More... | |
| struct | PostProcess |
| Main pipeline state for post-processing. More... | |
| struct | PostProcessPreset |
| Snapshot of every configurable parameter in the pipeline. More... | |
Enumerations | |
| enum | PostProcessEffect { POSTFX_VIGNETTE = (1U << 0U) , POSTFX_GRAIN = (1U << 1U) , POSTFX_EXPOSURE = (1U << 2U) , POSTFX_CHROM_ABBR = (1U << 3U) , POSTFX_BLOOM = (1U << 4U) , POSTFX_COLOR_GRADING , POSTFX_DOF = (1U << 6U) , POSTFX_DOF_DEBUG = (1U << 7U) , POSTFX_AUTO_EXPOSURE , POSTFX_EXPOSURE_DEBUG , POSTFX_MOTION_BLUR = (1U << 10U) , POSTFX_MOTION_BLUR_DEBUG , POSTFX_FXAA = (1U << 12U) , POSTFX_FXAA_DEBUG = (1U << 13U) , POSTFX_BANDING = (1U << 14U) , POSTFX_VECTOR_FIELD_DEBUG , POSTFX_STENCIL_DEBUG = (1U << 16U) , POSTFX_BLOOM_DEBUG = (1U << 17U) , POSTFX_FOG = (1U << 18U) , POSTFX_FOG_DEBUG = (1U << 19U) , POSTFX_LUT3D = (1U << 20U) , POSTFX_LUT_VIZ = (1U << 21U) } |
| Bitmask flags for enabling/disabling individual effects. More... | |
| enum | BandingMode { BANDING_MODE_LINEAR = 0 , BANDING_MODE_DITHERED = 1 , BANDING_MODE_PERCEPTUAL = 2 , BANDING_MODE_CHANNEL = 3 , BANDING_MODE_LUMINANCE = 4 } |
| Styles of color quantization. More... | |
| enum | { SHADER_CACHE_SIZE = 64 } |
Functions | |
| _Static_assert (_Alignof(PostProcessUBO) >=GL_UBO_ALIGNMENT, "PostProcessUBO" " must be >= 32-byte aligned for AVX (cglm)") | |
| int | postprocess_init (PostProcess *post_processing, GPUProfiler *external_profiler, int width, int height) |
| Initializes the post-processing pipeline. More... | |
| void | postprocess_cleanup (PostProcess *post_processing) |
| Releases all GPU and CPU resources. More... | |
| void | postprocess_compile_optimized (PostProcess *post_processing, unsigned int static_flags) |
| Compiles a specialized Uber-shader for maximum performance. More... | |
| void | postprocess_use_dynamic (PostProcess *post_processing) |
| Switches back to the dynamic/generic Uber-shader. More... | |
| void | postprocess_set_dummy_textures (PostProcess *post_processing, GLuint dummy_black) |
| Internal helper to set fallback textures. More... | |
| void | postprocess_resize (PostProcess *post_processing, int width, int height) |
| Recreates all internal buffers for a new resolution. More... | |
| void | postprocess_enable (PostProcess *post_processing, PostProcessEffect effect) |
| Enables a specific effect. More... | |
| void | postprocess_disable (PostProcess *post_processing, PostProcessEffect effect) |
| Disables a specific effect. More... | |
| void | postprocess_toggle (PostProcess *post_processing, PostProcessEffect effect) |
| Toggles the current state of an effect. More... | |
| int | postprocess_is_enabled (PostProcess *post_processing, PostProcessEffect effect) |
| Returns true if an effect is currently active. More... | |
| void | postprocess_set_white_balance (PostProcess *post_processing, float temperature, float tint) |
| void | postprocess_set_color_grading (PostProcess *post_processing, float saturation, float contrast, float gamma, float gain, float offset, float lift) |
| void | postprocess_set_tonemapper (PostProcess *post_processing, float slope, float toe, float shoulder, float black_clip, float white_clip) |
| void | postprocess_set_grading_ue_default (PostProcess *post_processing) |
| void | postprocess_set_vignette (PostProcess *post_processing, float intensity, float smoothness, float roundness) |
| void | postprocess_set_grain (PostProcess *post_processing, float intensity) |
| void | postprocess_set_exposure (PostProcess *post_processing, float exposure) |
| void | postprocess_set_chrom_abbr (PostProcess *post_processing, float strength) |
| void | postprocess_set_bloom (PostProcess *post_processing, float intensity, float threshold, float soft_threshold) |
| void | postprocess_set_dof (PostProcess *post_processing, float focal_distance, float focal_range, float bokeh_scale) |
| void | postprocess_set_dof_anamorphic (PostProcess *post_processing, float anamorphic_ratio) |
| float | postprocess_get_exposure (PostProcess *post_processing) |
| void | postprocess_set_auto_exposure (PostProcess *post_processing, float min_luminance, float max_luminance, float speed_up, float speed_down, float key_value) |
| void | postprocess_set_fxaa (PostProcess *post_processing, float subpix, float edge_threshold, float edge_threshold_min) |
| void | postprocess_set_banding (PostProcess *post_processing, BandingMode mode, float levels) |
| void | postprocess_set_banding_dither (PostProcess *post_processing, float strength) |
| void | postprocess_set_banding_perceptual (PostProcess *post_processing, float gamma) |
| void | postprocess_set_banding_channels (PostProcess *post_processing, float red, float green, float blue) |
| void | postprocess_set_fog (PostProcess *post_processing, float density, float start, float height_falloff, float fog_r, float fog_g, float fog_b) |
| void | postprocess_set_lut3d (PostProcess *post_processing, float intensity, GLuint texture) |
| int | postprocess_load_lut3d (PostProcess *post_processing, const char *path) |
| void | postprocess_update_matrices (PostProcess *post_processing, mat4 view_proj) |
| Updates view-projection matrices for effects requiring depth-reconstruction. More... | |
| void | postprocess_apply_preset (PostProcess *post_processing, const PostProcessPreset *preset) |
| Applies all settings from a preset atomically. More... | |
| void | postprocess_begin (PostProcess *post_processing) |
| Binds the HDR FBO and prepares for scene rendering. Should be called BEFORE the main render loop. More... | |
| void | postprocess_end (PostProcess *post_processing) |
| Processes the HDR scene and renders the final LDR result to screen. Should be called AFTER the main render loop. More... | |
| void | postprocess_update_time (PostProcess *post_processing, float delta_time) |
| Increments internal clocks. More... | |
| GLuint | postprocess_get_exposure_pbo (PostProcess *post_processing, int index) |
| GLuint | postprocess_get_histogram_pbo (PostProcess *post_processing, int index) |
| GLsync | postprocess_get_exposure_sync (PostProcess *post_processing, int index) |
| GLsync | postprocess_get_histogram_sync (PostProcess *post_processing, int index) |
| void | postprocess_set_exposure_sync (PostProcess *post_processing, int index, GLsync sync) |
| void | postprocess_set_histogram_sync (PostProcess *post_processing, int index, GLsync sync) |
| void | postprocess_update_readbacks (PostProcess *post_processing, uint64_t frame_count) |
| Updates all async GPU readbacks (Exposure, Histogram). Handles PBO mapping and Sync management internally to avoid CPU stalls. More... | |
| void | postprocess_set_exposure_target (PostProcess *post_processing, float threshold) |
| Updates the target exposure threshold for AE. More... | |
| int | postprocess_compute_luminance_histogram (PostProcess *post_processing, uint64_t frame_count, int *buckets, int size, float *min_lum, float *max_lum) |
| Computes the luminance histogram from the GPU readback. More... | |
High-level post-processing pipeline and effects.
This module manages the multi-pass post-processing pipeline, including blooming, auto-exposure, color grading, motion blur, and tone mapping. It uses a centralized Uniform Buffer Object (UBO) for settings.
| #define DEFAULT_ACTIVE_EFFECTS |
Default mask of active effects.
| #define DEFAULT_BANDING_LEVELS 256.0F |
8-bit simulation.
| #define DEFAULT_BLOOM_INTENSITY 0.0F |
| #define DEFAULT_BLOOM_RADIUS 1.0F |
| #define DEFAULT_BLOOM_SOFT_THRESHOLD 0.5F |
| #define DEFAULT_BLOOM_THRESHOLD 1.0F |
| #define DEFAULT_CHROM_ABBR_STRENGTH 0.005F |
| #define DEFAULT_DOF_ANAMORPHIC_RATIO 1.0F |
1.0 = Spherical, 2.0 = Anamorphic
| #define DEFAULT_DOF_BOKEH_SCALE 10.0F |
| #define DEFAULT_DOF_FOCAL_DISTANCE 20.0F |
| #define DEFAULT_DOF_FOCAL_RANGE 5.0F |
| #define DEFAULT_EXPOSURE 1.00F |
| #define DEFAULT_FILMIC_BLACK_CLIP 0.0F |
| #define DEFAULT_FILMIC_SHOULDER 0.0F |
| #define DEFAULT_FILMIC_SLOPE 1.0F |
| #define DEFAULT_FILMIC_TOE 0.0F |
| #define DEFAULT_FILMIC_WHITE_CLIP 0.0F |
| #define DEFAULT_FOG_COLOR_B 0.7F |
| #define DEFAULT_FOG_COLOR_G 0.6F |
| #define DEFAULT_FOG_COLOR_R 0.5F |
| #define DEFAULT_FOG_DENSITY 0.0F |
| #define DEFAULT_FOG_HEIGHT_FALLOFF 0.1F |
| #define DEFAULT_FOG_START 10.0F |
| #define DEFAULT_FXAA_EDGE_THRESHOLD 0.125F |
| #define DEFAULT_FXAA_EDGE_THRESHOLD_MIN 0.063F |
| #define DEFAULT_FXAA_SUBPIX 0.75F |
| #define DEFAULT_GRAIN_HIGHLIGHTS_MIN 0.5F |
| #define DEFAULT_GRAIN_INTENSITY 0.02F |
Default film grain strength.
| #define DEFAULT_GRAIN_SHADOWS_MAX 0.09F |
| #define DEFAULT_GRAIN_TEXEL_SIZE 1.0F |
| #define DEFAULT_VIGNETTE_INTENSITY 0.8F |
Default vignette strength.
| #define DEFAULT_VIGNETTE_ROUNDNESS 1.0F |
Default vignette shape.
| #define DEFAULT_VIGNETTE_SMOOTHNESS 0.5F |
Default vignette falloff.
| #define DEFAULT_WB_TEMP 6500.0F |
| #define DEFAULT_WB_TINT 0.0F |
| #define POSTPROCESS_HISTOGRAM_BUCKETS 256 |
| enum BandingMode |
| enum PostProcessEffect |
Bitmask flags for enabling/disabling individual effects.
| _Static_assert | ( | _Alignof(PostProcessUBO) >= | GL_UBO_ALIGNMENT, |
| "PostProcessUBO" " must be >= 32-byte aligned for AVX (cglm)" | |||
| ) |
| void postprocess_apply_preset | ( | PostProcess * | post_processing, |
| const PostProcessPreset * | preset | ||
| ) |
Applies all settings from a preset atomically.
| post_processing | Pointer to the struct. |
| preset | Pointer to the preset values. |
| void postprocess_begin | ( | PostProcess * | post_processing | ) |
Binds the HDR FBO and prepares for scene rendering. Should be called BEFORE the main render loop.
| void postprocess_cleanup | ( | PostProcess * | post_processing | ) |
Releases all GPU and CPU resources.
| post_processing | Pointer to the struct. |
| void postprocess_compile_optimized | ( | PostProcess * | post_processing, |
| unsigned int | static_flags | ||
| ) |
Compiles a specialized Uber-shader for maximum performance.
| post_processing | Pointer to the struct. |
| static_flags | Bitmask of effects to bake into the shader. |
| int postprocess_compute_luminance_histogram | ( | PostProcess * | post_processing, |
| uint64_t | frame_count, | ||
| int * | buckets, | ||
| int | size, | ||
| float * | min_lum, | ||
| float * | max_lum | ||
| ) |
Computes the luminance histogram from the GPU readback.
| void postprocess_disable | ( | PostProcess * | post_processing, |
| PostProcessEffect | effect | ||
| ) |
Disables a specific effect.
| void postprocess_enable | ( | PostProcess * | post_processing, |
| PostProcessEffect | effect | ||
| ) |
Enables a specific effect.
| void postprocess_end | ( | PostProcess * | post_processing | ) |
Processes the HDR scene and renders the final LDR result to screen. Should be called AFTER the main render loop.
| float postprocess_get_exposure | ( | PostProcess * | post_processing | ) |
| GLuint postprocess_get_exposure_pbo | ( | PostProcess * | post_processing, |
| int | index | ||
| ) |
| GLsync postprocess_get_exposure_sync | ( | PostProcess * | post_processing, |
| int | index | ||
| ) |
| GLuint postprocess_get_histogram_pbo | ( | PostProcess * | post_processing, |
| int | index | ||
| ) |
| GLsync postprocess_get_histogram_sync | ( | PostProcess * | post_processing, |
| int | index | ||
| ) |
| int postprocess_init | ( | PostProcess * | post_processing, |
| GPUProfiler * | external_profiler, | ||
| int | width, | ||
| int | height | ||
| ) |
Initializes the post-processing pipeline.
| post_processing | Pointer to the struct. |
| external_profiler | Pointer to the GPU profiler for timing stages. |
| width | Initial resolution width. |
| height | Initial resolution height. |
| int postprocess_is_enabled | ( | PostProcess * | post_processing, |
| PostProcessEffect | effect | ||
| ) |
Returns true if an effect is currently active.
| int postprocess_load_lut3d | ( | PostProcess * | post_processing, |
| const char * | path | ||
| ) |
| void postprocess_resize | ( | PostProcess * | post_processing, |
| int | width, | ||
| int | height | ||
| ) |
Recreates all internal buffers for a new resolution.
| post_processing | Pointer to the struct. |
| width | New width. |
| height | New height. |
| void postprocess_set_auto_exposure | ( | PostProcess * | post_processing, |
| float | min_luminance, | ||
| float | max_luminance, | ||
| float | speed_up, | ||
| float | speed_down, | ||
| float | key_value | ||
| ) |
| void postprocess_set_banding | ( | PostProcess * | post_processing, |
| BandingMode | mode, | ||
| float | levels | ||
| ) |
| void postprocess_set_banding_channels | ( | PostProcess * | post_processing, |
| float | red, | ||
| float | green, | ||
| float | blue | ||
| ) |
| void postprocess_set_banding_dither | ( | PostProcess * | post_processing, |
| float | strength | ||
| ) |
| void postprocess_set_banding_perceptual | ( | PostProcess * | post_processing, |
| float | gamma | ||
| ) |
| void postprocess_set_bloom | ( | PostProcess * | post_processing, |
| float | intensity, | ||
| float | threshold, | ||
| float | soft_threshold | ||
| ) |
| void postprocess_set_chrom_abbr | ( | PostProcess * | post_processing, |
| float | strength | ||
| ) |
| void postprocess_set_color_grading | ( | PostProcess * | post_processing, |
| float | saturation, | ||
| float | contrast, | ||
| float | gamma, | ||
| float | gain, | ||
| float | offset, | ||
| float | lift | ||
| ) |
| void postprocess_set_dof | ( | PostProcess * | post_processing, |
| float | focal_distance, | ||
| float | focal_range, | ||
| float | bokeh_scale | ||
| ) |
| void postprocess_set_dof_anamorphic | ( | PostProcess * | post_processing, |
| float | anamorphic_ratio | ||
| ) |
| void postprocess_set_dummy_textures | ( | PostProcess * | post_processing, |
| GLuint | dummy_black | ||
| ) |
Internal helper to set fallback textures.
| void postprocess_set_exposure | ( | PostProcess * | post_processing, |
| float | exposure | ||
| ) |
| void postprocess_set_exposure_sync | ( | PostProcess * | post_processing, |
| int | index, | ||
| GLsync | sync | ||
| ) |
| void postprocess_set_exposure_target | ( | PostProcess * | post_processing, |
| float | threshold | ||
| ) |
Updates the target exposure threshold for AE.
| void postprocess_set_fog | ( | PostProcess * | post_processing, |
| float | density, | ||
| float | start, | ||
| float | height_falloff, | ||
| float | fog_r, | ||
| float | fog_g, | ||
| float | fog_b | ||
| ) |
| void postprocess_set_fxaa | ( | PostProcess * | post_processing, |
| float | subpix, | ||
| float | edge_threshold, | ||
| float | edge_threshold_min | ||
| ) |
| void postprocess_set_grading_ue_default | ( | PostProcess * | post_processing | ) |
| void postprocess_set_grain | ( | PostProcess * | post_processing, |
| float | intensity | ||
| ) |
| void postprocess_set_histogram_sync | ( | PostProcess * | post_processing, |
| int | index, | ||
| GLsync | sync | ||
| ) |
| void postprocess_set_lut3d | ( | PostProcess * | post_processing, |
| float | intensity, | ||
| GLuint | texture | ||
| ) |
| void postprocess_set_tonemapper | ( | PostProcess * | post_processing, |
| float | slope, | ||
| float | toe, | ||
| float | shoulder, | ||
| float | black_clip, | ||
| float | white_clip | ||
| ) |
| void postprocess_set_vignette | ( | PostProcess * | post_processing, |
| float | intensity, | ||
| float | smoothness, | ||
| float | roundness | ||
| ) |
| void postprocess_set_white_balance | ( | PostProcess * | post_processing, |
| float | temperature, | ||
| float | tint | ||
| ) |
| void postprocess_toggle | ( | PostProcess * | post_processing, |
| PostProcessEffect | effect | ||
| ) |
Toggles the current state of an effect.
| void postprocess_update_matrices | ( | PostProcess * | post_processing, |
| mat4 | view_proj | ||
| ) |
Updates view-projection matrices for effects requiring depth-reconstruction.
| post_processing | Pointer to the struct. |
| view_proj | The current frame's View-Proj matrix. |
| void postprocess_update_readbacks | ( | PostProcess * | post_processing, |
| uint64_t | frame_count | ||
| ) |
Updates all async GPU readbacks (Exposure, Histogram). Handles PBO mapping and Sync management internally to avoid CPU stalls.
| void postprocess_update_time | ( | PostProcess * | post_processing, |
| float | delta_time | ||
| ) |
Increments internal clocks.
| post_processing | Pointer to the struct. |
| delta_time | SECONDS elapsed since last frame. |
| void postprocess_use_dynamic | ( | PostProcess * | post_processing | ) |
Switches back to the dynamic/generic Uber-shader.
| post_processing | Pointer to the struct. |