EEVEE: Move position renderpass to deferred combined pass

This is supposed to save a few milliseconds of compilation
time per material shader.

This might reduce output precision. If that is an issue
this commit can be reverted.

Rel #145347.

Pull Request: https://projects.blender.org/blender/blender/pulls/146464
This commit is contained in:
Clément Foucault
2025-09-22 14:18:23 +02:00
parent bb57ab3598
commit f7e19909f6
5 changed files with 17 additions and 8 deletions

View File

@@ -763,6 +763,7 @@ void DeferredLayer::end_sync(bool is_first_pass,
pass.specialize_constant(
sh, "use_radiance_feedback", use_feedback_output_ && use_clamp_direct_);
pass.specialize_constant(sh, "render_pass_normal_enabled", rbuf_data.normal_id != -1);
pass.specialize_constant(sh, "render_pass_position_enabled", rbuf_data.position_id != -1);
pass.shader_set(sh);
/* Use stencil test to reject pixels not written by this layer. */
pass.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_ADD_FULL | DRW_STATE_STENCIL_NEQUAL);
@@ -779,6 +780,7 @@ void DeferredLayer::end_sync(bool is_first_pass,
pass.bind_image("radiance_feedback_img", &radiance_feedback_tx_);
pass.bind_resources(inst_.gbuffer);
pass.bind_resources(inst_.uniform_data);
pass.bind_resources(inst_.hiz_buffer.front);
pass.barrier(GPU_BARRIER_TEXTURE_FETCH | GPU_BARRIER_SHADER_IMAGE_ACCESS);
pass.draw_procedural(GPU_PRIM_TRIS, 1, 3);
}
@@ -903,7 +905,7 @@ gpu::Texture *DeferredLayer::render(View &main_view,
}
GPU_framebuffer_bind(combined_fb);
inst_.manager->submit(combine_ps_);
inst_.manager->submit(combine_ps_, render_view);
if (use_feedback_output_ && !use_clamp_direct_) {
/* We skip writing the radiance during the combine pass. Do a simple fast copy. */

View File

@@ -11,6 +11,7 @@
FRAGMENT_SHADER_CREATE_INFO(eevee_deferred_combine)
#include "draw_view_lib.glsl"
#include "eevee_colorspace_lib.glsl"
#include "eevee_gbuffer_read_lib.glsl"
#include "eevee_renderpass_lib.glsl"
@@ -151,6 +152,11 @@ void main()
average_normal = (normal_len < 1e-5f) ? gbuf.surface_N() : (average_normal / normal_len);
output_renderpass_color(uniform_buf.render_pass.normal_id, float4(average_normal, 1.0f));
}
if (render_pass_position_enabled) {
float depth = texelFetch(hiz_tx, texel, 0).r;
float3 P = drw_point_screen_to_world(float3(screen_uv, depth));
output_renderpass_color(uniform_buf.render_pass.position_id, float4(P, 1.0f));
}
out_combined = float4(out_direct + out_indirect, 0.0f);
out_combined = any(isnan(out_combined)) ? float4(1.0f, 0.0f, 1.0f, 0.0f) : out_combined;

View File

@@ -113,7 +113,6 @@ void main()
cryptomatte_object_buf[drw_resource_id()], node_tree.crypto_hash, 0.0f);
imageStoreFast(rp_cryptomatte_img, out_texel, cryptomatte_output);
}
output_renderpass_color(uniform_buf.render_pass.position_id, float4(g_data.P, 1.0f));
output_renderpass_color(uniform_buf.render_pass.emission_id, float4(g_emission, 1.0f));
#endif

View File

@@ -116,7 +116,6 @@ void main()
cryptomatte_object_buf[drw_resource_id()], node_tree.crypto_hash, 0.0f);
imageStoreFast(rp_cryptomatte_img, out_texel, cryptomatte_output);
}
output_renderpass_color(uniform_buf.render_pass.position_id, float4(g_data.P, 1.0f));
output_renderpass_color(uniform_buf.render_pass.emission_id, float4(g_emission, 1.0f));
#endif

View File

@@ -114,23 +114,26 @@ GPU_SHADER_CREATE_INFO(eevee_deferred_combine)
EARLY_FRAGMENT_TEST(true)
/* Inputs. */
SAMPLER(2, usampler2D, direct_radiance_1_tx)
SAMPLER(3, usampler2D, direct_radiance_2_tx)
SAMPLER(4, usampler2D, direct_radiance_3_tx)
SAMPLER(5, sampler2D, indirect_radiance_1_tx)
SAMPLER(6, sampler2D, indirect_radiance_2_tx)
SAMPLER(7, sampler2D, indirect_radiance_3_tx)
SAMPLER(4, usampler2D, direct_radiance_2_tx)
SAMPLER(5, usampler2D, direct_radiance_3_tx)
SAMPLER(6, sampler2D, indirect_radiance_1_tx)
SAMPLER(7, sampler2D, indirect_radiance_2_tx)
SAMPLER(8, sampler2D, indirect_radiance_3_tx)
IMAGE(5, SFLOAT_16_16_16_16, read_write, image2D, radiance_feedback_img)
FRAGMENT_OUT(0, float4, out_combined)
TYPEDEF_SOURCE("eevee_defines.hh")
ADDITIONAL_INFO(eevee_gbuffer_data)
ADDITIONAL_INFO(eevee_render_pass_out)
ADDITIONAL_INFO(eevee_hiz_data)
ADDITIONAL_INFO(gpu_fullscreen)
ADDITIONAL_INFO(draw_view)
FRAGMENT_SOURCE("eevee_deferred_combine_frag.glsl")
/* NOTE: Both light IDs have a valid specialized assignment of '-1' so only when default is
* present will we instead dynamically look-up ID from the uniform buffer. */
SPECIALIZATION_CONSTANT(bool, render_pass_diffuse_light_enabled, false)
SPECIALIZATION_CONSTANT(bool, render_pass_specular_light_enabled, false)
SPECIALIZATION_CONSTANT(bool, render_pass_normal_enabled, false)
SPECIALIZATION_CONSTANT(bool, render_pass_position_enabled, false)
SPECIALIZATION_CONSTANT(bool, use_radiance_feedback, false)
SPECIALIZATION_CONSTANT(bool, use_split_radiance, true)
DO_STATIC_COMPILATION()