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) {
88 x = 2.0f *
M_PI *
clamp_f((x / width + 0.5f), 0.0f, 1.0f);
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;
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();
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);
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);
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);
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) {
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();
292 manager.
submit(taa_accumulation_ps_, view);
293 weight_accum_ += weights_sum_;
306 if (smaa_mix_factor_ > 0.0f) {
308 smaa_edge_fb_.
bind();
309 manager.
submit(smaa_edge_detect_ps_, view);
312 smaa_weight_fb_.
bind();
313 manager.
submit(smaa_aa_weight_ps_, view);
316 smaa_resolve_fb_.
bind();
317 manager.
submit(smaa_resolve_ps_, view);
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 ensure(GPUAttachment depth=GPU_ATTACHMENT_NONE, GPUAttachment color1=GPU_ATTACHMENT_NONE, GPUAttachment color2=GPU_ATTACHMENT_NONE, GPUAttachment color3=GPU_ATTACHMENT_NONE, GPUAttachment color4=GPU_ATTACHMENT_NONE, GPUAttachment color5=GPU_ATTACHMENT_NONE, GPUAttachment color6=GPU_ATTACHMENT_NONE, GPUAttachment color7=GPU_ATTACHMENT_NONE, GPUAttachment color8=GPU_ATTACHMENT_NONE)
void submit(PassSimple &pass, View &view)
void acquire(int2 extent, eGPUTextureFormat format, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL)
bool ensure_2d(eGPUTextureFormat format, int2 extent, eGPUTextureUsage usage=GPU_TEXTURE_USAGE_GENERAL, const float *data=nullptr, int mip_len=1)
void bind_texture(const char *name, GPUTexture *texture, GPUSamplerState state=sampler_auto)
void clear_color(float4 color)
void draw_procedural(GPUPrimType primitive, uint instance_len, uint vertex_len, uint vertex_first=-1, ResourceHandle handle={0}, uint custom_id=0)
void state_set(DRWState state, int clip_plane_count=0)
void state_stencil(uint8_t write_mask, uint8_t reference, uint8_t compare_mask)
void push_constant(const char *name, const float &data)
void shader_set(GPUShader *shader)
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)
StaticShader smaa_aa_weight
StaticShader taa_accumulation
static ShaderCache & get()
StaticShader smaa_resolve
StaticShader smaa_edge_detect
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()
VecBase< float, 4 > float4
VecBase< float, 2 > float2
const c_style_mat & ptr() const
TextureRef depth_in_front_tx