Skip to content

Commit

Permalink
DDGI probe count can now be changed
Browse files Browse the repository at this point in the history
  • Loading branch information
tippesi committed Mar 7, 2022
1 parent 411b4e4 commit 9179c90
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 32 deletions.
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ endif()

# Options and compiler settings ###################################################################
option(ATLAS_DEMO "Build demo executable" OFF)
option(ATLAS_IMGUI "Activate ImGui integration" OFF)

if (ATLAS_DEMO)
set (ATLAS_IMGUI ON)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
Expand Down Expand Up @@ -74,7 +79,10 @@ else()
add_subdirectory(${GLAD_LOCATION})
endif()
add_subdirectory(${ATLAS_LOCATION})
if (ATLAS_DEMO)

if (ATLAS_IMGUI)
add_subdirectory(${IMGUI_LOCATION})
endif()
if (ATLAS_DEMO)
add_subdirectory(${DEMO_LOCATION})
endif()
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ Run CMake with the option ATLAS_DEMO=ON to include the demo application in the p
that and launches Visual Studio afterwards. After launching the IDE, set AtlasEngineDemo as your target.
### Including the library into your own project
It is possible to compile the engine either as a shared or static library. Set the ATLAS_BUILD_SHARED option accordingly. To make
the library work with its dependencies, the root CMakeLists.txt of this repository has to be added as a subdirectory.
the library work with its dependencies, the root CMakeLists.txt of this repository has to be added as a subdirectory. As an entry
point to create an application from scratch take a look at the [Hello World tutorial](https://github.com/tippesi/Atlas-Engine/wiki/Hello-World). For reference, the source folder contains an empty [app header](https://github.com/tippesi/Atlas-Engine/blob/master/src/App.h) and an empty [app source](https://github.com/tippesi/Atlas-Engine/blob/master/src/App.cpp).
<!---
### Android
You can compile the engine using Gradle either with or without AndroidStudio.
Expand Down
89 changes: 61 additions & 28 deletions demo/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ void App::LoadContent() {

font = Atlas::Font("font/roboto.ttf", 44, 10);

DisplayLoadingScreen();

camera = Atlas::Camera(47.0f, 2.0f, 1.0f, 400.0f,
vec3(30.0f, 25.0f, 0.0f), vec2(-3.14f / 2.0f, 0.0f));

Expand All @@ -40,27 +42,20 @@ void App::LoadContent() {
directionalLight = Atlas::Lighting::DirectionalLight(AE_MOVABLE_LIGHT);
directionalLight.direction = vec3(0.0f, -1.0f, 1.0f);
directionalLight.color = vec3(253, 194, 109) / 255.0f;

// Cascaded shadow mapping
directionalLight.AddShadow(150.0f, 1.1f, 1024, 5, 0.8f);
directionalLight.AddVolumetric(10, 0.28f);

scene.Add(&directionalLight);

scene.ssao = new Atlas::Lighting::SSAO(32);

scene.fog = new Atlas::Lighting::Fog();

scene.fog->enable = true;
scene.fog->density = 0.0002f;
scene.fog->heightFalloff = 0.0284f;
scene.fog->height = 0.0f;
scene.fog->scatteringAnisotropy = 0.0f;

LoadScene();

scene.postProcessing.taa = Atlas::PostProcessing::TAA(0.99f);
// Use against TAA smoothing
scene.postProcessing.sharpen.enable = true;
scene.postProcessing.sharpen.factor = 0.15f;

Expand All @@ -70,22 +65,7 @@ void App::LoadContent() {
sphere.data.materials[0].metalness = 0.0;
sphere.data.materials[0].baseColor = vec3(1.0);

scene.Update(&camera, 1.0f);
scene.BuildRTStructures();

auto volume = scene.irradianceVolume;
volume->hysteresis = 0.99f;

int32_t probeCount = volume->probeCount.x * volume->probeCount.y *
volume->probeCount.z;

for (int32_t j = 0; j < probeCount; j++) {
auto actor = new Atlas::Actor::MovableMeshActor(&sphere);
actor->visible = false;
sphereActors.push_back(actor);

scene.Add(actor);
}
LoadScene();

ImGui::CreateContext();
ImGuiIO& io = ImGui::GetIO(); (void)io;
Expand Down Expand Up @@ -128,9 +108,9 @@ void App::Update(float deltaTime) {
static bool renderSpheres = false;
if (renderSpheres != spheresVisible) {
renderSpheres = spheresVisible;
for (auto actor : sphereActors)
for (auto& actor : probeActors)
{
actor->visible = renderSpheres;
actor.visible = renderSpheres;
}
}
if (renderSpheres) {
Expand All @@ -153,7 +133,7 @@ void App::Update(float deltaTime) {
ivec3 offset = ivec3(x, y, z);
vec3 pos = scene.irradianceVolume->GetProbeLocation(offset);

sphereActors[j]->SetMatrix(glm::translate(pos));
probeActors[j].SetMatrix(glm::translate(pos));
}
}
}
Expand Down Expand Up @@ -271,7 +251,7 @@ void App::Render(float deltaTime) {
const char* items[] = { "1280x720", "1920x1080", "2560x1440", "3840x2160" };
static int resolution = 1;
int currentItem = resolution;
ImGui::Combo("Resolution", &currentItem, items, IM_ARRAYSIZE(items));
ImGui::Combo("Resolution##Rendering", &currentItem, items, IM_ARRAYSIZE(items));

if (currentItem != resolution) {
resolution = currentItem;
Expand All @@ -285,12 +265,33 @@ void App::Render(float deltaTime) {

}

if (ImGui::CollapsingHeader("Irradiance volume")) {
if (ImGui::CollapsingHeader("DDGI")) {
ImGui::Text(("Probe count: " + vecToString(volume->probeCount)).c_str());
ImGui::Checkbox("Enable volume", &volume->enable);
ImGui::Checkbox("Update volume", &volume->update);
ImGui::Checkbox("Visualize probes", &spheresVisible);
ImGui::Checkbox("Sample emissives", &volume->sampleEmissives);

const char* items[] = { "5x5x5", "10x10x10", "20x20x20", "30x30x30" };
int currentItem = 0;
if (volume->probeCount == ivec3(5)) currentItem = 0;
if (volume->probeCount == ivec3(10)) currentItem = 1;
if (volume->probeCount == ivec3(20)) currentItem = 2;
if (volume->probeCount == ivec3(30)) currentItem = 3;
auto prevItem = currentItem;
ImGui::Combo("Resolution##DDGI", &currentItem, items, IM_ARRAYSIZE(items));

if (currentItem != prevItem) {
RemoveProbeActors();
switch (currentItem) {
case 0: volume->SetProbeCount(ivec3(5)); break;
case 1: volume->SetProbeCount(ivec3(10)); break;
case 2: volume->SetProbeCount(ivec3(20)); break;
case 3: volume->SetProbeCount(ivec3(30)); break;
}
AddProbeActors();
}

ImGui::SliderFloat("Strength##DDGI", &volume->strength, 0.0f, 5.0f);
ImGui::Separator();
ImGui::Text("AABB");
Expand Down Expand Up @@ -411,6 +412,8 @@ bool App::LoadScene() {

DisplayLoadingScreen();

RemoveProbeActors();

Atlas::Texture::Cubemap sky;
//else sky = Atlas::Texture::Cubemap("moonlit_golf_4k.hdr", 1024);

Expand Down Expand Up @@ -537,6 +540,8 @@ bool App::LoadScene() {
scene.Update(&camera, 1.0f);
scene.BuildRTStructures();

AddProbeActors();

// Reset input handlers
keyboardHandler.Reset(&camera);
mouseHandler.Reset(&camera);
Expand All @@ -554,6 +559,34 @@ void App::UnloadScene() {

}

void App::AddProbeActors() {

auto volume = scene.irradianceVolume;
int32_t probeCount = volume->probeCount.x * volume->probeCount.y *
volume->probeCount.z;

for (int32_t j = 0; j < probeCount; j++) {
auto actor = Atlas::Actor::MovableMeshActor(&sphere);
actor.visible = spheresVisible;
probeActors.push_back(actor);
}

for (auto& actor : probeActors) {
scene.Add(&actor);
}

}

void App::RemoveProbeActors() {

for (auto& actor : probeActors) {
scene.Remove(&actor);
}

probeActors.clear();

}

void App::SetResolution(int32_t width, int32_t height) {

renderTarget->Resize(width, height);
Expand Down
5 changes: 4 additions & 1 deletion demo/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class App : public Atlas::EngineInstance {
bool LoadScene();
void UnloadScene();

void AddProbeActors();
void RemoveProbeActors();

void SetResolution(int32_t width, int32_t height);

SceneSelection sceneSelection = SPONZA;
Expand All @@ -66,7 +69,7 @@ class App : public Atlas::EngineInstance {
Atlas::Input::MouseHandler mouseHandler;
Atlas::Input::KeyboardHandler keyboardHandler;

std::vector<Atlas::Actor::MovableMeshActor*> sphereActors;
std::vector<Atlas::Actor::MovableMeshActor> probeActors;

bool renderUI = true;
bool renderEnvProbe = true;
Expand Down
11 changes: 11 additions & 0 deletions demo/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
cmake_minimum_required(VERSION 3.7)
project(AtlasEngineDemo)

# Note: For this project, the root CMakeLists.txt turns
# the ATLAS_IMGUI and ATLAS_EXPORT_MAIN options on.

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/)

file(GLOB_RECURSE DEMO_SOURCE_FILES
Expand All @@ -10,6 +13,8 @@ file(GLOB_RECURSE DEMO_SOURCE_FILES
"*.hpp"
)

# Required: Set both the source and dependency directories
# as include directories
include_directories(../src)
include_directories(../dependencies)

Expand All @@ -24,6 +29,12 @@ foreach(SOURCE_FILE IN ITEMS ${DEMO_SOURCE_FILES})
source_group("${SOURCE_PATH_CONVERTED}" FILES "${SOURCE_FILE}")
endforeach()

# We use the exported main file from the AtlasEngine library to able to use
# the app class. Alternatively, you can write a main function yourself.
# To export the main file the ATLAS_EXPORT_MAIN option has to be turned on.
add_executable(${PROJECT_NAME} ${DEMO_SOURCE_FILES} ${ATLAS_ENGINE_MAIN_FILE})
# Required: Add the compile definitions of the library, such that includes work properly
target_compile_definitions(${PROJECT_NAME} PUBLIC ${ATLAS_ENGINE_COMPILE_DEFINITIONS})
# We want to use both ImGui and the AtlasEngine. For ImGui, the ATLAS_IMGUI option
# needs to be turned on.
target_link_libraries (${PROJECT_NAME} AtlasEngine Imgui)
2 changes: 1 addition & 1 deletion src/System.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#define AE_SHOW_LOG
// #define AE_SHOW_API_DEBUG_LOG
#define AE_INSTANT_SHADER_RELOAD
// #define AE_INSTANT_SHADER_RELOAD

#include <stdint.h>
#include <string>
Expand Down
17 changes: 17 additions & 0 deletions src/lighting/IrradianceVolume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,23 @@ namespace Atlas {

}

void IrradianceVolume::SetProbeCount(ivec3 probeCount) {

this->probeCount = probeCount;

auto irrRes = ivec2(this->irrRes + 2);
irrRes.x *= probeCount.x;
irrRes.y *= probeCount.z;

auto momRes = ivec2(this->momRes + 2);
momRes.x *= probeCount.x;
momRes.y *= probeCount.z;

internal = InternalIrradianceVolume(irrRes, momRes, probeCount);
internal.SetRayCount(rayCount, rayCountInactive);

}

void IrradianceVolume::ClearProbes() {

auto irrRes = ivec2(this->irrRes + 2);
Expand Down
2 changes: 2 additions & 0 deletions src/lighting/IrradianceVolume.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ namespace Atlas {

void SetRayCount(uint32_t rayCount, uint32_t rayCountInactive);

void SetProbeCount(ivec3 probeCount);

void ClearProbes();

Volume::AABB aabb;
Expand Down

0 comments on commit 9179c90

Please sign in to comment.