feat(antialias): toggle F5 i indicador AA al debug overlay

Permet alternar l'AA geomètric en runtime:

- Action::TOGGLE_ANTIALIAS bound a F5.
- GlobalEvents::handle reacciona al scancode F5 cridant sdl.toggleAntialias().
- SDLManager::toggleAntialias muta cfg_->rendering.antialias i propaga a
  gpu_renderer_.setAntialias().
- GpuFrameRenderer manté l'estat antialias_enabled_ (true per defecte) i
  pushLine adapta extrusió i edge_dist en funció del flag — geometria nua
  quan està OFF, fade als bords quan està ON.
- RenderingConfig guanya el camp `antialias{1}` per coherència amb vsync;
  l'estat NO es persisteix al YAML de moment (decisió volgudament conservadora,
  podem afegir-ho en un commit a part si cal).
- DebugOverlay (F11) mostra una tercera línia "AA: ON/OFF" sota VSYNC per
  poder comparar a temps real.
This commit is contained in:
2026-05-20 21:39:24 +02:00
parent b10f2da647
commit 1ef9ca551f
10 changed files with 122 additions and 85 deletions
@@ -243,21 +243,23 @@ namespace Rendering::GPU {
return;
}
// Antialias geomètric: extruim 0.5 píxel extra a cada banda del gruix
// demanat, i el fragment shader fa fade als bords usant edge_dist (±1
// als laterals, 0 al centre). Així el gruix "ple" coincideix amb el
// demanat i el píxel extra només aporta la transició suau.
const float AA_PADDING = 0.5F;
// Antialias geomètric: quan està ON, extruim 0.5 píxel extra a cada
// banda del gruix demanat i posem edge_dist = ±1 als laterals; el
// fragment shader fa fade als bords. Quan està OFF, geometria nua
// (thickness exacte) i edge_dist = 0 a tots els vèrtexs → el
// smoothstep del shader produeix alpha=1 sempre.
const float AA_PADDING = antialias_enabled_ ? 0.5F : 0.0F;
const float HALF = (thickness * 0.5F) + AA_PADDING;
const float NX = -DY / LEN * HALF;
const float NY = DX / LEN * HALF;
const float EDGE = antialias_enabled_ ? 1.0F : 0.0F;
const auto BASE_INDEX = static_cast<uint16_t>(vertices_.size());
vertices_.push_back({x1 + NX, y1 + NY, r, g, b, a, +1.0F});
vertices_.push_back({x1 - NX, y1 - NY, r, g, b, a, -1.0F});
vertices_.push_back({x2 + NX, y2 + NY, r, g, b, a, +1.0F});
vertices_.push_back({x2 - NX, y2 - NY, r, g, b, a, -1.0F});
vertices_.push_back({x1 + NX, y1 + NY, r, g, b, a, +EDGE});
vertices_.push_back({x1 - NX, y1 - NY, r, g, b, a, -EDGE});
vertices_.push_back({x2 + NX, y2 + NY, r, g, b, a, +EDGE});
vertices_.push_back({x2 - NX, y2 - NY, r, g, b, a, -EDGE});
indices_.push_back(BASE_INDEX + 0);
indices_.push_back(BASE_INDEX + 1);
@@ -27,30 +27,30 @@
namespace Rendering::GPU {
// Parámetros del postpro que el caller (SDLManager) pasa cada frame.
// Equivalente al lado "humano" del PostFxUniforms (sin paddings).
struct PostFxParams {
bool bloom_enabled{true};
float bloom_intensity{0.6F};
float bloom_threshold{0.4F};
float bloom_radius_px{2.0F};
// Parámetros del postpro que el caller (SDLManager) pasa cada frame.
// Equivalente al lado "humano" del PostFxUniforms (sin paddings).
struct PostFxParams {
bool bloom_enabled{true};
float bloom_intensity{0.6F};
float bloom_threshold{0.4F};
float bloom_radius_px{2.0F};
bool flicker_enabled{true};
float flicker_amplitude{0.10F};
float flicker_frequency_hz{6.0F};
bool flicker_enabled{true};
float flicker_amplitude{0.10F};
float flicker_frequency_hz{6.0F};
bool background_enabled{true};
float background_min_r{0.0F};
float background_min_g{0.02F};
float background_min_b{0.0F};
float background_max_r{0.0F};
float background_max_g{0.06F};
float background_max_b{0.0F};
float background_pulse_freq_hz{6.0F};
};
bool background_enabled{true};
float background_min_r{0.0F};
float background_min_g{0.02F};
float background_min_b{0.0F};
float background_max_r{0.0F};
float background_max_g{0.06F};
float background_max_b{0.0F};
float background_pulse_freq_hz{6.0F};
};
class GpuFrameRenderer {
public:
class GpuFrameRenderer {
public:
GpuFrameRenderer() = default;
~GpuFrameRenderer();
@@ -72,8 +72,7 @@ class GpuFrameRenderer {
[[nodiscard]] auto beginFrame(float clear_r, float clear_g, float clear_b) -> bool;
// Encola una línea con grosor configurable (px). Color RGBA en [0..1].
void pushLine(float x1, float y1, float x2, float y2, float thickness,
float r, float g, float b, float a);
void pushLine(float x1, float y1, float x2, float y2, float thickness, float r, float g, float b, float a);
// endFrame: flush del batch de líneas → composite postpro → submit + presenta.
void endFrame();
@@ -87,6 +86,13 @@ class GpuFrameRenderer {
// Activa/desactiva VSync. true = SDL_GPU_PRESENTMODE_VSYNC, false = IMMEDIATE.
void setVSync(bool enabled);
// Activa/desactiva l'antialias geomètric a les línies. Quan està OFF,
// pushLine no extrudeix píxel extra ni emet edge_dist (geometria com
// abans del commit d'AA-1). Quan està ON, l'extrusió i el fade del
// fragment shader produeixen bords suavitzats.
void setAntialias(bool enabled) { antialias_enabled_ = enabled; }
[[nodiscard]] auto isAntialiasEnabled() const -> bool { return antialias_enabled_; }
// Parámetros del postpro que se aplican en endFrame. Por defecto =
// valores de Defaults (bloom moderado, flicker suave, fondo verde tenue).
void setPostFx(const PostFxParams& params) { postfx_params_ = params; }
@@ -96,7 +102,7 @@ class GpuFrameRenderer {
[[nodiscard]] auto device() -> GpuDevice& { return device_; }
[[nodiscard]] auto isInsideFrame() const -> bool { return cmd_buffer_ != nullptr; }
private:
private:
GpuDevice device_;
GpuLinePipeline line_pipeline_;
GpuPostFxPipeline postfx_pipeline_;
@@ -128,12 +134,15 @@ class GpuFrameRenderer {
// Parámetros del postpro (configurables vía YAML).
PostFxParams postfx_params_{};
// Estat de l'antialias geomètric a les línies (toggle F5).
bool antialias_enabled_{true};
// Helpers internos.
[[nodiscard]] auto createOffscreen() -> bool;
void destroyOffscreen();
void flushBatch();
void compositePass();
void applyFinalViewport();
};
};
} // namespace Rendering::GPU