feat(shaders_lab): uniform annotations → auto-generated ImGui controls

- cpp/functions/gfx/uniform_parser: regex-based parser of @slider/@color/@toggle/@xy annotations (+ inline tests)
- cpp/functions/gfx/uniform_panel: ImGui widgets + value store + glUniform* apply
- shader_canvas: optional uniforms callback invoked per-frame
- gl_loader: +glUniform1i/3f/4f
- seed plasma: demo uniforms u_speed + u_color
- rebuild Windows .exe

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-04-24 21:02:35 +02:00
parent b828fd6acc
commit 4610bb4a99
15 changed files with 580 additions and 23 deletions
+82
View File
@@ -0,0 +1,82 @@
---
name: uniform_parser
kind: function
lang: cpp
domain: gfx
version: "1.0.0"
purity: pure
signature: "std::vector<UniformDescriptor> parse_uniforms(const std::string& glsl_source)"
description: "Parsea un fragment shader GLSL y extrae descriptores de uniforms anotados con @slider/@color/@toggle/@xy. Ignora los uniforms reservados (u_resolution, u_time, u_mouse) y sampler2D. Sin anotación aplica defaults por tipo."
tags: [opengl, shader, uniforms, parser, imgui, gfx]
uses_functions: []
uses_types: []
returns: []
returns_optional: false
error_type: ""
imports: [regex, string, vector, sstream, unordered_map, unordered_set]
tested: true
tests:
- "sin anotacion float -> Slider 0..1"
- "@slider min=0 max=5 default=1 sobre float"
- "@color default=0.1,0.2,0.5 sobre vec3"
- "@xy min=-1 max=1 default=0,0 sobre vec2"
- "uniform vec2 u_resolution ignorado"
- "@toggle default=true sobre bool"
test_file_path: "cpp/functions/gfx/uniform_parser.cpp"
file_path: "cpp/functions/gfx/uniform_parser.cpp"
params:
- name: glsl_source
desc: "Código fuente GLSL completo del fragment shader. Se escanea línea a línea buscando declaraciones uniform con anotaciones opcionales."
output: "Vector de UniformDescriptor ordenado según aparición en el shader. Cada descriptor tiene nombre, tipo GLSL, widget ImGui, rangos min/max, valor por defecto y flags (log_scale, step, default_bool)."
---
# uniform_parser
Parsea declaraciones `uniform <type> <name>; // @<widget> key=value ...` en GLSL.
## Sintaxis de anotación
```glsl
uniform float u_speed; // @slider min=0.1 max=5 default=1
uniform vec3 u_color; // @color default=0.5,0.2,0.8
uniform bool u_debug; // @toggle default=true
uniform vec2 u_offset; // @xy min=-1 max=1 default=0,0
```
### Widgets disponibles
| Widget | Tipos soportados | Props relevantes |
|----------|-------------------|---------------------------------------------|
| `slider` | float, int, vec2 | min, max, default, step, log=true |
| `color` | vec3, vec4 | default (lista comma-separated) |
| `toggle` | bool | default=true/false |
| `xy` | vec2 | min, max, default (dos componentes) |
### Defaults por tipo sin anotación
| Tipo | Widget | min | max | default |
|-------|--------|------|------|-------------|
| float | Slider | 0 | 1 | 0 |
| int | Slider | 0 | 10 | 0, step=1 |
| bool | Toggle | — | — | false |
| vec2 | XY | 0,0 | 1,1 | 0.5,0.5 |
| vec3 | Color | — | — | 1,1,1 |
| vec4 | Color | — | — | 1,1,1,1 |
## Notas
- `@slider` sobre `vec2` equivale a `@xy`.
- Props desconocidas o de otro widget se ignoran silenciosamente.
- No lanza excepciones; errores de parse usan defaults.
- `u_resolution`, `u_time`, `u_mouse` y `sampler2D` se ignoran.
### Tests
Build y ejecución del test inline:
```bash
g++ -std=c++17 -DUNIFORM_PARSER_TEST -I cpp/functions \
cpp/functions/gfx/uniform_parser.cpp \
-o /tmp/uniform_parser_test \
&& /tmp/uniform_parser_test
```