diff options
| author | skal <pascal.massimino@gmail.com> | 2026-03-29 01:42:28 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-03-29 01:42:28 +0100 |
| commit | 70b77307a9a9ee4fdff23f783e041fe49e60e100 (patch) | |
| tree | 828948256e04a1aee5762643da773b23d29f8e11 /src/tests/util/test_procedural.cc | |
| parent | f05f76e07c8a91911aa61af16b7db4f30247a3d8 (diff) | |
feat(procedural): add plasma, voronoi, normalmap generators
Add three new procedural texture generators:
- gen_plasma: classic sine-sum color texture (RGB output)
- gen_voronoi: Worley cellular noise (F1/F2/F2-F1 modes)
- gen_normalmap: post-process grayscale→RGB normal map
Remove gen_noise_256 (was an alias for gen_noise). Register new
generators in asset_manager and asset_packer. Add unit tests for
all three, and use them in test_3d_render (plasma sky, voronoi noise,
fBm normal map).
handoff(Gemini): plasma/voronoi/normalmap procedural generators added;
gen_noise_256 removed; tests + 3d_render usage wired up.
Diffstat (limited to 'src/tests/util/test_procedural.cc')
| -rw-r--r-- | src/tests/util/test_procedural.cc | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/tests/util/test_procedural.cc b/src/tests/util/test_procedural.cc index e9f9a02..c6616ad 100644 --- a/src/tests/util/test_procedural.cc +++ b/src/tests/util/test_procedural.cc @@ -127,11 +127,99 @@ void test_periodic() { assert(res); // Should return true but do nothing } +void test_plasma() { + std::cout << "Testing Plasma Generator..." << std::endl; + int w = 64, h = 64; + std::vector<uint8_t> buffer(w * h * 4); + + float params[] = {0.0f, 2.0f}; + bool res = procedural::gen_plasma(buffer.data(), w, h, params, 2); + assert(res); + assert(buffer[3] == 255); + + // RGB should differ (color output, not grayscale) + bool has_color = false; + for (size_t i = 0; i < buffer.size(); i += 4) { + if (buffer[i] != buffer[i + 1] || buffer[i + 1] != buffer[i + 2]) { + has_color = true; + break; + } + } + assert(has_color); + + // Test defaults + res = procedural::gen_plasma(buffer.data(), w, h, nullptr, 0); + assert(res); +} + +void test_voronoi() { + std::cout << "Testing Voronoi Generator..." << std::endl; + int w = 64, h = 64; + std::vector<uint8_t> buffer(w * h * 4); + + // F1 mode + float params_f1[] = {4.0f, 0.0f, 0.0f}; + bool res = procedural::gen_voronoi(buffer.data(), w, h, params_f1, 3); + assert(res); + assert(buffer[3] == 255); + + bool nonzero = false; + for (size_t i = 0; i < buffer.size(); i += 4) { + if (buffer[i] > 0) { nonzero = true; break; } + } + assert(nonzero); + + // F2-F1 (borders) mode + float params_border[] = {4.0f, 2.0f, 0.0f}; + res = procedural::gen_voronoi(buffer.data(), w, h, params_border, 3); + assert(res); + + // Test defaults + res = procedural::gen_voronoi(buffer.data(), w, h, nullptr, 0); + assert(res); +} + +void test_normalmap() { + std::cout << "Testing Normal Map Generator..." << std::endl; + int w = 64, h = 64; + std::vector<uint8_t> buffer(w * h * 4); + + // Fill with a horizontal gradient as height + for (int y = 0; y < h; ++y) { + for (int x = 0; x < w; ++x) { + int idx = (y * w + x) * 4; + buffer[idx] = (uint8_t)(x * 255 / (w - 1)); + buffer[idx + 1] = buffer[idx]; + buffer[idx + 2] = buffer[idx]; + buffer[idx + 3] = 255; + } + } + + float params[] = {4.0f}; + bool res = procedural::gen_normalmap(buffer.data(), w, h, params, 1); + assert(res); + assert(buffer[3] == 255); + + // For a horizontal gradient, X-normal (R) should be shifted from 128 + // (non-flat normals expected) + bool has_normal_variation = false; + for (size_t i = 0; i < buffer.size(); i += 4) { + if (buffer[i] != 128) { has_normal_variation = true; break; } + } + assert(has_normal_variation); + + // Z component (B) should be > 0 (normal faces up) + assert(buffer[2] > 0); +} + int main() { test_noise(); test_perlin(); test_grid(); test_periodic(); + test_plasma(); + test_voronoi(); + test_normalmap(); std::cout << "--- PROCEDURAL TESTS PASSED ---" << std::endl; return 0; }
\ No newline at end of file |
