diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-07-24 11:33:41 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-07-24 20:24:50 +0300 |
commit | bd9bb56f181de64779539db833217cb6a04d855b (patch) | |
tree | df0cc1361c1ffda5aa752c8374ad17d26a81f809 /source/blender/draw/engines/eevee_next | |
parent | 364babab652bf80d6beea419a74242611a4e2393 (diff) |
EEVEE-Next: Fix Alt+B render borders
A few offsets were missing.
Reminder that this does not change the actual render resolution but it
reduces the VRAM consumption of accumulation buffers.
Diffstat (limited to 'source/blender/draw/engines/eevee_next')
5 files changed, 20 insertions, 11 deletions
diff --git a/source/blender/draw/engines/eevee_next/eevee_film.cc b/source/blender/draw/engines/eevee_next/eevee_film.cc index b8408e55cb3..ae84ea249b7 100644 --- a/source/blender/draw/engines/eevee_next/eevee_film.cc +++ b/source/blender/draw/engines/eevee_next/eevee_film.cc @@ -311,7 +311,7 @@ void Film::init(const int2 &extent, const rcti *output_rect) { /* TODO(@fclem): Over-scans. */ - render_extent_ = math::divide_ceil(extent, int2(data_.scaling_factor)); + data_.render_extent = math::divide_ceil(extent, int2(data_.scaling_factor)); int2 weight_extent = inst_.camera.is_panoramic() ? data_.extent : int2(data_.scaling_factor); eGPUTextureFormat color_format = GPU_RGBA16F; @@ -536,7 +536,13 @@ void Film::accumulate(const DRWView *view) { if (inst_.is_viewport()) { DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get(); + DefaultTextureList *dtxl = DRW_viewport_texture_list_get(); GPU_framebuffer_bind(dfbl->default_fb); + /* Clear when using render borders. */ + if (data_.extent != int2(GPU_texture_width(dtxl->color), GPU_texture_height(dtxl->color))) { + float4 clear_color = {0.0f, 0.0f, 0.0f, 0.0f}; + GPU_framebuffer_clear_color(dfbl->default_fb, clear_color); + } GPU_framebuffer_viewport_set(dfbl->default_fb, UNPACK2(data_.offset), UNPACK2(data_.extent)); } diff --git a/source/blender/draw/engines/eevee_next/eevee_film.hh b/source/blender/draw/engines/eevee_next/eevee_film.hh index e2d5956710d..26e27c447bc 100644 --- a/source/blender/draw/engines/eevee_next/eevee_film.hh +++ b/source/blender/draw/engines/eevee_next/eevee_film.hh @@ -55,8 +55,6 @@ class Film { /** Static reference as SwapChain does not actually move the objects when swapping. */ GPUTexture *weight_src_tx_ = nullptr; GPUTexture *weight_dst_tx_ = nullptr; - /** Extent used by the render buffers when rendering the main views. */ - int2 render_extent_ = int2(-1); /** User setting to disable reprojection. Useful for debugging or have a more precise render. */ bool force_disable_reprojection_ = false; @@ -86,7 +84,7 @@ class Film { int2 render_extent_get() const { - return render_extent_; + return data_.render_extent; } float2 pixel_jitter_get() const; diff --git a/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh b/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh index cc991efeee2..d703f000ab6 100644 --- a/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh +++ b/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh @@ -154,6 +154,8 @@ struct FilmData { int2 extent; /** Offset of the film in the full-res frame, in pixels. */ int2 offset; + /** Extent used by the render buffers when rendering the main views. */ + int2 render_extent; /** Sub-pixel offset applied to the window matrix. * NOTE: In final film pixel unit. * NOTE: Positive values makes the view translate in the negative axes direction. @@ -172,6 +174,7 @@ struct FilmData { /** Is true if accumulation of filtered passes is needed. */ bool1 any_render_pass_1; bool1 any_render_pass_2; + float _pad0, _pad1; /** Output counts per type. */ int color_len, value_len; /** Index in color_accum_img or value_accum_img of each pass. -1 if pass is not enabled. */ 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 454c835673b..5867330f151 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 @@ -4,7 +4,7 @@ void main() { - ivec2 texel_film = ivec2(gl_FragCoord.xy); + ivec2 texel_film = ivec2(gl_FragCoord.xy) - film_buf.offset; float out_depth; if (film_buf.display_only) { 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 efd3d2dfe35..c0d19ca4451 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 @@ -80,9 +80,9 @@ FilmSample film_sample_get(int sample_n, ivec2 texel_film) # endif FilmSample film_sample = film_buf.samples[sample_n]; - film_sample.texel += texel_film; + film_sample.texel += texel_film + film_buf.offset; /* Use extend on borders. */ - film_sample.texel = clamp(film_sample.texel, ivec2(0, 0), film_buf.extent - 1); + film_sample.texel = clamp(film_sample.texel, ivec2(0, 0), film_buf.render_extent - 1); /* TODO(fclem): Panoramic projection will need to compute the sample weight in the shader * instead of precomputing it on CPU. */ @@ -440,7 +440,7 @@ void film_store_combined( /* Interactive accumulation. Do reprojection and Temporal Anti-Aliasing. */ /* Reproject by finding where this pixel was in the previous frame. */ - vec2 motion = film_pixel_history_motion_vector(dst.texel); + vec2 motion = film_pixel_history_motion_vector(src_texel); vec2 history_texel = vec2(dst.texel) + motion; float velocity = length(motion); @@ -592,11 +592,13 @@ void film_process_data(ivec2 texel_film, out vec4 out_color, out float out_depth float weight_accum = 0.0; vec4 combined_accum = vec4(0.0); - for (int i = 0; i < film_buf.samples_len; i++) { - FilmSample src = film_sample_get(i, texel_film); + FilmSample src; + for (int i = film_buf.samples_len - 1; i >= 0; i--) { + src = film_sample_get(i, texel_film); film_sample_accum_combined(src, combined_accum, weight_accum); } - film_store_combined(dst, texel_film, combined_accum, weight_accum, out_color); + /* NOTE: src.texel is center texel in incomming data buffer. */ + film_store_combined(dst, src.texel, combined_accum, weight_accum, out_color); } if (film_buf.has_data) { |