diff options
author | Clément Foucault <foucault.clem@gmail.com> | 2022-07-23 23:56:01 +0300 |
---|---|---|
committer | Clément Foucault <foucault.clem@gmail.com> | 2022-07-23 23:57:10 +0300 |
commit | 0c3851d31fa89642797f00da179ca91702c28697 (patch) | |
tree | 9182da0347d37bdb9793a820ae0d7a6fcbda76bd /source/blender/draw/engines/eevee_next | |
parent | 3ea2b4ac310af64572045f59debd550e7f9671cc (diff) |
EEVEE-Next: Film: Rename filter_size for clarity and add box filter ...
... as a debug option.
Diffstat (limited to 'source/blender/draw/engines/eevee_next')
3 files changed, 23 insertions, 21 deletions
diff --git a/source/blender/draw/engines/eevee_next/eevee_film.cc b/source/blender/draw/engines/eevee_next/eevee_film.cc index a111b1db4a3..b8408e55cb3 100644 --- a/source/blender/draw/engines/eevee_next/eevee_film.cc +++ b/source/blender/draw/engines/eevee_next/eevee_film.cc @@ -146,8 +146,8 @@ void Film::sync_mist() inline bool operator==(const FilmData &a, const FilmData &b) { - return (a.extent == b.extent) && (a.offset == b.offset) && (a.filter_size == b.filter_size) && - (a.scaling_factor == b.scaling_factor); + return (a.extent == b.extent) && (a.offset == b.offset) && + (a.filter_radius == b.filter_radius) && (a.scaling_factor == b.scaling_factor); } inline bool operator!=(const FilmData &a, const FilmData &b) @@ -232,8 +232,8 @@ void Film::init(const int2 &extent, const rcti *output_rect) data.offset = int2(output_rect->xmin, output_rect->ymin); data.extent_inv = 1.0f / float2(data.extent); /* Disable filtering if sample count is 1. */ - data.filter_size = (sampling.sample_count() == 1) ? 0.0f : - clamp_f(scene.r.gauss, 0.0f, 100.0f); + data.filter_radius = (sampling.sample_count() == 1) ? 0.0f : + clamp_f(scene.r.gauss, 0.0f, 100.0f); /* TODO(fclem): parameter hidden in experimental. * We need to figure out LOD bias first in order to preserve texture crispiness. */ data.scaling_factor = 1; @@ -433,12 +433,12 @@ float2 Film::pixel_jitter_get() const { float2 jitter = inst_.sampling.rng_2d_get(SAMPLING_FILTER_U); - if (data_.filter_size < M_SQRT1_2 && !inst_.camera.is_panoramic()) { + if (!use_box_filter && data_.filter_radius < M_SQRT1_2 && !inst_.camera.is_panoramic()) { /* For filter size less than a pixel, change sampling strategy and use a uniform disk * distribution covering the filter shape. This avoids putting samples in areas without any * weights. */ /* TODO(fclem): Importance sampling could be a better option here. */ - jitter = Sampling::sample_disk(jitter) * data_.filter_size; + jitter = Sampling::sample_disk(jitter) * data_.filter_radius; } else { /* Jitter the size of a whole pixel. [-0.5..0.5] */ @@ -459,36 +459,36 @@ void Film::update_sample_table() { data_.subpixel_offset = pixel_jitter_get(); - int filter_size_ceil = ceilf(data_.filter_size); - float filter_size_sqr = square_f(data_.filter_size); + int filter_radius_ceil = ceilf(data_.filter_radius); + float filter_radius_sqr = square_f(data_.filter_radius); data_.samples_len = 0; - if (data_.filter_size < 0.01f) { - /* Disable filtering. */ + if (use_box_filter || data_.filter_radius < 0.01f) { + /* Disable gather filtering. */ data_.samples[0].texel = int2(0, 0); data_.samples[0].weight = 1.0f; data_.samples_weight_total = 1.0f; data_.samples_len = 1; } /* NOTE: Threshold determined by hand until we don't hit the assert bellow. */ - else if (data_.filter_size < 2.20f) { + else if (data_.filter_radius < 2.20f) { /* Small filter Size. */ int closest_index = 0; float closest_distance = FLT_MAX; data_.samples_weight_total = 0.0f; /* TODO(fclem): For optimization, could try Z-tile ordering. */ - for (int y = -filter_size_ceil; y <= filter_size_ceil; y++) { - for (int x = -filter_size_ceil; x <= filter_size_ceil; x++) { + for (int y = -filter_radius_ceil; y <= filter_radius_ceil; y++) { + for (int x = -filter_radius_ceil; x <= filter_radius_ceil; x++) { float2 pixel_offset = float2(x, y) - data_.subpixel_offset; float distance_sqr = math::length_squared(pixel_offset); - if (distance_sqr < filter_size_sqr) { + if (distance_sqr < filter_radius_sqr) { if (data_.samples_len >= FILM_PRECOMP_SAMPLE_MAX) { BLI_assert_msg(0, "Precomputed sample table is too small."); break; } FilmSample &sample = data_.samples[data_.samples_len]; sample.texel = int2(x, y); - sample.weight = film_filter_weight(data_.filter_size, distance_sqr); + sample.weight = film_filter_weight(data_.filter_radius, distance_sqr); data_.samples_weight_total += sample.weight; if (distance_sqr < closest_distance) { @@ -521,11 +521,11 @@ void Film::update_sample_table() * neighbor filtering not converging rapidly. */ random_2d.x = (random_2d.x + i) / float(FILM_PRECOMP_SAMPLE_MAX); - float2 pixel_offset = math::floor(Sampling::sample_spiral(random_2d) * data_.filter_size); + float2 pixel_offset = math::floor(Sampling::sample_spiral(random_2d) * data_.filter_radius); sample.texel = int2(pixel_offset); float distance_sqr = math::length_squared(pixel_offset - data_.subpixel_offset); - sample.weight = film_filter_weight(data_.filter_size, distance_sqr); + sample.weight = film_filter_weight(data_.filter_radius, distance_sqr); data_.samples_weight_total += sample.weight; i++; } diff --git a/source/blender/draw/engines/eevee_next/eevee_film.hh b/source/blender/draw/engines/eevee_next/eevee_film.hh index 4ccd5684396..e2d5956710d 100644 --- a/source/blender/draw/engines/eevee_next/eevee_film.hh +++ b/source/blender/draw/engines/eevee_next/eevee_film.hh @@ -34,6 +34,8 @@ class Film { public: /** Stores indirection table of AOVs based on their name hash and their type. */ AOVsInfoDataBuf aovs_info; + /** For debugging purpose but could be a user option in the future. */ + static constexpr bool use_box_filter = false; private: Instance &inst_; 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 819f49756d7..cc991efeee2 100644 --- a/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh +++ b/source/blender/draw/engines/eevee_next/eevee_shader_shared.hh @@ -206,7 +206,7 @@ struct FilmData { /** Scaling factor for scaled resolution rendering. */ int scaling_factor; /** Film pixel filter radius. */ - float filter_size; + float filter_radius; /** Precomputed samples. First in the table is the closest one. The rest is unordered. */ int samples_len; /** Sum of the weights of all samples in the sample table. */ @@ -215,17 +215,17 @@ struct FilmData { }; BLI_STATIC_ASSERT_ALIGN(FilmData, 16) -static inline float film_filter_weight(float filter_size, float sample_distance_sqr) +static inline float film_filter_weight(float filter_radius, float sample_distance_sqr) { #if 1 /* Faster */ /* Gaussian fitted to Blackman-Harris. */ - float r = sample_distance_sqr / (filter_size * filter_size); + float r = sample_distance_sqr / (filter_radius * filter_radius); const float sigma = 0.284; const float fac = -0.5 / (sigma * sigma); float weight = expf(fac * r); #else /* Blackman-Harris filter. */ - float r = M_2PI * saturate(0.5 + sqrtf(sample_distance_sqr) / (2.0 * filter_size)); + float r = M_2PI * saturate(0.5 + sqrtf(sample_distance_sqr) / (2.0 * filter_radius)); float weight = 0.35875 - 0.48829 * cosf(r) + 0.14128 * cosf(2.0 * r) - 0.01168 * cosf(3.0 * r); #endif return weight; |