diff --git a/KaimosEditor/assets/shaders/SkyboxShader.glsl b/KaimosEditor/assets/shaders/SkyboxShader.glsl index 8bfe257..4086214 100644 --- a/KaimosEditor/assets/shaders/SkyboxShader.glsl +++ b/KaimosEditor/assets/shaders/SkyboxShader.glsl @@ -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)); diff --git a/KaimosEditor/src/Panels/SettingsPanel.cpp b/KaimosEditor/src/Panels/SettingsPanel.cpp index d51504d..62a5309 100644 --- a/KaimosEditor/src/Panels/SettingsPanel.cpp +++ b/KaimosEditor/src/Panels/SettingsPanel.cpp @@ -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"); diff --git a/KaimosEngine/src/Renderer/Renderer.cpp b/KaimosEngine/src/Renderer/Renderer.cpp index 02ae7ff..3200eb9 100644 --- a/KaimosEngine/src/Renderer/Renderer.cpp +++ b/KaimosEngine/src/Renderer/Renderer.cpp @@ -52,6 +52,8 @@ namespace Kaimos { Ref EnvironmentCubemap = nullptr, IrradianceCubemap = nullptr, PrefilterCubemap = nullptr; Ref BRDF_LutTexture = nullptr; Ref EnvironmentMapFBO = nullptr; + uint EnvironmentRenderingSetting = 0; + float PrefilterDisplayMipmap = 0; }; static RendererData* s_RendererData = nullptr; @@ -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(); @@ -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) diff --git a/KaimosEngine/src/Renderer/Renderer.h b/KaimosEngine/src/Renderer/Renderer.h index 971004a..37097ce 100644 --- a/KaimosEngine/src/Renderer/Renderer.h +++ b/KaimosEngine/src/Renderer/Renderer.h @@ -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);