Skip to content
This repository has been archived by the owner on Oct 8, 2022. It is now read-only.

Commit

Permalink
Implemented Renderer Option to Draw Prefilter & Irradiance IBL maps
Browse files Browse the repository at this point in the history
  • Loading branch information
lucho1 committed Sep 22, 2021
1 parent aa160c8 commit 9130ce7
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 5 deletions.
9 changes: 7 additions & 2 deletions KaimosEditor/assets/shaders/SkyboxShader.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,17 @@ layout(location = 1) out int color2;
in vec3 v_LocalPos;
uniform samplerCube u_Cubemap;
uniform vec3 u_SceneColor;
uniform bool u_DisplayPrefiltering;
uniform float u_PrefilterMipmap;

// --- Main ---
void main()
{
vec3 env_color = texture(u_Cubemap, v_LocalPos).rgb * u_SceneColor;
//vec3 env_color = textureLod(u_Cubemap, v_LocalPos, 2.2).rgb;
vec3 env_color = vec3(1.0);
if(u_DisplayPrefiltering)
env_color = textureLod(u_Cubemap, v_LocalPos, u_PrefilterMipmap).rgb * u_SceneColor;
else
env_color = texture(u_Cubemap, v_LocalPos).rgb * u_SceneColor;

env_color = env_color/(env_color + vec3(1.0));
env_color = pow(env_color, vec3(1.0/2.2));
Expand Down
21 changes: 21 additions & 0 deletions KaimosEditor/src/Panels/SettingsPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,27 @@ namespace Kaimos {
enviromap_path = enviromap_path.substr(enviromap_path.find("assets"), enviromap_path.size() - 1);
}

// Environment Rendering Settings
const char* const enviro_render_settings[] = { "Standard", "Render Irradiance Map", "Render Prefiltered Map" };
static int env_rend_op = Renderer::GetEnvironmentRenderingSetting();

ImGui::Text("Environment Rendering"); ImGui::SameLine();
ImGui::SetNextItemWidth(75.0f);
if (ImGui::Combo("###environment_rendering_settings", &env_rend_op, enviro_render_settings, IM_ARRAYSIZE(enviro_render_settings)))
Renderer::SetEnvironmentRenderingSetting(env_rend_op);

if (env_rend_op == 2)
{
const char* const enviro_pref_mipmaps[] = { "0", "1", "2", "3", "4" };
static float enviro_pref_mipmap = Renderer::GetEnvironmentPrefilterMipmap();

ImGui::Text("Prefilter Level"); ImGui::SameLine();
ImGui::SetNextItemWidth(45.0f);
if(ImGui::DragFloat("###enviro_prefilter_mipmap", &enviro_pref_mipmap, 0.1f, 0.0f, 10.0f, "%.1f"))
Renderer::SetEnvironmentPrefilterMipmap(enviro_pref_mipmap);
}


// Skybox HDR Warn
if(!Renderer::IsSceneInPBRPipeline())
ImGui::TextColored({ 0.8f, 0.8f, 0.2f, 1.0f }, "Non-PBR Skybox must be in HDR format too");
Expand Down
39 changes: 36 additions & 3 deletions KaimosEngine/src/Renderer/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ namespace Kaimos {
Ref<CubemapTexture> EnvironmentCubemap = nullptr, IrradianceCubemap = nullptr, PrefilterCubemap = nullptr;
Ref<LUTTexture> BRDF_LutTexture = nullptr;
Ref<Framebuffer> EnvironmentMapFBO = nullptr;
uint EnvironmentRenderingSetting = 0;
float PrefilterDisplayMipmap = 0;
};

static RendererData* s_RendererData = nullptr;
Expand Down Expand Up @@ -234,9 +236,18 @@ namespace Kaimos {
skybox_shader->SetUniformMat4("u_ViewProjection", view_proj);
skybox_shader->SetUniformFloat3("u_SceneColor", s_RendererData->SceneColor);

s_RendererData->EnvironmentCubemap->Bind();
//s_RendererData->IrradianceCubemap->Bind();
//s_RendererData->PrefilterCubemap->Bind();
skybox_shader->SetUniformInt("u_DisplayPrefiltering", 0);
if(s_RendererData->EnvironmentRenderingSetting == 0)
s_RendererData->EnvironmentCubemap->Bind();
else if(s_RendererData->EnvironmentRenderingSetting == 1)
s_RendererData->IrradianceCubemap->Bind();
else
{
skybox_shader->SetUniformInt("u_DisplayPrefiltering", 1);
s_RendererData->PrefilterCubemap->Bind();
skybox_shader->SetUniformFloat("u_PrefilterMipmap", s_RendererData->PrefilterDisplayMipmap);
}

skybox_shader->SetUniformInt("u_Cubemap", 0);
RenderCube();
skybox_shader->Unbind();
Expand Down Expand Up @@ -434,6 +445,28 @@ namespace Kaimos {
return 0;
}

uint Renderer::GetEnvironmentRenderingSetting()
{
return s_RendererData->EnvironmentRenderingSetting;
}

void Renderer::SetEnvironmentRenderingSetting(uint setting)
{
if(setting < 3)
s_RendererData->EnvironmentRenderingSetting = setting;
}

float Renderer::GetEnvironmentPrefilterMipmap()
{
return s_RendererData->PrefilterDisplayMipmap;
}

void Renderer::SetEnvironmentPrefilterMipmap(float mip_level)
{
if (mip_level < 10.1f)
s_RendererData->PrefilterDisplayMipmap = mip_level;
}

glm::ivec2 Renderer::GetEnvironmentMapSize()
{
if (s_RendererData->EnvironmentHDRMap)
Expand Down
5 changes: 5 additions & 0 deletions KaimosEngine/src/Renderer/Renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ namespace Kaimos {
static void ForceEnvironmentMapRecompile(uint environment_map_resolution = 1024, uint prefiltered_map_resolution = 128, uint irradiance_map_resolution = 32);
static void RemoveEnvironmentMap();

static uint GetEnvironmentRenderingSetting();
static void SetEnvironmentRenderingSetting(uint setting);
static float GetEnvironmentPrefilterMipmap();
static void SetEnvironmentPrefilterMipmap(float mip_level);


// --- Event Methods ---
static void OnWindowResize(uint width, uint height);
Expand Down

0 comments on commit 9130ce7

Please sign in to comment.