MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches
ProceduralTextureNode.hpp
Go to the documentation of this file.
1// ProceduralTextureNode.hpp
2#pragma once
3
4#include "TextureNode.hpp"
5#include "glm/vec4.hpp"
6
8
9/**
10 * @class ProceduralTextureNode
11 * @brief Pixels generated by arbitrary functions
12 *
13 * Philosophy:
14 * - Pixels are just numbers - transform them freely
15 * - Algorithm-driven generation, not file loading
16 * - Live coding friendly - hot-swap generation functions
17 * - Use lambda captures for state - no parameter system
18 *
19 * Usage:
20 * ```cpp
21 * // Static pattern
22 * auto checker = std::make_shared<ProceduralTextureNode>(512, 512,
23 * [](uint32_t x, uint32_t y, uint32_t w, uint32_t h) -> glm::vec4 {
24 * bool is_white = ((x / 32) + (y / 32)) % 2 == 0;
25 * float value = is_white ? 1.0f : 0.0f;
26 * return glm::vec4(value, value, value, 1.0f);
27 * });
28 *
29 * // Animated gradient via captures
30 * float time = 0.0f;
31 * auto gradient = std::make_shared<ProceduralTextureNode>(512, 512,
32 * [&time](uint32_t x, uint32_t y, uint32_t w, uint32_t h) {
33 * float u = float(x) / float(w);
34 * float v = float(y) / float(h);
35 * return glm::vec4(u, v, std::sin(time), 1.0f);
36 * });
37 *
38 * // Each frame:
39 * time += 0.016f;
40 * gradient->compute_frame(); // Sees updated 'time' automatically
41 * ```
42 */
43class MAYAFLUX_API ProceduralTextureNode : public TextureNode {
44public:
45 /**
46 * @brief Pixel generator function signature
47 * @param x Pixel X coordinate
48 * @param y Pixel Y coordinate
49 * @param width Texture width (for normalization)
50 * @param height Texture height (for normalization)
51 * @return RGBA color for this pixel
52 */
53 using PixelGenerator = std::function<glm::vec4(
54 uint32_t x, uint32_t y,
55 uint32_t width, uint32_t height)>;
56
57 /**
58 * @brief Create procedural texture with default (black) generator
59 * @param width Texture width
60 * @param height Texture height
61 */
62 ProceduralTextureNode(uint32_t width, uint32_t height);
63
64 /**
65 * @brief Create procedural texture with custom generator
66 * @param width Texture width
67 * @param height Texture height
68 * @param generator Pixel generation function
69 */
70 ProceduralTextureNode(uint32_t width, uint32_t height, PixelGenerator generator);
71
72 /**
73 * @brief Set pixel generator function
74 * @param generator New generation function
75 *
76 * Marks texture as dirty - next compute_frame() will regenerate all pixels.
77 * Use this for hot-swapping algorithms, not for per-frame updates.
78 */
79 void set_generator(PixelGenerator generator);
80
81 /**
82 * @brief Compute frame - generate all pixels via generator function
83 */
84 void compute_frame() override;
85
86private:
88};
89
90} // namespace MayaFlux::Nodes::GpuSync
std::function< glm::vec4(uint32_t x, uint32_t y, uint32_t width, uint32_t height)> PixelGenerator
Pixel generator function signature.
Pixels generated by arbitrary functions.
Base class for texture-generating nodes.