diff --git a/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_breakdown_ex.cpp b/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_breakdown_ex.cpp index 9dc6ac0e..9cd73b9a 100644 --- a/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_breakdown_ex.cpp +++ b/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_breakdown_ex.cpp @@ -22,6 +22,7 @@ #define IMGUI_DEFINE_MATH_OPERATORS #include "imgui_breakdown_ex.h" +#include "imgui_ex.h" #include #include @@ -130,6 +131,8 @@ namespace ImGuiX else color = col_base + random(); + color = ColorAlpha( color, style.Alpha, ColorAlphaOp_Multiply ); + window->DrawList->AddRectFilled( rect.Min, rect.Max, color ); t0 = t1; diff --git a/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_ex.cpp b/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_ex.cpp index 02c6ded2..0b65306a 100644 --- a/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_ex.cpp +++ b/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_ex.cpp @@ -182,11 +182,25 @@ namespace ImGuiX Set color alpha. \*************************************************************************/ - ImU32 ColorAlpha( ImU32 color, float alpha ) + ImU32 ColorAlpha( ImU32 color, float alpha, ColorAlphaOp op ) { - ImU32 c = color & 0x00FFFFFF; - ImU8 a = ImClamp( 255.f * alpha, 0.f, 255.f ); - return ( c & 0x00FFFFFF ) | ( a << 24 ); + ImU32 a = ( color & IM_COL32_A_MASK ) >> IM_COL32_A_SHIFT; + switch( op ) + { + case ColorAlphaOp_Set: + a = ImClamp( 255 * alpha, 0, 255 ); + break; + case ColorAlphaOp_Add: + a = ImClamp( a + 255 * alpha, 0, 255 ); + break; + case ColorAlphaOp_Multiply: + a = ImClamp( a * alpha, 0, 255 ); + break; + default: + IM_ASSERT( false ); + break; + } + return ( color & ~IM_COL32_A_MASK ) | ( a << IM_COL32_A_SHIFT ); } /*************************************************************************\ diff --git a/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_ex.h b/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_ex.h index df7b490f..32945a73 100644 --- a/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_ex.h +++ b/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_ex.h @@ -23,6 +23,13 @@ namespace ImGuiX { + enum ColorAlphaOp + { + ColorAlphaOp_Set, + ColorAlphaOp_Add, + ColorAlphaOp_Multiply + }; + /*************************************************************************\ Function: @@ -87,7 +94,7 @@ namespace ImGuiX Set color alpha. \*************************************************************************/ - ImU32 ColorAlpha( ImU32, float ); + ImU32 ColorAlpha( ImU32, float, ColorAlphaOp = ColorAlphaOp_Set ); /*************************************************************************\ diff --git a/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_histogram_ex.cpp b/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_histogram_ex.cpp index c4147e4d..418fab02 100644 --- a/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_histogram_ex.cpp +++ b/VkLayer_profiler_layer/profiler_overlay/imgui_widgets/imgui_histogram_ex.cpp @@ -22,6 +22,7 @@ #define IMGUI_DEFINE_MATH_OPERATORS #include "imgui_histogram_ex.h" +#include "imgui_ex.h" #include #include @@ -242,7 +243,7 @@ namespace ImGuiX { x_pos - 5.0f * g.IO.FontGlobalScale, y_pos }, { x_pos + 5.0f * g.IO.FontGlobalScale, y_pos }, { x_pos, y_pos + 5.0f * g.IO.FontGlobalScale }, - data.color ); + ColorAlpha( data.color, style.Alpha, ColorAlphaOp_Multiply ) ); // Check if mouse is over the event const ImRect event_bb( @@ -292,10 +293,14 @@ namespace ImGuiX ( data.flags & HistogramColumnFlags_NoHover ) == 0 && column_bb.ContainsWithPad( g.IO.MousePos, style.TouchExtraPadding ); + ImU32 color = ColorAlpha( data.color, style.Alpha, ColorAlphaOp_Multiply ); + if( hovered_column ) + color = ColorSaturation( color, 1.5f ); + window->DrawList->AddRectFilled( column_bb.Min, column_bb.Max, - hovered_column ? ColorSaturation( data.color, 1.5f ) : data.color ); + color ); if( hovered_column ) { diff --git a/VkLayer_profiler_layer/profiler_overlay/lang/en_us.h b/VkLayer_profiler_layer/profiler_overlay/lang/en_us.h index 51e347ee..4a0b9937 100644 --- a/VkLayer_profiler_layer/profiler_overlay/lang/en_us.h +++ b/VkLayer_profiler_layer/profiler_overlay/lang/en_us.h @@ -171,6 +171,7 @@ namespace Profiler inline static constexpr char SamplingMode[] = "Sampling mode"; inline static constexpr char FrameDelimiter[] = "Frame delimiter"; inline static constexpr char InterfaceScale[] = "Interface scale"; + inline static constexpr char InterfaceOpacity[] = "Interface opacity"; inline static constexpr char CollectedFrameCount[] = "Collected frame count"; inline static constexpr char ShowDebugLabels[] = "Show debug labels"; inline static constexpr char ShowShaderCapabilities[] = "Show shader capabilities"; diff --git a/VkLayer_profiler_layer/profiler_overlay/profiler_overlay.cpp b/VkLayer_profiler_layer/profiler_overlay/profiler_overlay.cpp index f166e9c3..22e5f293 100644 --- a/VkLayer_profiler_layer/profiler_overlay/profiler_overlay.cpp +++ b/VkLayer_profiler_layer/profiler_overlay/profiler_overlay.cpp @@ -634,6 +634,8 @@ namespace Profiler m_HasNewSnapshots = false; m_pData = nullptr; + + m_Opacity = 0.9f; m_Pause = false; m_Fullscreen = false; m_ShowDebugLabels = true; @@ -925,6 +927,7 @@ namespace Profiler // Begin main window ImGui::PushFont( m_Resources.GetDefaultFont() ); + ImGui::PushStyleVar( ImGuiStyleVar_Alpha, m_Opacity ); ImGui::Begin( m_Title.c_str(), nullptr, mainWindowFlags ); if( !m_Fullscreen ) @@ -1163,6 +1166,7 @@ namespace Profiler pForegroundDrawList->AddCircleFilled( ImGui::GetIO().MousePos, 2.f, 0xffffffff, 4 ); } + ImGui::PopStyleVar(); ImGui::PopFont(); ImGui::Render(); @@ -1185,6 +1189,12 @@ namespace Profiler // Round window corners style.WindowRounding = 7.f; + // Disable default window transparency + for( ImGuiCol col : { ImGuiCol_WindowBg, ImGuiCol_TitleBg, ImGuiCol_TitleBgActive } ) + { + style.Colors[col].w = 1.0f; + } + // Performance graph colors m_RenderPassColumnColor = ImGui::GetColorU32( { 0.9f, 0.7f, 0.0f, 1.0f } ); // #e6b200 m_GraphicsPipelineColumnColor = ImGui::GetColorU32( { 0.9f, 0.7f, 0.0f, 1.0f } ); // #e6b200 @@ -4921,6 +4931,11 @@ namespace Profiler ImGui::PushStyleColor( ImGuiCol_ChildBg, ImGui::GetStyleColorVec4( ImGuiCol_ScrollbarBg ) ); ImGui::PushStyleColor( ImGuiCol_ScrollbarBg, 0 ); + const ImU32 gridColor = ImGuiX::ColorAlpha( IM_COL32( 128, 128, 128, 64 ), m_Opacity, ImGuiX::ColorAlphaOp_Multiply ); + const ImU32 blockColor = ImGuiX::ColorAlpha( m_GraphicsPipelineColumnColor, m_Opacity, ImGuiX::ColorAlphaOp_Multiply ); + const ImU32 hoveredBlockColor = ImGuiX::ColorAlpha( ImGuiX::Darker( m_GraphicsPipelineColumnColor, 1.5f ), m_Opacity, ImGuiX::ColorAlphaOp_Multiply ); + const ImU32 blockBorderColor = ImGuiX::ColorAlpha( ImGuiX::Darker( m_GraphicsPipelineColumnColor ), m_Opacity, ImGuiX::ColorAlphaOp_Multiply ); + if( ImGui::BeginChild( "##ImageMemoryMap", ImVec2( 0, blockMapSize.y + 25.f * interfaceScale ), ImGuiChildFlags_Border, @@ -4937,7 +4952,7 @@ namespace Profiler lt.x += x * blockSize; lt.y += y * blockSize; ImVec2 rb = ImVec2( lt.x + blockSize, lt.y + blockSize ); - dl->AddRect( lt, rb, IM_COL32( 128, 128, 128, 64 ) ); + dl->AddRect( lt, rb, gridColor ); } } @@ -4963,12 +4978,12 @@ namespace Profiler rb.x += ( (float)binding.m_Block.m_ImageExtent.width / formatProperties.imageGranularity.width ) * blockSize; rb.y += ( (float)binding.m_Block.m_ImageExtent.height / formatProperties.imageGranularity.height ) * blockSize; ImRect bb( lt, rb ); - dl->AddRect( lt, rb, ImGuiX::Darker( m_GraphicsPipelineColumnColor ) ); + dl->AddRect( lt, rb, blockBorderColor ); - ImU32 color = m_GraphicsPipelineColumnColor; + ImU32 color = blockColor; bool hovered = bb.Contains( mousePos ); if( hovered ) - color = ImGuiX::Darker( color, 1.5f ); + color = hoveredBlockColor; bb.Expand( ImVec2( -1, -1 ) ); dl->AddRectFilled( bb.Min, bb.Max, color ); @@ -5023,7 +5038,7 @@ namespace Profiler rb.y += formatProperties.imageGranularity.height * blockSize - 2; ImRect bb( lt, rb ); - dl->AddRectFilled( bb.Min, bb.Max, m_GraphicsPipelineColumnColor ); + dl->AddRectFilled( bb.Min, bb.Max, blockColor ); ImVec2 cp = ImGui::GetMousePos(); if( bb.Contains( cp ) ) @@ -6465,6 +6480,13 @@ namespace Profiler ImGui::GetIO().FontGlobalScale = std::clamp( interfaceScale, 0.25f, 4.0f ); } + // Set interface opacity. + float interfaceOpacity = m_Opacity; + if( ImGui::InputFloat( Lang::InterfaceOpacity, &interfaceOpacity, 0.1f, 0, "%.1f", ImGuiInputTextFlags_CharsDecimal ) ) + { + m_Opacity = std::clamp( interfaceOpacity, 0.1f, 1.0f ); + } + // Set number of collected frames int maxFrameCount = static_cast( m_MaxFrameCount ); if( ImGui::InputInt( Lang::CollectedFrameCount, &maxFrameCount ) ) diff --git a/VkLayer_profiler_layer/profiler_overlay/profiler_overlay.h b/VkLayer_profiler_layer/profiler_overlay/profiler_overlay.h index cc5a9c00..68267400 100644 --- a/VkLayer_profiler_layer/profiler_overlay/profiler_overlay.h +++ b/VkLayer_profiler_layer/profiler_overlay/profiler_overlay.h @@ -160,6 +160,8 @@ namespace Profiler bool m_HasNewSnapshots; std::shared_ptr m_pData; + + float m_Opacity; bool m_Pause; bool m_Fullscreen; bool m_ShowDebugLabels;