|
| 1 | +// Copyright 2024-2025 NVIDIA Corporation |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +#include "tsd/authoring/procedural.hpp" |
| 5 | + |
| 6 | +namespace tsd { |
| 7 | + |
| 8 | +void generate_hdri_test_image(Context &ctx, LayerNodeRef location) |
| 9 | +{ |
| 10 | + if (!location) |
| 11 | + location = ctx.defaultLayer()->root(); |
| 12 | + |
| 13 | + int2 size(1024, 1024); |
| 14 | + |
| 15 | + auto arr = ctx.createArray(ANARI_FLOAT32_VEC3, size.x, size.y); |
| 16 | + |
| 17 | + auto *as3f = arr->mapAs<float3>(); |
| 18 | + |
| 19 | + // ================================================================== |
| 20 | + // base pattern is thin black grid on white background |
| 21 | + // ================================================================== |
| 22 | + for (int iy = 0; iy < size.y; iy++) { |
| 23 | + for (int ix = 0; ix < size.x; ix++) { |
| 24 | + float3 color = |
| 25 | + ((ix % 16 == 0) || (iy % 16 == 0)) ? float3(0.f) : float3(1.f); |
| 26 | + as3f[ix + iy * size.x] = color; |
| 27 | + } |
| 28 | + } |
| 29 | + // ================================================================== |
| 30 | + // red square in lower left corner |
| 31 | + // ================================================================== |
| 32 | + for (int iy = 0; iy < size.y / 32; iy++) { |
| 33 | + for (int ix = 0; ix < size.x / 32; ix++) { |
| 34 | + float3 color = float3(1, 0, 0); |
| 35 | + as3f[ix + iy * size.x] = color; |
| 36 | + } |
| 37 | + } |
| 38 | + // ================================================================== |
| 39 | + // blue crosshair through center image, |
| 40 | + // ================================================================== |
| 41 | + for (int iy = 0; iy < size.y; iy++) { |
| 42 | + int ix = size.x / 2; |
| 43 | + as3f[ix + iy * size.x] = float3(0, 0, 1); |
| 44 | + } |
| 45 | + for (int ix = 0; ix < size.x; ix++) { |
| 46 | + int iy = size.y / 2; |
| 47 | + as3f[ix + iy * size.x] = float3(0, 0, 1); |
| 48 | + } |
| 49 | + // ================================================================== |
| 50 | + // gradient |
| 51 | + // ================================================================== |
| 52 | + int iy0 = size.y / 2 - 16; |
| 53 | + int ix0 = size.x / 2 - 16; |
| 54 | + int iy1 = size.y / 2 + 16; |
| 55 | + int ix1 = size.x / 2 + 16; |
| 56 | + for (int iy = iy0; iy <= iy1; iy++) { |
| 57 | + for (int ix = ix0; ix <= ix1; ix++) { |
| 58 | + float r = float(ix - ix0) / float(ix1 - ix0); |
| 59 | + float g = float(iy - iy0) / float(iy1 - iy0); |
| 60 | + // as3f[ix+iy*size.x] = float3(0,1,0); |
| 61 | + as3f[ix + iy * size.x] = float3(r, g, (r + g) / 2.f); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + arr->unmap(); |
| 66 | + |
| 67 | + auto [inst, hdri] = ctx.insertNewChildObjectNode<tsd::Light>( |
| 68 | + location, tsd::tokens::light::hdri); |
| 69 | + hdri->setName("hdri_dome"); |
| 70 | + hdri->setParameterObject("radiance"_t, *arr); |
| 71 | +} |
| 72 | + |
| 73 | +} // namespace tsd |
0 commit comments