Back home ๐Ÿก WGSL Spec Bevy WGSL Functions

smaa.wgsl

Constants

Name Type Value Shader Def
SMAA_THRESHOLD # f32 0.15 ๐ŸŸข SMAA_PRESET_LOW
SMAA_MAX_SEARCH_STEPS # u32 4u ๐ŸŸข SMAA_PRESET_LOW
SMAA_THRESHOLD # f32 0.1 ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_MAX_SEARCH_STEPS # u32 8u ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_THRESHOLD # f32 0.1 ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_MAX_SEARCH_STEPS # u32 16u ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_MAX_SEARCH_STEPS_DIAG # u32 8u ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_CORNER_ROUNDING # u32 25u ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_THRESHOLD # f32 0.05 ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_MAX_SEARCH_STEPS # u32 32u ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_MAX_SEARCH_STEPS_DIAG # u32 16u ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_CORNER_ROUNDING # u32 25u ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_THRESHOLD # f32 0.1 ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_MAX_SEARCH_STEPS # u32 16u ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_MAX_SEARCH_STEPS_DIAG # u32 8u ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_CORNER_ROUNDING # u32 25u ๐Ÿ”ด SMAA_PRESET_LOW
SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR # f32 2.0
SMAA_AREATEX_MAX_DISTANCE # f32 16.0
SMAA_AREATEX_MAX_DISTANCE_DIAG # f32 20.0
SMAA_AREATEX_PIXEL_SIZE # vec2<f32> (1.0 / vec2<f32>(160.0, 560.0))
SMAA_AREATEX_SUBTEX_SIZE # f32 (1.0 / 7.0)
SMAA_SEARCHTEX_SIZE # vec2<f32> vec2(66.0, 33.0)
SMAA_SEARCHTEX_PACKED_SIZE # vec2<f32> vec2(64.0, 16.0)
SMAA_CORNER_ROUNDING_NORM # f32 f32(SMAA_CORNER_ROUNDING) / 100.0

Bindings

Name Group Binding index Binding type Type Shader Def
color_texture # 0 0 texture_2d<f32>
smaa_info # 0 1 <uniform> SmaaInfo
color_sampler # 1 0 sampler ๐ŸŸข SMAA_EDGE_DETECTION
edges_texture # 1 0 texture_2d<f32> ๐ŸŸข SMAA_BLENDING_WEIGHT_CALCULATION
edges_sampler # 1 1 sampler ๐ŸŸข SMAA_BLENDING_WEIGHT_CALCULATION
search_texture # 1 2 texture_2d<f32> ๐ŸŸข SMAA_BLENDING_WEIGHT_CALCULATION
area_texture # 1 3 texture_2d<f32> ๐ŸŸข SMAA_BLENDING_WEIGHT_CALCULATION
blend_texture # 1 0 texture_2d<f32> ๐ŸŸข SMAA_NEIGHBORHOOD_BLENDING
blend_sampler # 1 1 sampler ๐ŸŸข SMAA_NEIGHBORHOOD_BLENDING

Structures

SmaaInfo

#
Name Type
rt_metrics vec4<f32>

VertexVaryings

#
Name Type
clip_coord vec2<f32>
tex_coord vec2<f32>

EdgeDetectionVaryings

#
Annotation Name Type
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

#
Annotation Name Type
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

#
Annotation Name Type
builtin(position) position vec4<f32>
location(0) offset vec4<f32>
location(1) tex_coord vec2<f32>

Functions

calculate_vertex_varyings

#
This vertex shader produces the following, when drawn using indices 0..3: 1 | 0-----x.....2 0 | | s | . ยด -1 | x_____xยด -2 | : .ยด -3 | 1ยด +--------------- -1 0 1 2 3 The axes are clip-space x and y. The region marked s is the visible region. The digits in the corners of the right-angled triangle are the vertex indices. 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
Parameter Type
vertex_index u32
Returns: VertexVaryings

edge_detection_vertex_main

#
@vertex

Shader defs:

๐ŸŸข SMAA_EDGE_DETECTION

* Edge Detection Vertex Shader
fn edge_detection_vertex_main(vertex_index: u32) -> EdgeDetectionVaryings
Parameter Type
vertex_index u32
Returns: EdgeDetectionVaryings

blending_weight_calculation_vertex_main

#
@vertex

Shader defs:

๐ŸŸข SMAA_BLENDING_WEIGHT_CALCULATION

* Blend Weight Calculation Vertex Shader
fn blending_weight_calculation_vertex_main(vertex_index: u32) -> BlendingWeightCalculationVaryings
Parameter Type
vertex_index u32
Returns: BlendingWeightCalculationVaryings

neighborhood_blending_vertex_main

#
@vertex

Shader defs:

๐ŸŸข SMAA_NEIGHBORHOOD_BLENDING

* Neighborhood Blending Vertex Shader
fn neighborhood_blending_vertex_main(vertex_index: u32) -> NeighborhoodBlendingVaryings
Parameter Type
vertex_index u32
Returns: NeighborhoodBlendingVaryings

luma_edge_detection_fragment_main

#
@fragment

Shader defs:

๐ŸŸข 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(in: EdgeDetectionVaryings) -> @location(0) vec4<f32>
Parameter Type
in EdgeDetectionVaryings
Returns: @location(0) vec4<f32>

decode_diag_bilinear_access_2

#

Shader defs:

๐ŸŸข SMAA_BLENDING_WEIGHT_CALCULATION

* Allows to decode two binary values from a bilinear-filtered access.
fn decode_diag_bilinear_access_2(in_e: vec2<f32>) -> vec2<f32>
Parameter Type
in_e vec2<f32>
Returns: vec2<f32>

decode_diag_bilinear_access_4

#

Shader defs:

๐ŸŸข SMAA_BLENDING_WEIGHT_CALCULATION

fn decode_diag_bilinear_access_4(e: vec4<f32>) -> vec4<f32>
Parameter Type
e vec4<f32>
Returns: vec4<f32>

search_diag_1

#

Shader defs:

๐ŸŸข SMAA_BLENDING_WEIGHT_CALCULATION

* These functions allows to perform diagonal pattern searches.
fn search_diag_1(tex_coord: vec2<f32>, dir: vec2<f32>, e: ptr<function, vec2<f32>>) -> vec2<f32>
Parameter Type
tex_coord vec2<f32>
dir vec2<f32>
e ptr<function, vec2<f32>>
Returns: vec2<f32>

search_diag_2

#

Shader defs:

๐ŸŸข SMAA_BLENDING_WEIGHT_CALCULATION

fn search_diag_2(tex_coord: vec2<f32>, dir: vec2<f32>, e: ptr<function, vec2<f32>>) -> vec2<f32>
Parameter Type
tex_coord vec2<f32>
dir vec2<f32>
e ptr<function, vec2<f32>>
Returns: vec2<f32>

area_diag

#

Shader defs:

๐ŸŸข SMAA_BLENDING_WEIGHT_CALCULATION

* Similar to SMAAArea, this calculates the area corresponding to a certain diagonal distance and crossing edges 'e'.
fn area_diag(dist: vec2<f32>, e: vec2<f32>, offset: f32) -> vec2<f32>
Parameter Type
dist vec2<f32>
e vec2<f32>
offset f32
Returns: vec2<f32>

calculate_diag_weights

#

Shader defs:

๐ŸŸข SMAA_BLENDING_WEIGHT_CALCULATION

* This searches for diagonal patterns and returns the corresponding weights.
fn calculate_diag_weights(tex_coord: vec2<f32>, e: vec2<f32>, subsample_indices: vec4<f32>) -> vec2<f32>
Parameter Type
tex_coord vec2<f32>
e vec2<f32>
subsample_indices vec4<f32>
Returns: vec2<f32>

search_length

#
fn search_length(e: vec2<f32>, offset: f32) -> f32
Parameter Type
e vec2<f32>
offset f32
Returns: f32

search_x_left

#
* Horizontal/vertical search functions for the 2nd pass.
fn search_x_left(in_tex_coord: vec2<f32>, end: f32) -> f32
Parameter Type
in_tex_coord vec2<f32>
end f32
Returns: f32

search_x_right

#
fn search_x_right(in_tex_coord: vec2<f32>, end: f32) -> f32
Parameter Type
in_tex_coord vec2<f32>
end f32
Returns: f32

search_y_up

#
fn search_y_up(in_tex_coord: vec2<f32>, end: f32) -> f32
Parameter Type
in_tex_coord vec2<f32>
end f32
Returns: f32

search_y_down

#
fn search_y_down(in_tex_coord: vec2<f32>, end: f32) -> f32
Parameter Type
in_tex_coord vec2<f32>
end f32
Returns: f32

area

#
* Ok, we have the distance and both crossing edges. So, what are the areas at each side of current edge?
fn area(dist: vec2<f32>, e1: f32, e2: f32, offset: f32) -> vec2<f32>
Parameter Type
dist vec2<f32>
e1 f32
e2 f32
offset f32
Returns: vec2<f32>

detect_horizontal_corner_pattern

#
fn detect_horizontal_corner_pattern(weights: vec2<f32>, tex_coord: vec4<f32>, d: vec2<f32>) -> vec2<f32>
Parameter Type
weights vec2<f32>
tex_coord vec4<f32>
d vec2<f32>
Returns: vec2<f32>

detect_vertical_corner_pattern

#
fn detect_vertical_corner_pattern(weights: vec2<f32>, tex_coord: vec4<f32>, d: vec2<f32>) -> vec2<f32>
Parameter Type
weights vec2<f32>
tex_coord vec4<f32>
d vec2<f32>
Returns: vec2<f32>

blending_weight_calculation_fragment_main

#
@fragment
fn blending_weight_calculation_fragment_main(in: BlendingWeightCalculationVaryings) -> @location(0) vec4<f32>
Parameter Type
in BlendingWeightCalculationVaryings
Returns: @location(0) vec4<f32>

neighborhood_blending_fragment_main

#
@fragment

Shader defs:

๐ŸŸข SMAA_NEIGHBORHOOD_BLENDING

fn neighborhood_blending_fragment_main(in: NeighborhoodBlendingVaryings) -> @location(0) vec4<f32>
Parameter Type
in NeighborhoodBlendingVaryings
Returns: @location(0) vec4<f32>