diff --git a/source/blender/draw/engines/eevee_next/eevee_film.cc b/source/blender/draw/engines/eevee_next/eevee_film.cc index 0820a2fb13e..13bbc04fec4 100644 --- a/source/blender/draw/engines/eevee_next/eevee_film.cc +++ b/source/blender/draw/engines/eevee_next/eevee_film.cc @@ -458,6 +458,9 @@ void Film::sync() accumulate_ps_.specialize_constant(sh, "samples_len", &data_.samples_len); accumulate_ps_.specialize_constant(sh, "use_reprojection", &use_reprojection_); accumulate_ps_.specialize_constant(sh, "scaling_factor", data_.scaling_factor); + accumulate_ps_.specialize_constant(sh, "combined_id", &data_.combined_id); + accumulate_ps_.specialize_constant(sh, "display_id", &data_.display_id); + accumulate_ps_.specialize_constant(sh, "normal_id", &data_.normal_id); accumulate_ps_.state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_ALWAYS); accumulate_ps_.shader_set(sh); accumulate_ps_.bind_resources(inst_.uniform_data); diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_film_frag.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_film_frag.glsl index 7f265f207ff..a7b44adc3d6 100644 --- a/source/blender/draw/engines/eevee_next/shaders/eevee_film_frag.glsl +++ b/source/blender/draw/engines/eevee_next/shaders/eevee_film_frag.glsl @@ -12,20 +12,19 @@ void main() if (uniform_buf.film.display_only) { out_depth = imageLoad(depth_img, texel_film).r; - if (uniform_buf.film.display_id == -1) { + if (display_id == -1) { out_color = texelFetch(in_combined_tx, texel_film, 0); } else if (uniform_buf.film.display_storage_type == PASS_STORAGE_VALUE) { - out_color.rgb = - imageLoad(value_accum_img, ivec3(texel_film, uniform_buf.film.display_id)).rrr; + out_color.rgb = imageLoad(value_accum_img, ivec3(texel_film, display_id)).rrr; out_color.a = 1.0; } else if (uniform_buf.film.display_storage_type == PASS_STORAGE_COLOR) { - out_color = imageLoad(color_accum_img, ivec3(texel_film, uniform_buf.film.display_id)); + out_color = imageLoad(color_accum_img, ivec3(texel_film, display_id)); } else /* PASS_STORAGE_CRYPTOMATTE */ { out_color = cryptomatte_false_color( - imageLoad(cryptomatte_img, ivec3(texel_film, uniform_buf.film.display_id)).r); + imageLoad(cryptomatte_img, ivec3(texel_film, display_id)).r); } } else { diff --git a/source/blender/draw/engines/eevee_next/shaders/eevee_film_lib.glsl b/source/blender/draw/engines/eevee_next/shaders/eevee_film_lib.glsl index d25f1f04f91..b9849e482c8 100644 --- a/source/blender/draw/engines/eevee_next/shaders/eevee_film_lib.glsl +++ b/source/blender/draw/engines/eevee_next/shaders/eevee_film_lib.glsl @@ -87,7 +87,7 @@ float film_weight_accumulation(ivec2 texel_film) /* TODO(fclem): Reference implementation, also needed for panoramic cameras. */ if (scaling_factor > 1) { float weight = 0.0; - for (int i = 0; i < uniform_buf.film.samples_len; i++) { + for (int i = 0; i < samples_len; i++) { weight += film_sample_get(i, texel_film).weight; } return weight; @@ -132,7 +132,7 @@ void film_sample_accum_mist(FilmSample samp, inout float accum) void film_sample_accum_combined(FilmSample samp, inout vec4 accum, inout float weight_accum) { - if (uniform_buf.film.combined_id == -1) { + if (combined_id == -1) { return; } vec4 color = film_texelfetch_as_YCoCg_opacity(combined_tx, samp.texel); @@ -436,7 +436,7 @@ float film_history_blend_factor(float velocity, void film_store_combined( FilmSample dst, ivec2 src_texel, vec4 color, float color_weight, inout vec4 display) { - if (uniform_buf.film.combined_id == -1) { + if (combined_id == -1) { return; } @@ -499,7 +499,7 @@ void film_store_combined( color = vec4(0.0, 0.0, 0.0, 1.0); } - if (uniform_buf.film.display_id == -1) { + if (display_id == -1) { display = color; } imageStore(out_combined_img, dst.texel, color); @@ -520,7 +520,7 @@ void film_store_color(FilmSample dst, int pass_id, vec4 color, inout vec4 displa color = vec4(0.0, 0.0, 0.0, 1.0); } - if (uniform_buf.film.display_id == pass_id) { + if (display_id == pass_id) { display = color; } imageStore(color_accum_img, ivec3(dst.texel, pass_id), color); @@ -541,7 +541,7 @@ void film_store_value(FilmSample dst, int pass_id, float value, inout vec4 displ value = 0.0; } - if (uniform_buf.film.display_id == pass_id) { + if (display_id == pass_id) { display = vec4(value, value, value, 1.0); } imageStore(value_accum_img, ivec3(dst.texel, pass_id), vec4(value)); @@ -554,7 +554,7 @@ void film_store_data(ivec2 texel_film, int pass_id, vec4 data_sample, inout vec4 return; } - if (uniform_buf.film.display_id == pass_id) { + if (display_id == pass_id) { display = data_sample; } imageStore(color_accum_img, ivec3(texel_film, pass_id), data_sample); @@ -616,7 +616,7 @@ void film_process_data(ivec2 texel_film, out vec4 out_color, out float out_depth /* NOTE: We split the accumulations into separate loops to avoid using too much registers and * maximize occupancy. */ - if (uniform_buf.film.combined_id != -1) { + if (combined_id != -1) { /* NOTE: Do weight accumulation again since we use custom weights. */ float weight_accum = 0.0; vec4 combined_accum = vec4(0.0); @@ -643,10 +643,10 @@ void film_process_data(ivec2 texel_film, out vec4 out_color, out float out_depth vector *= vec4(vec2(uniform_buf.film.render_extent), vec2(uniform_buf.film.render_extent)); film_store_depth(texel_film, depth, out_depth); - if (uniform_buf.film.normal_id != -1) { + if (normal_id != -1) { vec4 normal = texelFetch( rp_color_tx, ivec3(film_sample.texel, uniform_buf.render_pass.normal_id), 0); - film_store_data(texel_film, uniform_buf.film.normal_id, normal, out_color); + film_store_data(texel_film, normal_id, normal, out_color); } if (uniform_buf.film.position_id != -1) { vec4 position = texelFetch( @@ -658,10 +658,8 @@ void film_process_data(ivec2 texel_film, out vec4 out_color, out float out_depth } else { out_depth = imageLoad(depth_img, texel_film).r; - if (uniform_buf.film.display_id != -1 && - uniform_buf.film.display_id == uniform_buf.film.normal_id) - { - out_color = imageLoad(color_accum_img, ivec3(texel_film, uniform_buf.film.display_id)); + if (display_id != -1 && display_id == normal_id) { + out_color = imageLoad(color_accum_img, ivec3(texel_film, display_id)); } } } diff --git a/source/blender/draw/engines/eevee_next/shaders/infos/eevee_film_info.hh b/source/blender/draw/engines/eevee_next/shaders/infos/eevee_film_info.hh index 8005eaeec45..9a614d2b751 100644 --- a/source/blender/draw/engines/eevee_next/shaders/infos/eevee_film_info.hh +++ b/source/blender/draw/engines/eevee_next/shaders/infos/eevee_film_info.hh @@ -27,6 +27,9 @@ GPU_SHADER_CREATE_INFO(eevee_film) .specialization_constant(Type::INT, "samples_len", 0) .specialization_constant(Type::BOOL, "use_reprojection", false) .specialization_constant(Type::INT, "scaling_factor", 1) + .specialization_constant(Type::INT, "combined_id", 0) + .specialization_constant(Type::INT, "display_id", -1) + .specialization_constant(Type::INT, "normal_id", -1) .additional_info("eevee_shared") .additional_info("eevee_global_ubo") .additional_info("eevee_velocity_camera")