290#define SMAA_CUSTOM_SL
291#define SMAA_AREATEX_SELECT(sample) sample.xy()
292#define SMAA_SEARCHTEX_SELECT(sample) sample.x
293#define SMAATexture2D(tex) const MemoryBuffer *tex
294#define SMAATexturePass2D(tex) tex
295#define SMAASampleLevelZero(tex, coord) tex->texture_bilinear_extend(coord)
296#define SMAASampleLevelZeroPoint(tex, coord) tex->texture_bilinear_extend(coord)
297#define SMAASampleLevelZeroOffset(tex, coord, offset, size) \
298 tex->texture_bilinear_extend(coord + float2(offset) / float2(size))
299#define SMAASample(tex, coord) tex->texture_bilinear_extend(coord)
300#define SMAASamplePoint(tex, coord) tex->texture_nearest_extend(coord)
301#define SMAASamplePointOffset(tex, coord, offset, size) \
302 tex->texture_nearest_extend(coord + float2(offset) / float2(size))
303#define SMAASampleOffset(tex, coord, offset, size) \
304 tex->texture_bilinear_extend(coord + float2(offset) / float2(size))
307#define lerp(a, b, t) math::interpolate(a, b, t)
308#define saturate(a) math::clamp(a, 0.0f, 1.0f)
309#define mad(a, b, c) (a * b + c)
319#if defined(SMAA_PRESET_LOW)
320# define SMAA_THRESHOLD 0.15f
321# define SMAA_MAX_SEARCH_STEPS 4
322# define SMAA_DISABLE_DIAG_DETECTION
323# define SMAA_DISABLE_CORNER_DETECTION
324#elif defined(SMAA_PRESET_MEDIUM)
325# define SMAA_THRESHOLD 0.1f
326# define SMAA_MAX_SEARCH_STEPS 8
327# define SMAA_DISABLE_DIAG_DETECTION
328# define SMAA_DISABLE_CORNER_DETECTION
329#elif defined(SMAA_PRESET_HIGH)
330# define SMAA_THRESHOLD 0.1f
331# define SMAA_MAX_SEARCH_STEPS 16
332# define SMAA_MAX_SEARCH_STEPS_DIAG 8
333# define SMAA_CORNER_ROUNDING 25
334#elif defined(SMAA_PRESET_ULTRA)
335# define SMAA_THRESHOLD 0.05f
336# define SMAA_MAX_SEARCH_STEPS 32
337# define SMAA_MAX_SEARCH_STEPS_DIAG 16
338# define SMAA_CORNER_ROUNDING 25
356#ifndef SMAA_THRESHOLD
357# define SMAA_THRESHOLD 0.1f
365#ifndef SMAA_DEPTH_THRESHOLD
366# define SMAA_DEPTH_THRESHOLD (0.1f * SMAA_THRESHOLD)
379#ifndef SMAA_MAX_SEARCH_STEPS
380# define SMAA_MAX_SEARCH_STEPS 16
395#ifndef SMAA_MAX_SEARCH_STEPS_DIAG
396# define SMAA_MAX_SEARCH_STEPS_DIAG 8
406#ifndef SMAA_CORNER_ROUNDING
407# define SMAA_CORNER_ROUNDING 25
418#ifndef SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR
419# define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0f
436#ifndef SMAA_PREDICATION
437# define SMAA_PREDICATION 0
446#ifndef SMAA_PREDICATION_THRESHOLD
447# define SMAA_PREDICATION_THRESHOLD 0.01f
456#ifndef SMAA_PREDICATION_SCALE
457# define SMAA_PREDICATION_SCALE 2.0f
465#ifndef SMAA_PREDICATION_STRENGTH
466# define SMAA_PREDICATION_STRENGTH 0.4f
480#ifndef SMAA_REPROJECTION
481# define SMAA_REPROJECTION 0
495#ifndef SMAA_REPROJECTION_WEIGHT_SCALE
496# define SMAA_REPROJECTION_WEIGHT_SCALE 30.0f
503#ifndef SMAA_INCLUDE_VS
504# define SMAA_INCLUDE_VS 1
506#ifndef SMAA_INCLUDE_PS
507# define SMAA_INCLUDE_PS 1
513#ifndef SMAA_AREATEX_SELECT
514# if defined(SMAA_HLSL_3)
515# define SMAA_AREATEX_SELECT(sample) sample.ra
517# define SMAA_AREATEX_SELECT(sample) sample.rg
521#ifndef SMAA_SEARCHTEX_SELECT
522# define SMAA_SEARCHTEX_SELECT(sample) sample.r
525#ifndef SMAA_DECODE_VELOCITY
526# define SMAA_DECODE_VELOCITY(sample) sample.rg
532#define SMAA_AREATEX_MAX_DISTANCE 16
533#define SMAA_AREATEX_MAX_DISTANCE_DIAG 20
534#define SMAA_AREATEX_PIXEL_SIZE (1.0f / float2(160.0f, 560.0f))
535#define SMAA_AREATEX_SUBTEX_SIZE (1.0f / 7.0f)
536#define SMAA_SEARCHTEX_SIZE float2(66.0f, 33.0f)
537#define SMAA_SEARCHTEX_PACKED_SIZE float2(64.0f, 16.0f)
538#define SMAA_CORNER_ROUNDING_NORM (float(SMAA_CORNER_ROUNDING) / 100.0f)
543#if defined(SMAA_HLSL_3)
544# define SMAATexture2D(tex) sampler2D tex
545# define SMAATexturePass2D(tex) tex
546# define SMAASampleLevelZero(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0))
547# define SMAASampleLevelZeroPoint(tex, coord) tex2Dlod(tex, float4(coord, 0.0, 0.0))
549# define SMAASampleLevelZeroOffset(tex, coord, offset) tex2Dlod(tex, float4(coord + offset * SMAA_RT_METRICS.xy, 0.0, 0.0))
551# define SMAASample(tex, coord) tex2D(tex, coord)
552# define SMAASamplePoint(tex, coord) tex2D(tex, coord)
553# define SMAASampleOffset(tex, coord, offset) tex2D(tex, coord + offset * SMAA_RT_METRICS.xy)
554# define SMAA_FLATTEN [flatten]
555# define SMAA_BRANCH [branch]
557#if defined(SMAA_HLSL_4) || defined(SMAA_HLSL_4_1)
558SamplerState LinearSampler
560 Filter = MIN_MAG_LINEAR_MIP_POINT;
564SamplerState PointSampler
566 Filter = MIN_MAG_MIP_POINT;
570# define SMAATexture2D(tex) Texture2D tex
571# define SMAATexturePass2D(tex) tex
572# define SMAASampleLevelZero(tex, coord) tex.SampleLevel(LinearSampler, coord, 0)
573# define SMAASampleLevelZeroPoint(tex, coord) tex.SampleLevel(PointSampler, coord, 0)
575# define SMAASampleLevelZeroOffset(tex, coord, offset) tex.SampleLevel(LinearSampler, coord, 0, offset)
577# define SMAASample(tex, coord) tex.Sample(LinearSampler, coord)
578# define SMAASamplePoint(tex, coord) tex.Sample(PointSampler, coord)
579# define SMAASampleOffset(tex, coord, offset) tex.Sample(LinearSampler, coord, offset)
580# define SMAA_FLATTEN [flatten]
581# define SMAA_BRANCH [branch]
582# define SMAATexture2DMS2(tex) Texture2DMS<float4, 2> tex
583# define SMAALoad(tex, pos, sample) tex.Load(pos, sample)
584# if defined(SMAA_HLSL_4_1)
585# define SMAAGather(tex, coord) tex.Gather(LinearSampler, coord, 0)
588#if defined(SMAA_GLSL_3) || defined(SMAA_GLSL_4) || defined(GPU_METAL) || defined(GPU_VULKAN)
589# define SMAATexture2D(tex) sampler2D tex
590# define SMAATexturePass2D(tex) tex
591# define SMAASampleLevelZero(tex, coord) textureLod(tex, coord, 0.0)
592# define SMAASampleLevelZeroPoint(tex, coord) textureLod(tex, coord, 0.0)
593# define SMAASampleLevelZeroOffset(tex, coord, offset) textureLodOffset(tex, coord, 0.0, offset)
594# define SMAASample(tex, coord) texture(tex, coord)
595# define SMAASamplePoint(tex, coord) texture(tex, coord)
596# define SMAASampleOffset(tex, coord, offset) texture(tex, coord, offset)
599# define lerp(a, b, t) mix(a, b, t)
600# define saturate(a) clamp(a, 0.0, 1.0)
601# if defined(SMAA_GLSL_4)
602# define SMAAGather(tex, coord) textureGather(tex, coord)
604# if defined(SMAA_GLSL_4)
605# define mad(a, b, c) fma(a, b, c)
606# elif defined(GPU_VULKAN)
616vec2
mad(vec2 a, vec2
b, vec2 c)
620float mad(
float a,
float b,
float c)
625# define mad(a, b, c) (a * b + c)
642#if !defined(SMAA_HLSL_3) && !defined(SMAA_HLSL_4) && !defined(SMAA_HLSL_4_1) && !defined(SMAA_GLSL_3) && !defined(SMAA_GLSL_4) && !defined(SMAA_CUSTOM_SL)
643# error you must define the shading language: SMAA_HLSL_*, SMAA_GLSL_* or SMAA_CUSTOM_SL
676 offset[0] =
float4(texcoord.
xy(), texcoord.
xy()) +
678 offset[1] =
float4(texcoord.
xy(), texcoord.
xy()) +
680 offset[2] =
float4(texcoord.
xy(), texcoord.
xy()) +
692 pixcoord = texcoord *
float2(size);
695 offset[0] =
float4(texcoord.
xy(), texcoord.
xy()) +
696 float4(-0.25f, -0.125f, 1.25f, -0.125f) /
float4(size, size);
697 offset[1] =
float4(texcoord.
xy(), texcoord.
xy()) +
698 float4(-0.125f, -0.25f, -0.125f, 1.25f) /
float4(size, size);
701 offset[2] =
float4(offset[0].x, offset[0].
z, offset[1].y, offset[1].
w) +
711 offset =
float4(texcoord, texcoord) +
float4(1.0f, 0.0f, 0.0f, 1.0f) /
float4(size, size);
727 float edge_threshold,
728 float3 luminance_coefficients,
729 float local_contrast_adaptation_factor)
732 float2 threshold = SMAACalculatePredicatedThreshold(
736 float2 threshold =
float2(edge_threshold, edge_threshold);
750 delta.x = delta_left_top.x;
751 delta.y = delta_left_top.y;
763 delta.z = delta_right_bottom.x;
764 delta.w = delta_right_bottom.y;
773 delta.z = delta_left_left_top_top.x;
774 delta.w = delta_left_left_top_top.y;
778 float finalDelta =
math::max(maxDelta.x, maxDelta.y);
781 edges *=
math::step(finalDelta, local_contrast_adaptation_factor * delta.
xy());
789#if !defined(SMAA_DISABLE_DIAG_DETECTION)
831 coord.x = increment.x;
832 coord.y = increment.y;
833 coord.z = increment.z;
844 coord.x += 0.25f / size.x;
848 coord.x = increment.x;
849 coord.y = increment.y;
850 coord.z = increment.z;
906 d.x = negative_diagonal.x;
907 d.z = negative_diagonal.y;
908 d.x +=
float(end.y > 0.9f);
916 d.y = positive_diagonal.x;
917 d.w = positive_diagonal.y;
920 if (d.x + d.y > 2.0f) {
923 float4(-d.x + 0.25f, d.x, d.y, -d.y - 0.25f) /
float4(size, size);
932 c.y = decoded_access.x;
933 c.x = decoded_access.y;
934 c.w = decoded_access.z;
935 c.z = decoded_access.w;
958 d.x = negative_diagonal.x;
959 d.z = negative_diagonal.y;
963 d.y = positive_diagonal.x;
964 d.w = positive_diagonal.y;
965 d.y +=
float(end.y > 0.9f);
973 if (d.x + d.y > 2.0f) {
1014 scale +=
float2(-1.0f, 1.0f);
1015 bias +=
float2(0.5f, -0.5f);
1040 while (texcoord.x > end &&
e.y > 0.8281f &&
1044 texcoord = texcoord -
float2(2.0f, 0.0f) /
float2(size);
1049 return texcoord.x + offset / size.x;
1069 while (texcoord.x < end &&
e.y > 0.8281f &&
1073 texcoord = texcoord +
float2(2.0f, 0.0f) /
float2(size);
1077 return texcoord.x - offset / size.x;
1084 while (texcoord.y > end &&
e.x > 0.8281f &&
1088 texcoord = texcoord -
float2(0.0f, 2.0f) /
float2(size);
1091 float offset =
mad(-(255.0f / 127.0f),
1094 return texcoord.y + offset / size.y;
1101 while (texcoord.y < end &&
e.x > 0.8281f &&
1105 texcoord = texcoord +
float2(0.0f, 2.0f) /
float2(size);
1108 float offset =
mad(-(255.0f / 127.0f),
1111 return texcoord.y - offset / size.y;
1143 int corner_rounding)
1145#if !defined(SMAA_DISABLE_CORNER_DETECTION)
1147 float2 rounding = (1.0f - corner_rounding / 100.0f) * leftRight;
1149 rounding /= leftRight.x + leftRight.y;
1166 int corner_rounding)
1168#if !defined(SMAA_DISABLE_CORNER_DETECTION)
1170 float2 rounding = (1.0f - corner_rounding / 100.0f) * leftRight;
1172 rounding /= leftRight.x + leftRight.y;
1195 int corner_rounding)
1204#if !defined(SMAA_DISABLE_DIAG_DETECTION)
1214 weights.x = diagonal_weights.x;
1215 weights.y = diagonal_weights.y;
1220 if (weights.x == -weights.y) {
1266 coords.y = texcoord.y;
1268 float2 corner_weight = weights.
xy();
1271 float4(coords.
xy(), coords.z, coords.y),
1275 weights.x = corner_weight.x;
1276 weights.y = corner_weight.y;
1278#if !defined(SMAA_DISABLE_DIAG_DETECTION)
1296 coords.x = offset[0].x;
1325 coords.x = texcoord.x;
1327 float2 corner_weight = weights.
zw();
1330 float4(coords.
xy(), coords.x, coords.z),
1334 weights.z = corner_weight.x;
1335 weights.w = corner_weight.y;
1365#if SMAA_REPROJECTION
1385 float4 blendingCoord =
float4(texcoord, texcoord) + blendingOffset /
float4(size, -size);
1391#if SMAA_REPROJECTION
1393 float2 velocity = blendingWeight.x *
1395 velocity += blendingWeight.y *
1414 const rcti &output_area,
1417 r_input_area.
xmax = output_area.
xmax +
1421 r_input_area.
ymax = output_area.
ymax +
1432 if (image->is_a_single_elem()) {
1433 copy_v4_v4(output->get_elem(0, 0), image->get_elem(0, 0));
1437 const int2 size =
int2(image->get_width(), image->get_height());
1440 float3 luminance_coefficients;
1444 for (const int64_t y : sub_y_range) {
1445 for (const int64_t x : IndexRange(size.x)) {
1446 int2 texel = int2(x, y);
1447 float2 coordinates = (float2(texel) + float2(0.5f)) / float2(size);
1450 SMAAEdgeDetectionVS(coordinates, size, offset);
1452 float2 edge = SMAALumaEdgeDetectionPS(coordinates,
1456 luminance_coefficients,
1457 local_contrast_adaptation_factor_);
1458 copy_v2_v2(edges.get_elem(texel.x, texel.y), edge);
1466 area_texture.copy_from(
areaTexBytes, area_texture.get_rect());
1469 search_texture.copy_from(
searchTexBytes, search_texture.get_rect());
1472 for (const int64_t y : sub_y_range) {
1473 for (const int64_t x : IndexRange(size.x)) {
1474 int2 texel = int2(x, y);
1475 float2 coordinates = (float2(texel) + float2(0.5f)) / float2(size);
1478 float2 pixel_coordinates;
1479 SMAABlendingWeightCalculationVS(coordinates, size, pixel_coordinates, offset);
1481 float4 weights = SMAABlendingWeightCalculationPS(coordinates,
1490 copy_v4_v4(blending_weights.get_elem(texel.x, texel.y), weights);
1496 for (const int64_t y : sub_y_range) {
1497 for (const int64_t x : IndexRange(size.x)) {
1498 int2 texel = int2(x, y);
1499 float2 coordinates = (float2(texel) + float2(0.5f)) / float2(size);
1502 SMAANeighborhoodBlendingVS(coordinates, size, offset);
1504 float4 result = SMAANeighborhoodBlendingPS(
1505 coordinates, offset, image, &blending_weights, size);
1506 copy_v4_v4(output->get_elem(texel.x, texel.y), result);
MINLINE void copy_v4_v4(float r[4], const float a[4])
const unsigned char searchTexBytes[]
const unsigned char areaTexBytes[]
#define SMAATexturePass2D(tex)
#define SMAASampleLevelZero(tex, coord)
#define SMAA_AREATEX_MAX_DISTANCE
#define SMAATexture2D(tex)
#define SMAA_AREATEX_MAX_DISTANCE_DIAG
#define SMAASamplePoint(tex, coord)
#define SMAASamplePointOffset(tex, coord, offset, size)
#define SMAA_DECODE_VELOCITY(sample)
#define SMAA_SEARCHTEX_PACKED_SIZE
#define SMAASample(tex, coord)
#define SMAA_SEARCHTEX_SELECT(sample)
#define SMAA_REPROJECTION
#define SMAASampleLevelZeroOffset(tex, coord, offset, size)
#define SMAA_MAX_SEARCH_STEPS
#define SMAA_AREATEX_PIXEL_SIZE
#define SMAA_AREATEX_SELECT(sample)
#define SMAA_MAX_SEARCH_STEPS_DIAG
#define SMAA_SEARCHTEX_SIZE
#define SMAA_AREATEX_SUBTEX_SIZE
BLI_INLINE void IMB_colormanagement_get_luminance_coefficients(float r_rgb[3])
Group Output data from inside of a node group A color picker Mix two input colors RGB to Convert a color s luminance to a grayscale value Generate a normal vector and a dot product Brightness Control the brightness and contrast of the input color Vector Map input vector components with curves Camera Retrieve information about the camera and how it relates to the current shading point s position Clamp
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
SIMD_FORCE_INLINE const btScalar & z() const
Return the z value.
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
a MemoryBuffer contains access to the data
void add_output_socket(DataType datatype)
NodeOperationFlags flags_
void add_input_socket(DataType datatype, ResizeMode resize_mode=ResizeMode::Center)
void update_memory_buffer(MemoryBuffer *output, const rcti &area, Span< MemoryBuffer * > inputs) override
void get_area_of_interest(int input_idx, const rcti &output_area, rcti &r_input_area) override
Get input operation area being read by this operation on rendering given output area.
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
velocity_obj_prev_buf[] vec4
@ Float2
Float2 data type.
static float SMAASearchYUp(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end, int2 size)
static void SMAANeighborhoodBlendingVS(float2 texcoord, int2 size, float4 &offset)
static float2 SMAASearchDiag2(SMAATexture2D(edgesTex), float2 texcoord, float2 dir, int2 size, float2 &e)
static float2 SMAAAreaDiag(SMAATexture2D(areaTex), float2 dist, float2 e, float offset)
static void SMAADetectHorizontalCornerPattern(SMAATexture2D(edgesTex), float2 &weights, float4 texcoord, float2 d, int2 size, int corner_rounding)
static float2 SMAAArea(SMAATexture2D(areaTex), float2 dist, float e1, float e2, float offset)
static void SMAABlendingWeightCalculationVS(float2 texcoord, int2 size, float2 &pixcoord, float4 offset[3])
static float SMAASearchXRight(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end, int2 size)
static float4 SMAABlendingWeightCalculationPS(float2 texcoord, float2 pixcoord, float4 offset[3], MemoryBuffer *edgesTex, MemoryBuffer *areaTex, MemoryBuffer *searchTex, float4 subsampleIndices, int2 size, int corner_rounding)
static float2 SMAASearchDiag1(SMAATexture2D(edgesTex), float2 texcoord, float2 dir, int2 size, float2 &e)
static float2 SMAADecodeDiagBilinearAccess(float2 e)
static float SMAASearchYDown(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end, int2 size)
static void SMAAMovc(float2 cond, float2 &variable, float2 value)
static float SMAASearchLength(SMAATexture2D(searchTex), float2 e, float offset)
static float2 SMAACalculateDiagWeights(SMAATexture2D(edgesTex), SMAATexture2D(areaTex), float2 texcoord, float2 e, float4 subsampleIndices, int2 size)
static float4 SMAANeighborhoodBlendingPS(float2 texcoord, float4 offset, SMAATexture2D(colorTex), SMAATexture2D(blendTex), int2 size)
static void SMAAEdgeDetectionVS(float2 texcoord, int2 size, float4 offset[3])
static float SMAASearchXLeft(SMAATexture2D(edgesTex), SMAATexture2D(searchTex), float2 texcoord, float end, int2 size)
static float2 SMAALumaEdgeDetectionPS(float2 texcoord, float4 offset[3], SMAATexture2D(colorTex), float edge_threshold, float3 luminance_coefficients, float local_contrast_adaptation_factor)
static void SMAADetectVerticalCornerPattern(SMAATexture2D(edgesTex), float2 &weights, float4 texcoord, float2 d, int2 size, int corner_rounding)
T length(const VecBase< T, Size > &a)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
T step(const T &edge, const T &value)
T interpolate(const T &a, const T &b, const FactorT &t)
T max(const T &a, const T &b)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
VecBase< float, 4 > float4
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
VecBase< float, 3 > float3
VecBase< T, 2 > zw() const
VecBase< T, 2 > xy() const
VecBase< T, 3 > xyz() const