myth_resources/fxaa.rs
1//! FXAA (Fast Approximate Anti-Aliasing) Configuration
2//!
3//! This module defines FXAA settings as a pure data structure, following the same
4//! pattern as [`BloomSettings`](super::bloom::BloomSettings) and
5//! [`ToneMappingSettings`](super::tone_mapping::ToneMappingSettings).
6//!
7//! FXAA is a screen-space anti-aliasing technique that identifies aliased edges
8//! via luma contrast detection and applies sub-pixel smoothing. It operates on
9//! LDR (post-tone-mapped) images and is therefore placed **after** tone mapping
10//! in the HDR pipeline.
11//!
12//! # Quality Presets
13//!
14//! | Preset | Iterations | Best for |
15//! |----------|------------|----------------------|
16//! | `Low` | 4 | Mobile / low-end GPU |
17//! | `Medium` | 8 | Default balance |
18//! | `High` | 12 | Maximum quality |
19//!
20//! # Usage
21//!
22//! ```rust,ignore
23//! // Access via scene
24//! scene.fxaa.enabled = true;
25//! scene.fxaa.set_quality(FxaaQuality::High);
26//! ```
27
28/// FXAA quality preset.
29///
30/// Controls the number of edge exploration iterations in the FXAA shader.
31/// Higher quality means more iterations and better edge detection at the
32/// cost of additional texture samples per pixel.
33#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
34pub enum FxaaQuality {
35 /// 4 iterations — suitable for mobile and low-end GPUs.
36 Low,
37 /// 8 iterations — good balance of quality and performance (default).
38 Medium,
39 /// 12 iterations — maximum edge exploration quality.
40 #[default]
41 High,
42}
43
44impl FxaaQuality {
45 /// Returns a human-readable name for the quality preset.
46 #[must_use]
47 pub const fn name(self) -> &'static str {
48 match self {
49 Self::Low => "Low",
50 Self::Medium => "Medium",
51 Self::High => "High",
52 }
53 }
54
55 /// Returns all available quality presets.
56 #[must_use]
57 pub const fn all() -> &'static [FxaaQuality] {
58 &[Self::Low, Self::Medium, Self::High]
59 }
60
61 /// Returns the shader define key for this quality preset.
62 ///
63 /// Used by `FxaaPass` to select the correct shader variant.
64 #[must_use]
65 pub const fn define_key(self) -> &'static str {
66 match self {
67 Self::Low => "FXAA_QUALITY_LOW",
68 Self::Medium => "FXAA_QUALITY_MEDIUM",
69 Self::High => "FXAA_QUALITY_HIGH",
70 }
71 }
72}
73
74/// FXAA post-processing configuration.
75///
76/// This is a lightweight settings struct — FXAA has no per-frame GPU uniforms,
77/// only a quality preset that affects shader compilation.
78///
79/// # Usage
80///
81/// ```rust,ignore
82/// let fxaa = &mut scene.fxaa;
83/// fxaa.set_quality(FxaaQuality::High);
84/// ```
85#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Default)]
86pub struct FxaaSettings {
87 /// Quality preset controlling edge exploration iterations.
88 pub quality: FxaaQuality,
89}
90
91impl FxaaSettings {
92 /// Creates new FXAA settings with default values (enabled, medium quality).
93 #[must_use]
94 pub fn new() -> Self {
95 Self::default()
96 }
97
98 /// Returns the current quality preset.
99 #[inline]
100 #[must_use]
101 pub fn quality(&self) -> FxaaQuality {
102 self.quality
103 }
104
105 #[inline]
106 pub fn set_quality(&mut self, quality: FxaaQuality) {
107 self.quality = quality;
108 }
109}