Skip to content

Commit d036e50

Browse files
committed
add hdri test image code
1 parent 6967a44 commit d036e50

File tree

4 files changed

+86
-3
lines changed

4 files changed

+86
-3
lines changed

tsd/apps/interactive/common/windows/ObjectTree.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,17 @@ void ObjectTree::buildUI_objectContextMenu()
266266
clearSelectedNode = true;
267267
}
268268

269-
if (ImGui::MenuItem("hdri dome")) {
270-
generate_hdri_dome(ctx, menuNode);
271-
clearSelectedNode = true;
269+
if (ImGui::BeginMenu("hdri")) {
270+
if (ImGui::MenuItem("simple dome")) {
271+
generate_hdri_dome(ctx, menuNode);
272+
clearSelectedNode = true;
273+
}
274+
275+
if (ImGui::MenuItem("test image")) {
276+
generate_hdri_test_image(ctx, menuNode);
277+
clearSelectedNode = true;
278+
}
279+
ImGui::EndMenu();
272280
}
273281

274282
ImGui::EndMenu();

tsd/src/tsd/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ PRIVATE
2828
authoring/importers/import_XYZDP.cpp
2929
authoring/procedural/generate_cylinders.cpp
3030
authoring/procedural/generate_hdri_dome.cpp
31+
authoring/procedural/generate_hdri_test_image.cpp
3132
authoring/procedural/generate_material_orb.cpp
3233
authoring/procedural/generate_monkey.cpp
3334
authoring/procedural/generate_noiseVolume.cpp

tsd/src/tsd/authoring/procedural.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ namespace tsd {
1111

1212
void generate_cylinders(Context &ctx, LayerNodeRef location = {}, bool useDefaultMaterial = false);
1313
void generate_hdri_dome(Context &ctx, LayerNodeRef location = {});
14+
void generate_hdri_test_image(Context &ctx, LayerNodeRef location = {});
1415
void generate_material_orb(Context &ctx, LayerNodeRef location = {});
1516
void generate_monkey(Context &ctx, LayerNodeRef location = {});
1617
VolumeRef generate_noiseVolume(Context &ctx, LayerNodeRef location = {}, ArrayRef colors = {}, ArrayRef opacities = {});
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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(200, 200);
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

Comments
 (0)