Skip to main content

par_term_render/renderer/shaders/
mod.rs

1//! Shader management for the renderer.
2//!
3//! Manages two independent shader renderers:
4//!
5//! - **Background shader** (`custom_shader_renderer`) — full-screen post-processing
6//!   effect rendered before the terminal cell grid, compatible with Ghostty/Shadertoy GLSL.
7//! - **Cursor shader** (`cursor_shader_renderer`) — cursor overlay effect rendered after
8//!   the cell grid, enabling glow, trail, and other cursor effects.
9//!
10//! ## Sub-modules
11//!
12//! - [`background`] — init and `impl Renderer` methods for the background shader
13//! - [`cursor`] — init and `impl Renderer` methods for the cursor shader
14//! - [`shared`] — `impl Renderer` methods that update both renderers (mouse, cursor state, etc.)
15
16pub(super) mod background;
17pub(super) mod cursor;
18pub(super) mod shared;
19
20use crate::cell_renderer::CellRenderer;
21use crate::custom_shader_renderer::CustomShaderRenderer;
22use par_term_config::{ShaderBackgroundBlendMode, ShaderUniformValue};
23use std::collections::BTreeMap;
24
25/// Parameters for initialising the background custom shader renderer.
26pub struct CustomShaderInitParams<'a> {
27    pub size_width: u32,
28    pub size_height: u32,
29    pub window_padding: f32,
30    pub path: Option<&'a str>,
31    pub enabled: bool,
32    pub animation: bool,
33    pub animation_speed: f32,
34    pub window_opacity: f32,
35    pub full_content: bool,
36    pub brightness: f32,
37    pub channel_paths: &'a [Option<std::path::PathBuf>; 4],
38    pub cubemap_path: Option<&'a std::path::Path>,
39    pub custom_uniforms: &'a BTreeMap<String, ShaderUniformValue>,
40    pub use_background_as_channel0: bool,
41    pub background_channel0_blend_mode: ShaderBackgroundBlendMode,
42    pub auto_dim_under_text: bool,
43    pub auto_dim_strength: f32,
44}
45
46/// Parameters for initialising the cursor shader renderer.
47pub struct CursorShaderInitParams<'a> {
48    pub size_width: u32,
49    pub size_height: u32,
50    pub window_padding: f32,
51    pub path: Option<&'a str>,
52    pub enabled: bool,
53    pub animation: bool,
54    pub animation_speed: f32,
55    pub window_opacity: f32,
56}
57
58/// Parameters for enabling/updating the background custom shader at runtime.
59pub struct CustomShaderEnableParams<'a> {
60    pub enabled: bool,
61    pub shader_path: Option<&'a str>,
62    pub window_opacity: f32,
63    pub animation_enabled: bool,
64    pub animation_speed: f32,
65    pub full_content: bool,
66    pub brightness: f32,
67    pub channel_paths: &'a [Option<std::path::PathBuf>; 4],
68    pub cubemap_path: Option<&'a std::path::Path>,
69    pub custom_uniforms: &'a BTreeMap<String, ShaderUniformValue>,
70    pub background_channel0_blend_mode: ShaderBackgroundBlendMode,
71    pub auto_dim_under_text: bool,
72    pub auto_dim_strength: f32,
73}
74
75/// Initialize the custom (background) shader renderer if configured.
76///
77/// Returns `(renderer, shader_path)` where both are `Some` if initialization succeeded.
78pub(super) fn init_custom_shader(
79    cell_renderer: &CellRenderer,
80    params: CustomShaderInitParams<'_>,
81) -> (Option<CustomShaderRenderer>, Option<String>) {
82    background::init_custom_shader(cell_renderer, params)
83}
84
85/// Initialize the cursor shader renderer if configured.
86///
87/// Returns `(renderer, shader_path)` where both are `Some` if initialization succeeded.
88pub(super) fn init_cursor_shader(
89    cell_renderer: &CellRenderer,
90    params: CursorShaderInitParams<'_>,
91) -> (Option<CustomShaderRenderer>, Option<String>) {
92    cursor::init_cursor_shader(cell_renderer, params)
93}