Skip to content

Commit

Permalink
Picklist for environment maps
Browse files Browse the repository at this point in the history
  • Loading branch information
knightcrawler25 committed Jan 1, 2022
1 parent df26edf commit 00f806d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 9 deletions.
47 changes: 41 additions & 6 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@ Scene* scene = nullptr;
Renderer* renderer = nullptr;

std::vector<string> sceneFiles;
std::vector<string> envMaps;

float mouseSensitivity = 0.01f;
bool keyPressed = false;
int sampleSceneIndex = 0;
int sampleSceneIdx = 0;
int selectedInstance = 0;
double lastTime = SDL_GetTicks();
int envMapIdx = 0;
bool done = false;

std::string shadersDir = "../src/shaders/";
std::string assetsDir = "../assets/";
std::string envMapDir = "../assets/HDR/";

RenderOptions renderOptions;

Expand Down Expand Up @@ -93,6 +96,27 @@ void GetSceneFiles()
tinydir_close(&dir);
}

void GetEnvMaps()
{
tinydir_dir dir;
int i;
tinydir_open_sorted(&dir, envMapDir.c_str());

for (i = 0; i < dir.n_files; i++)
{
tinydir_file file;
tinydir_readfile_n(&dir, &file, i);

std::string ext = std::string(file.extension);
if (ext == "hdr")
{
envMaps.push_back(envMapDir + std::string(file.name));
}
}

tinydir_close(&dir);
}

void LoadScene(std::string sceneName)
{
delete scene;
Expand Down Expand Up @@ -304,20 +328,30 @@ void MainLoop(void* arg)
SaveFrame("./img_" + to_string(renderer->GetSampleCount()) + ".png");
}

// Scenes
std::vector<const char*> scenes;
for (int i = 0; i < sceneFiles.size(); ++i)
{
scenes.push_back(sceneFiles[i].c_str());
}

if (ImGui::Combo("Scene", &sampleSceneIndex, scenes.data(), scenes.size()))
if (ImGui::Combo("Scene", &sampleSceneIdx, scenes.data(), scenes.size()))
{
LoadScene(sceneFiles[sampleSceneIndex]);
LoadScene(sceneFiles[sampleSceneIdx]);
SDL_RestoreWindow(loopdata.mWindow);
SDL_SetWindowSize(loopdata.mWindow, renderOptions.windowResolution.x, renderOptions.windowResolution.y);
InitRenderer();
}

// Environment maps
std::vector<const char*> envMapsList;
for (int i = 0; i < envMaps.size(); ++i)
envMapsList.push_back(envMaps[i].c_str());

if (ImGui::Combo("EnvMaps", &envMapIdx, envMapsList.data(), envMapsList.size()))
{
scene->AddHDR(envMaps[envMapIdx]);
InitRenderer();
}

bool optionsChanged = false;

optionsChanged |= ImGui::SliderFloat("Mouse Sensitivity", &mouseSensitivity, 0.001f, 1.0f);
Expand Down Expand Up @@ -498,7 +532,8 @@ int main(int argc, char** argv)
else
{
GetSceneFiles();
LoadScene(sceneFiles[sampleSceneIndex]);
GetEnvMaps();
LoadScene(sceneFiles[sampleSceneIdx]);
}

// Setup SDL
Expand Down
7 changes: 4 additions & 3 deletions src/core/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ namespace GLSLPT
printf("Copying Mesh Data\n");
for (int i = 0; i < meshes.size(); i++)
{
// Copy indices from BVH and not from Mesh
// Copy indices from BVH and not from Mesh.
// Required if splitBVH is used as a triangle can be shared by leaf nodes
int numIndices = meshes[i]->bvh->GetNumIndices();
const int * triIndices = meshes[i]->bvh->GetIndices();

Expand Down Expand Up @@ -276,9 +277,9 @@ namespace GLSLPT
if (!camera)
{
RadeonRays::bbox bounds = sceneBvh->Bounds();
Vec3 extents = bounds.extents() * 5.0f;
Vec3 extents = bounds.extents();
Vec3 center = bounds.center();
AddCamera(Vec3(0, center.y, extents.x), center, 45.0f);
AddCamera(Vec3(center.x, center.y, center.z + Vec3::Length(extents) * 2.0f), center, 45.0f);
}

initialized = true;
Expand Down

0 comments on commit 00f806d

Please sign in to comment.