From 8bdc4754647c9c6691130fa91d51fee93c5fc88f Mon Sep 17 00:00:00 2001 From: skal Date: Sun, 1 Feb 2026 10:51:15 +0100 Subject: 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. --- src/procedural/generator.cc | 56 +++++++++++++++++++++++++++++++++++++++++++++ src/procedural/generator.h | 27 ++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 src/procedural/generator.cc create mode 100644 src/procedural/generator.h (limited to 'src/procedural') 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 +#include + +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 +#include + +// 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 -- cgit v1.2.3