Advanced search tips: use spaces to require multiple terms (AND), | for alternatives (OR), wrap phrases in quotes (="a b"), =term for exact match, 'term to include, !term to exclude, ^term to match prefix, !^term to exclude prefix, .ext$ to match suffix, and !.ext$ to exclude suffix.

smaa.wgsl

Constants

SMAA_THRESHOLD

#
const SMAA_THRESHOLD: f32 = 0.15

SMAA_MAX_SEARCH_STEPS

#
const SMAA_MAX_SEARCH_STEPS: u32 = 4u

SMAA_THRESHOLD

#
const SMAA_THRESHOLD: f32 = 0.1

SMAA_MAX_SEARCH_STEPS

#
const SMAA_MAX_SEARCH_STEPS: u32 = 8u

SMAA_THRESHOLD

#
const SMAA_THRESHOLD: f32 = 0.1

SMAA_MAX_SEARCH_STEPS

#
const SMAA_MAX_SEARCH_STEPS: u32 = 16u

SMAA_MAX_SEARCH_STEPS_DIAG

#
const SMAA_MAX_SEARCH_STEPS_DIAG: u32 = 8u

SMAA_CORNER_ROUNDING

#
const SMAA_CORNER_ROUNDING: u32 = 25u

SMAA_THRESHOLD

#
const SMAA_THRESHOLD: f32 = 0.05

SMAA_MAX_SEARCH_STEPS

#
const SMAA_MAX_SEARCH_STEPS: u32 = 32u

SMAA_MAX_SEARCH_STEPS_DIAG

#
const SMAA_MAX_SEARCH_STEPS_DIAG: u32 = 16u

SMAA_CORNER_ROUNDING

#
const SMAA_CORNER_ROUNDING: u32 = 25u

SMAA_THRESHOLD

#
const SMAA_THRESHOLD: f32 = 0.1

SMAA_MAX_SEARCH_STEPS

#
const SMAA_MAX_SEARCH_STEPS: u32 = 16u

SMAA_MAX_SEARCH_STEPS_DIAG

#
const SMAA_MAX_SEARCH_STEPS_DIAG: u32 = 8u

SMAA_CORNER_ROUNDING

#
const SMAA_CORNER_ROUNDING: u32 = 25u

SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR

#
const SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR: f32 = 2.0

SMAA_AREATEX_MAX_DISTANCE

#
const SMAA_AREATEX_MAX_DISTANCE: f32 = 16.0

SMAA_AREATEX_MAX_DISTANCE_DIAG

#
const SMAA_AREATEX_MAX_DISTANCE_DIAG: f32 = 20.0

SMAA_AREATEX_PIXEL_SIZE

#
const SMAA_AREATEX_PIXEL_SIZE: vec2<f32> = (1.0 / vec2<f32>(160.0, 560.0))

SMAA_AREATEX_SUBTEX_SIZE

#
const SMAA_AREATEX_SUBTEX_SIZE: f32 = (1.0 / 7.0)

SMAA_SEARCHTEX_SIZE

#
const SMAA_SEARCHTEX_SIZE: vec2<f32> = vec2(66.0, 33.0)

SMAA_SEARCHTEX_PACKED_SIZE

#
const SMAA_SEARCHTEX_PACKED_SIZE: vec2<f32> = vec2(64.0, 16.0)

SMAA_CORNER_ROUNDING_NORM

#
const SMAA_CORNER_ROUNDING_NORM: f32 = f32(SMAA_CORNER_ROUNDING) / 100.0

Bindings

color_texture

#
@group(0)
@binding(0)
var color_texture: texture_2d<f32>

smaa_info

#
@group(0)
@binding(1)
var<uniform> smaa_info: SmaaInfo

color_sampler

#

Shader defs requirments:

🟢 SMAA_EDGE_DETECTION

@group(1)
@binding(0)
var color_sampler: sampler

edges_texture

#

Shader defs requirments:

🟢 SMAA_BLENDING_WEIGHT_CALCULATION

@group(1)
@binding(0)
var edges_texture: texture_2d<f32>

edges_sampler

#

Shader defs requirments:

🟢 SMAA_BLENDING_WEIGHT_CALCULATION

@group(1)
@binding(1)
var edges_sampler: sampler

search_texture

#

Shader defs requirments:

🟢 SMAA_BLENDING_WEIGHT_CALCULATION

@group(1)
@binding(2)
var search_texture: texture_2d<f32>

area_texture

#

Shader defs requirments:

🟢 SMAA_BLENDING_WEIGHT_CALCULATION

@group(1)
@binding(3)
var area_texture: texture_2d<f32>

blend_texture

#

Shader defs requirments:

🟢 SMAA_NEIGHBORHOOD_BLENDING

@group(1)
@binding(0)
var blend_texture: texture_2d<f32>

blend_sampler

#

Shader defs requirments:

🟢 SMAA_NEIGHBORHOOD_BLENDING

@group(1)
@binding(1)
var blend_sampler: sampler

Structures

SmaaInfo

#
struct SmaaInfo {
rt_metrics: vec4<f32> ,
}

VertexVaryings

#
struct VertexVaryings {
clip_coord: vec2<f32> ,
tex_coord: vec2<f32> ,
}

EdgeDetectionVaryings

#
struct EdgeDetectionVaryings {
@builtin(position)
position: vec4<f32> ,
@location(0)
offset_0: vec4<f32> ,
@location(1)
offset_1: vec4<f32> ,
@location(2)
offset_2: vec4<f32> ,
@location(3)
tex_coord: vec2<f32> ,
}

BlendingWeightCalculationVaryings

#
struct BlendingWeightCalculationVaryings {
@builtin(position)
position: vec4<f32> ,
@location(0)
offset_0: vec4<f32> ,
@location(1)
offset_1: vec4<f32> ,
@location(2)
offset_2: vec4<f32> ,
@location(3)
tex_coord: vec2<f32> ,
}

NeighborhoodBlendingVaryings

#
struct NeighborhoodBlendingVaryings {
@builtin(position)
position: vec4<f32> ,
@location(0)
offset: vec4<f32> ,
@location(1)
tex_coord: vec2<f32> ,
}

Functions

calculate_vertex_varyings

#

The top-left has UV 0,0, the bottom-left has 0,2, and the top-right has 2,0. This means that the UV gets interpolated to 1,1 at the bottom-right corner of the clip-space rectangle that is at 1,-1 in clip space.

fn calculate_vertex_varyings (
vertex_index: u32
) -> VertexVaryings

edge_detection_vertex_main

#
@vertex
Processes each 3D point in a model before it's drawn

Shader defs requirments:

🟢 SMAA_EDGE_DETECTION

* Edge Detection Vertex Shader

fn edge_detection_vertex_main (
@builtin(vertex_index)
vertex_index: u32
) -> EdgeDetectionVaryings

blending_weight_calculation_vertex_main

#
@vertex
Processes each 3D point in a model before it's drawn

Shader defs requirments:

🟢 SMAA_BLENDING_WEIGHT_CALCULATION

* Blend Weight Calculation Vertex Shader

fn blending_weight_calculation_vertex_main (
@builtin(vertex_index)
vertex_index: u32
) -> BlendingWeightCalculationVaryings

neighborhood_blending_vertex_main

#
@vertex
Processes each 3D point in a model before it's drawn

Shader defs requirments:

🟢 SMAA_NEIGHBORHOOD_BLENDING

* Neighborhood Blending Vertex Shader

fn neighborhood_blending_vertex_main (
@builtin(vertex_index)
vertex_index: u32
) -> NeighborhoodBlendingVaryings

luma_edge_detection_fragment_main

#
@fragment
Calculates the final color of each pixel on the screen

Shader defs requirments:

🟢 SMAA_EDGE_DETECTION

* Luma Edge Detection

IMPORTANT NOTICE: luma edge detection requires gamma-corrected colors, and thus ‘color_texture’ should be a non-sRGB texture.

fn luma_edge_detection_fragment_main ( ) ->
@location(0)
vec4<f32>

decode_diag_bilinear_access_2

#

Shader defs requirments:

🟢 SMAA_BLENDING_WEIGHT_CALCULATION

* Allows to decode two binary values from a bilinear-filtered access.

fn decode_diag_bilinear_access_2 ( ) -> vec2<f32>

decode_diag_bilinear_access_4

#

Shader defs requirments:

🟢 SMAA_BLENDING_WEIGHT_CALCULATION

fn decode_diag_bilinear_access_4 ( ) -> vec4<f32>

search_diag_1

#

Shader defs requirments:

🟢 SMAA_BLENDING_WEIGHT_CALCULATION

* These functions allows to perform diagonal pattern searches.

fn search_diag_1 (
tex_coord: vec2<f32>
) -> vec2<f32>

search_diag_2

#

Shader defs requirments:

🟢 SMAA_BLENDING_WEIGHT_CALCULATION

fn search_diag_2 (
tex_coord: vec2<f32>
) -> vec2<f32>

area_diag

#

Shader defs requirments:

🟢 SMAA_BLENDING_WEIGHT_CALCULATION

* Similar to SMAAArea, this calculates the area corresponding to a certain diagonal distance and crossing edges ‘e’.

fn area_diag (
offset: f32
) -> vec2<f32>

calculate_diag_weights

#

Shader defs requirments:

🟢 SMAA_BLENDING_WEIGHT_CALCULATION

* This searches for diagonal patterns and returns the corresponding weights.

fn calculate_diag_weights (
tex_coord: vec2<f32>
subsample_indices: vec4<f32>
) -> vec2<f32>

search_length

#

* This allows to determine how much length should we add in the last step of the searches. It takes the bilinearly interpolated edge (see @PSEUDO_GATHER4), and adds 0, 1 or 2, depending on which edges and crossing edges are active.

fn search_length (
offset: f32
) -> f32

search_x_left

#

* Horizontal/vertical search functions for the 2nd pass.

fn search_x_left (
in_tex_coord: vec2<f32>
end: f32
) -> f32

search_x_right

#
fn search_x_right (
in_tex_coord: vec2<f32>
end: f32
) -> f32

search_y_up

#
fn search_y_up (
in_tex_coord: vec2<f32>
end: f32
) -> f32

search_y_down

#
fn search_y_down (
in_tex_coord: vec2<f32>
end: f32
) -> f32

area

#

* Ok, we have the distance and both crossing edges. So, what are the areas at each side of current edge?

fn area (
offset: f32
) -> vec2<f32>

detect_horizontal_corner_pattern

#
fn detect_horizontal_corner_pattern (
weights: vec2<f32>
tex_coord: vec4<f32>
) -> vec2<f32>

detect_vertical_corner_pattern

#
fn detect_vertical_corner_pattern (
weights: vec2<f32>
tex_coord: vec4<f32>
) -> vec2<f32>

blending_weight_calculation_fragment_main

#
@fragment
Calculates the final color of each pixel on the screen
fn blending_weight_calculation_fragment_main ( ) ->
@location(0)
vec4<f32>

neighborhood_blending_fragment_main

#
@fragment
Calculates the final color of each pixel on the screen

Shader defs requirments:

🟢 SMAA_NEIGHBORHOOD_BLENDING

fn neighborhood_blending_fragment_main ( ) ->
@location(0)
vec4<f32>