summaryrefslogtreecommitdiff
path: root/src/procedural
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-01 10:51:15 +0100
committerskal <pascal.massimino@gmail.com>2026-02-01 10:51:15 +0100
commit8bdc4754647c9c6691130fa91d51fee93c5fc88f (patch)
tree2cfd7f72a21541c488ea48629eef47a6774fc2c4 /src/procedural
parent7905abd9f7ad35231289e729b42e3ad57a943ff5 (diff)
feat: Implement 3D system and procedural texture manager
- Extended mini_math.h with mat4 multiplication and affine transforms. - Implemented TextureManager for runtime procedural texture generation and GPU upload. - Added 3D system components: Camera, Object, Scene, and Renderer3D. - Created test_3d_render mini-demo for interactive 3D verification. - Fixed WebGPU validation errors regarding depthSlice and unimplemented WaitAny.
Diffstat (limited to 'src/procedural')
-rw-r--r--src/procedural/generator.cc56
-rw-r--r--src/procedural/generator.h27
2 files changed, 83 insertions, 0 deletions
diff --git a/src/procedural/generator.cc b/src/procedural/generator.cc
new file mode 100644
index 0000000..3d969ba
--- /dev/null
+++ b/src/procedural/generator.cc
@@ -0,0 +1,56 @@
+// This file is part of the 64k demo project.
+// It implements basic procedural texture generators.
+
+#include "procedural/generator.h"
+#include <cmath>
+#include <cstdlib>
+
+namespace procedural {
+
+// Simple noise generator
+// Params[0]: Seed (optional, if 0 uses rand())
+// Params[1]: Intensity (0.0 - 1.0)
+void gen_noise(uint8_t* buffer, int w, int h, const float* params,
+ int num_params) {
+ float intensity = (num_params > 1) ? params[1] : 1.0f;
+ if (num_params > 0 && params[0] != 0) {
+ srand((unsigned int)params[0]);
+ }
+
+ for (int i = 0; i < w * h; ++i) {
+ uint8_t val = (uint8_t)((rand() % 255) * intensity);
+ buffer[i * 4 + 0] = val; // R
+ buffer[i * 4 + 1] = val; // G
+ buffer[i * 4 + 2] = val; // B
+ buffer[i * 4 + 3] = 255; // A
+ }
+}
+
+// Simple grid generator
+// Params[0]: Grid Size (pixels)
+// Params[1]: Line Thickness (pixels)
+void gen_grid(uint8_t* buffer, int w, int h, const float* params,
+ int num_params) {
+ int grid_size = (num_params > 0) ? (int)params[0] : 32;
+ int thickness = (num_params > 1) ? (int)params[1] : 2;
+
+ if (grid_size < 1)
+ grid_size = 32;
+
+ for (int y = 0; y < h; ++y) {
+ for (int x = 0; x < w; ++x) {
+ bool on_line = ((x % grid_size) < thickness) ||
+ ((y % grid_size) < thickness);
+
+ int idx = (y * w + x) * 4;
+ uint8_t val = on_line ? 255 : 0;
+
+ buffer[idx + 0] = val;
+ buffer[idx + 1] = val;
+ buffer[idx + 2] = val;
+ buffer[idx + 3] = 255;
+ }
+ }
+}
+
+} // namespace procedural
diff --git a/src/procedural/generator.h b/src/procedural/generator.h
new file mode 100644
index 0000000..a5ced68
--- /dev/null
+++ b/src/procedural/generator.h
@@ -0,0 +1,27 @@
+// This file is part of the 64k demo project.
+// It defines the interface for procedural texture generation.
+// Used to generate texture data at runtime.
+
+#pragma once
+
+#include <cstdint>
+#include <vector>
+
+// Procedural generation function signature
+// buffer: Pointer to RGBA8 buffer (size w * h * 4)
+// w, h: Dimensions
+// params: Arbitrary float parameters for the generator
+typedef void (*ProcGenFunc)(uint8_t* buffer, int w, int h, const float* params,
+ int num_params);
+
+namespace procedural {
+
+// Example: Simple noise generator
+void gen_noise(uint8_t* buffer, int w, int h, const float* params,
+ int num_params);
+
+// Example: Grid pattern
+void gen_grid(uint8_t* buffer, int w, int h, const float* params,
+ int num_params);
+
+} // namespace procedural