Skip to content

Commit 00f806d

Browse files
Picklist for environment maps
1 parent df26edf commit 00f806d

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

src/Main.cpp

Lines changed: 41 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,19 @@ Scene* scene = nullptr;
5353
Renderer* renderer = nullptr;
5454

5555
std::vector<string> sceneFiles;
56+
std::vector<string> envMaps;
5657

5758
float mouseSensitivity = 0.01f;
5859
bool keyPressed = false;
59-
int sampleSceneIndex = 0;
60+
int sampleSceneIdx = 0;
6061
int selectedInstance = 0;
6162
double lastTime = SDL_GetTicks();
63+
int envMapIdx = 0;
6264
bool done = false;
6365

6466
std::string shadersDir = "../src/shaders/";
6567
std::string assetsDir = "../assets/";
68+
std::string envMapDir = "../assets/HDR/";
6669

6770
RenderOptions renderOptions;
6871

@@ -93,6 +96,27 @@ void GetSceneFiles()
9396
tinydir_close(&dir);
9497
}
9598

99+
void GetEnvMaps()
100+
{
101+
tinydir_dir dir;
102+
int i;
103+
tinydir_open_sorted(&dir, envMapDir.c_str());
104+
105+
for (i = 0; i < dir.n_files; i++)
106+
{
107+
tinydir_file file;
108+
tinydir_readfile_n(&dir, &file, i);
109+
110+
std::string ext = std::string(file.extension);
111+
if (ext == "hdr")
112+
{
113+
envMaps.push_back(envMapDir + std::string(file.name));
114+
}
115+
}
116+
117+
tinydir_close(&dir);
118+
}
119+
96120
void LoadScene(std::string sceneName)
97121
{
98122
delete scene;
@@ -304,20 +328,30 @@ void MainLoop(void* arg)
304328
SaveFrame("./img_" + to_string(renderer->GetSampleCount()) + ".png");
305329
}
306330

331+
// Scenes
307332
std::vector<const char*> scenes;
308333
for (int i = 0; i < sceneFiles.size(); ++i)
309-
{
310334
scenes.push_back(sceneFiles[i].c_str());
311-
}
312335

313-
if (ImGui::Combo("Scene", &sampleSceneIndex, scenes.data(), scenes.size()))
336+
if (ImGui::Combo("Scene", &sampleSceneIdx, scenes.data(), scenes.size()))
314337
{
315-
LoadScene(sceneFiles[sampleSceneIndex]);
338+
LoadScene(sceneFiles[sampleSceneIdx]);
316339
SDL_RestoreWindow(loopdata.mWindow);
317340
SDL_SetWindowSize(loopdata.mWindow, renderOptions.windowResolution.x, renderOptions.windowResolution.y);
318341
InitRenderer();
319342
}
320343

344+
// Environment maps
345+
std::vector<const char*> envMapsList;
346+
for (int i = 0; i < envMaps.size(); ++i)
347+
envMapsList.push_back(envMaps[i].c_str());
348+
349+
if (ImGui::Combo("EnvMaps", &envMapIdx, envMapsList.data(), envMapsList.size()))
350+
{
351+
scene->AddHDR(envMaps[envMapIdx]);
352+
InitRenderer();
353+
}
354+
321355
bool optionsChanged = false;
322356

323357
optionsChanged |= ImGui::SliderFloat("Mouse Sensitivity", &mouseSensitivity, 0.001f, 1.0f);
@@ -498,7 +532,8 @@ int main(int argc, char** argv)
498532
else
499533
{
500534
GetSceneFiles();
501-
LoadScene(sceneFiles[sampleSceneIndex]);
535+
GetEnvMaps();
536+
LoadScene(sceneFiles[sampleSceneIdx]);
502537
}
503538

504539
// Setup SDL

src/core/Scene.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,8 @@ namespace GLSLPT
224224
printf("Copying Mesh Data\n");
225225
for (int i = 0; i < meshes.size(); i++)
226226
{
227-
// Copy indices from BVH and not from Mesh
227+
// Copy indices from BVH and not from Mesh.
228+
// Required if splitBVH is used as a triangle can be shared by leaf nodes
228229
int numIndices = meshes[i]->bvh->GetNumIndices();
229230
const int * triIndices = meshes[i]->bvh->GetIndices();
230231

@@ -276,9 +277,9 @@ namespace GLSLPT
276277
if (!camera)
277278
{
278279
RadeonRays::bbox bounds = sceneBvh->Bounds();
279-
Vec3 extents = bounds.extents() * 5.0f;
280+
Vec3 extents = bounds.extents();
280281
Vec3 center = bounds.center();
281-
AddCamera(Vec3(0, center.y, extents.x), center, 45.0f);
282+
AddCamera(Vec3(center.x, center.y, center.z + Vec3::Length(extents) * 2.0f), center, 45.0f);
282283
}
283284

284285
initialized = true;

0 commit comments

Comments
 (0)