Skip to content

Commit

Permalink
[image_based_lighting] improved blending with gi specular and ssr
Browse files Browse the repository at this point in the history
PanosK92 committed Jan 24, 2025
1 parent a4f15ab commit 265ee00
Showing 2 changed files with 16 additions and 24 deletions.
12 changes: 5 additions & 7 deletions data/shaders/light_image_based.hlsl
Original file line number Diff line number Diff line change
@@ -42,20 +42,19 @@ float3 sample_environment(float2 uv, float mip_level, float mip_max)
return tex_environment.SampleLevel(samplers[sampler_trilinear_clamp], uv, mip_level).rgb;
}

float get_blend_weight(float value, float threshold, float smoothness)
float get_blend_weight(float value, float smoothness)
{
return saturate((value - (threshold - smoothness)) / (smoothness * 2.0f));
return saturate((value + smoothness) / (smoothness * 2.0f));
}

float3 combine_specular_sources(float4 specular_ssr, float3 specular_gi, float3 specular_sky)
{
const float threshold = 0.01f;
const float smoothness = 0.35f; // aka blend region size
const float smoothness = 1.0f; // aka blend region size

// get weights for each source
float ssr_alpha = saturate(specular_ssr.a / 0.3f); // it's not exactly an alpha
float ssr_weight = get_blend_weight(ssr_alpha, threshold, smoothness);
float gi_weight = get_blend_weight(luminance(specular_gi), threshold, smoothness);
float ssr_weight = get_blend_weight(ssr_alpha, smoothness);
float gi_weight = get_blend_weight(luminance(specular_gi), smoothness);

// blend
float3 result = specular_sky; // start with sky as base
@@ -111,4 +110,3 @@ void main_cs(uint3 thread_id : SV_DispatchThreadID)

tex_uav[thread_id.xy] += float4(ibl, 0.0f);
}

28 changes: 11 additions & 17 deletions editor/ImGui/Implementation/ImGui_RHI.h
Original file line number Diff line number Diff line change
@@ -201,12 +201,12 @@ namespace ImGui::RHI
RHI_Buffer* index_buffer = rhi_resources->index_buffers[buffer_index].get();
RHI_Queue* queue = RHI_Device::GetQueue(RHI_Queue_Type::Graphics);

// get command list
// child windows need to be handled here
if (!is_main_window)
{
// for independent windows, we use another command list
// this is because it needs to begin, end and present independently
queue->NextCommandList();
swapchain->AcquireNextImage();
queue->GetCommandList()->Begin(queue);
}

RHI_CommandList* cmd_list = queue->GetCommandList();
@@ -258,23 +258,17 @@ namespace ImGui::RHI
}

// set pipeline state
static RHI_PipelineState pso = {};
pso.name = "imgui";
static RHI_PipelineState pso = {};
pso.name = "imgui";
pso.shaders[RHI_Shader_Type::Vertex] = g_shader_vertex.get();
pso.shaders[RHI_Shader_Type::Pixel] = g_shader_pixel.get();
pso.rasterizer_state = g_rasterizer_state.get();
pso.blend_state = g_blend_state.get();
pso.depth_stencil_state = g_depth_stencil_state.get();
pso.render_target_swapchain = swapchain;
pso.clear_color[0] = clear ? Color::standard_black : rhi_color_dont_care;

// begin
if (!is_main_window)
{
swapchain->AcquireNextImage();
cmd_list->Begin(queue);
}
pso.rasterizer_state = g_rasterizer_state.get();
pso.blend_state = g_blend_state.get();
pso.depth_stencil_state = g_depth_stencil_state.get();
pso.render_target_swapchain = swapchain;
pso.clear_color[0] = clear ? Color::standard_black : rhi_color_dont_care;

// start the pass
const char* name = is_main_window ? "imgui_window_main" : "imgui_window_child";
bool gpu_timing = is_main_window;
cmd_list->BeginTimeblock(name, true, spartan::Debugging::IsGpuTimingEnabled() && gpu_timing);

0 comments on commit 265ee00

Please sign in to comment.