18 int closest_index = 0;
19 float closest_squared_distance = 1.0f;
23 if (squared_dist < closest_squared_distance) {
24 closest_squared_distance = squared_dist;
29 const float2 closest_sample = samples[closest_index];
41 if (closest_index != 0) {
42 std::swap(samples[0], samples[closest_index]);
46 for (
int i = 0; i < samples.
size() - 2; i++) {
47 float squared_dist = 0.0;
49 for (
int j = i + 1; j < samples.
size(); j++) {
51 if (_squared_dist > squared_dist) {
52 squared_dist = _squared_dist;
56 std::swap(samples[i + 1], samples[index]);
61 std::array<float2, 5>
x5;
62 std::array<float2, 8>
x8;
63 std::array<float2, 11>
x11;
64 std::array<float2, 16>
x16;
65 std::array<float2, 32>
x32;
85 if (
x > width * 0.5f) {
97 const float filter_width = 2.0f;
100 for (
int x = -1;
x <= 1;
x++) {
101 for (
int y = -1;
y <= 1;
y++, i++) {
103 float r =
len_v2(sample_co);
106 r_weight_sum += weight;
107 r_weights[i] = weight;
114 smaa_search_tx_.ensure_2d(
126 enabled_ = scene_state.
draw_aa;
131 overlay_depth_ps_.init();
139 taa_accumulation_tx_.free();
140 sample0_depth_tx_.free();
146 smaa_mix_factor_ = 1.0f -
clamp_f(scene_state.
sample / 4.0f, 0.0f, 1.0f);
155 taa_accumulation_ps_.init();
156 taa_accumulation_ps_.state_set(scene_state.
sample == 0 ?
160 taa_accumulation_ps_.bind_texture(
"colorBuffer", &resources.
color_tx);
161 taa_accumulation_ps_.push_constant(
"samplesWeights", weights_, 9);
164 smaa_edge_detect_ps_.init();
167 smaa_edge_detect_ps_.bind_texture(
"colorTex", &taa_accumulation_tx_);
168 smaa_edge_detect_ps_.push_constant(
"viewportMetrics", &smaa_viewport_metrics_, 1);
169 smaa_edge_detect_ps_.clear_color(
float4(0.0f));
172 smaa_aa_weight_ps_.init();
175 smaa_aa_weight_ps_.bind_texture(
"edgesTex", &smaa_edge_tx_);
176 smaa_aa_weight_ps_.bind_texture(
"areaTex", smaa_area_tx_);
177 smaa_aa_weight_ps_.bind_texture(
"searchTex", smaa_search_tx_);
178 smaa_aa_weight_ps_.push_constant(
"viewportMetrics", &smaa_viewport_metrics_, 1);
179 smaa_aa_weight_ps_.clear_color(
float4(0.0f));
182 smaa_resolve_ps_.init();
185 smaa_resolve_ps_.bind_texture(
"blendTex", &smaa_weight_tx_);
186 smaa_resolve_ps_.bind_texture(
"colorTex", &taa_accumulation_tx_);
187 smaa_resolve_ps_.push_constant(
"viewportMetrics", &smaa_viewport_metrics_, 1);
188 smaa_resolve_ps_.push_constant(
"mixFactor", &smaa_mix_factor_, 1);
189 smaa_resolve_ps_.push_constant(
"taaAccumulatedWeight", &weight_accum_, 1);
190 smaa_resolve_ps_.clear_color(
float4(0.0f));
206 sample_offset = taa_samples.
x5[scene_state.
sample];
209 sample_offset = taa_samples.
x8[scene_state.
sample];
212 sample_offset = taa_samples.
x11[scene_state.
sample];
215 sample_offset = taa_samples.
x16[scene_state.
sample];
218 sample_offset = taa_samples.
x32[scene_state.
sample];
237 view.sync(viewmat, winmat);
244 GPUTexture *depth_in_front_tx)
248 overlay_depth_fb_.bind();
249 manager.
submit(overlay_depth_ps_);
259 if (scene_state.
sample == 0) {
262 sample0_depth_in_front_tx_.ensure_2d(
267 sample0_depth_in_front_tx_.free();
273 if (sample0_depth_in_front_tx_.is_valid()) {
286 if (scene_state.
sample == 0) {
291 taa_accumulation_fb_.bind();
293 weight_accum_ += weights_sum_;
297 smaa_weight_tx_.acquire(scene_state.
resolution,
306 if (smaa_mix_factor_ > 0.0f) {
308 smaa_edge_fb_.bind();
312 smaa_weight_fb_.bind();
316 smaa_resolve_fb_.bind();
320 smaa_edge_tx_.release();
321 smaa_weight_tx_.release();
void BLI_jitter_init(float(*jitarr)[2], int num)
MINLINE float clamp_f(float value, float min, float max)
void window_translate_m4(float winmat[4][4], float perspmat[4][4], float x, float y)
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
const unsigned char searchTexBytes[]
const unsigned char areaTexBytes[]
#define GPU_ATTACHMENT_TEXTURE(_texture)
#define GPU_ATTACHMENT_NONE
void GPU_texture_copy(GPUTexture *dst, GPUTexture *src)
@ GPU_TEXTURE_USAGE_SHADER_READ
@ GPU_TEXTURE_USAGE_ATTACHMENT
void GPU_texture_filter_mode(GPUTexture *texture, bool use_filter)
void GPU_texture_update(GPUTexture *texture, eGPUDataFormat data_format, const void *data)
constexpr int64_t size() const
constexpr T * data() const
constexpr IndexRange index_range() const
void submit(PassSimple &pass, View &view)
void setup_view(View &view, const SceneState &scene_state)
void init(const SceneState &scene_state)
void draw(Manager &manager, View &view, const SceneState &scene_state, SceneResources &resources, GPUTexture *depth_in_front_tx)
void sync(const SceneState &scene_state, SceneResources &resources)
static ShaderCache & get()
std::array< float2, 16 > x16
std::array< float2, 8 > x8
std::array< float2, 5 > x5
std::array< float2, 11 > x11
std::array< float2, 32 > x32
bool DRW_state_is_image_render()
bool DRW_state_is_scene_render()
const DRWView * DRW_view_default_get()
void DRW_view_persmat_get(const DRWView *view, float mat[4][4], bool inverse)
void DRW_view_winmat_get(const DRWView *view, float mat[4][4], bool inverse)
void DRW_view_viewmat_get(const DRWView *view, float mat[4][4], bool inverse)
@ DRW_STATE_STENCIL_EQUAL
@ DRW_STATE_BLEND_ADD_FULL
RAYTRACE_GROUP_SIZE additional_info("eevee_shared", "eevee_gbuffer_data", "eevee_global_ubo", "eevee_sampling_data", "eevee_utility_texture", "eevee_hiz_data", "draw_view") .specialization_constant(Type RAYTRACE_GROUP_SIZE in_sh_0_tx in_sh_2_tx screen_normal_tx GPU_RGBA8
T length_squared(const VecBase< T, Size > &a)
T cos(const AngleRadianBase< T > &a)
static float filter_blackman_harris(float x, const float width)
static void setup_taa_weights(const float2 offset, float r_weights[9], float &r_weight_sum)
static const TaaSamples & get_taa_samples()
MatBase< float, 4, 4 > float4x4
VecBase< float, 4 > float4
VecBase< float, 2 > float2
const c_style_mat & ptr() const
TextureRef depth_in_front_tx