|
Blender V4.3
|
#include "BLI_math_vector.h"#include "BLI_math_vector.hh"#include "BLI_smaa_textures.h"#include "BLI_span.hh"#include "BLI_task.hh"#include "IMB_colormanagement.hh"#include "COM_MemoryBuffer.h"#include "COM_SMAAOperation.h"Go to the source code of this file.
Namespaces | |
| namespace | blender |
| namespace | blender::compositor |
Definition at line 307 of file COM_SMAAOperation.cc.
Referenced by btSoftBodyHelpers::CreatePatch(), btSoftBodyHelpers::CreatePatchUV(), btSoftBodyHelpers::CreateRope(), debugDrawPhase(), newPerlin(), and noise3_perlin().
Definition at line 309 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAAArea(), blender::compositor::SMAAAreaDiag(), blender::compositor::SMAABlendingWeightCalculationPS(), blender::compositor::SMAACalculateDiagWeights(), blender::compositor::SMAASearchDiag1(), blender::compositor::SMAASearchDiag2(), blender::compositor::SMAASearchLength(), blender::compositor::SMAASearchXLeft(), blender::compositor::SMAASearchXRight(), blender::compositor::SMAASearchYDown(), and blender::compositor::SMAASearchYUp().
| #define saturate | ( | a | ) | math::clamp(a, 0.0f, 1.0f) |
Definition at line 308 of file COM_SMAAOperation.cc.
Referenced by bsdf_microfacet_setup_fresnel_conductor(), bsdf_microfacet_setup_fresnel_generalized_schlick(), bsdf_oren_nayar_setup(), MixVectorNonUniformNode::constant_fold(), blender::eevee::film_filter_weight(), fresnel_iridescence(), microfacet_fresnel(), blender::compositor::SMAADetectHorizontalCornerPattern(), blender::compositor::SMAADetectVerticalCornerPattern(), surface_shader_alpha(), svm_mix_clamp(), svm_node_closure_bsdf(), svm_node_mix_color(), and svm_node_mix_vector_non_uniform().
| #define SMAA_AREATEX_MAX_DISTANCE 16 |
Definition at line 532 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAAArea().
| #define SMAA_AREATEX_MAX_DISTANCE_DIAG 20 |
Definition at line 533 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAAAreaDiag().
Definition at line 534 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAAArea(), and blender::compositor::SMAAAreaDiag().
Definition at line 291 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAAArea(), and blender::compositor::SMAAAreaDiag().
| #define SMAA_AREATEX_SUBTEX_SIZE (1.0f / 7.0f) |
Definition at line 535 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAAArea(), and blender::compositor::SMAAAreaDiag().
| #define SMAA_BRANCH |
Definition at line 306 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAABlendingWeightCalculationPS(), blender::compositor::SMAACalculateDiagWeights(), and blender::compositor::SMAANeighborhoodBlendingPS().
| #define SMAA_CORNER_ROUNDING 25 |
SMAA_CORNER_ROUNDING specifies how much sharp corners will be rounded.
Range: [0, 100]
Define SMAA_DISABLE_CORNER_DETECTION to disable corner processing.
Definition at line 407 of file COM_SMAAOperation.cc.
| #define SMAA_CORNER_ROUNDING_NORM (float(SMAA_CORNER_ROUNDING) / 100.0f) |
Definition at line 538 of file COM_SMAAOperation.cc.
| #define SMAA_CUSTOM_SL |
_______ ___ ___ ___ ___
/ || \/ | / \ / \
| (---- | \ / | / ^ \ / ^ \
\ \ | |\/| | / /_\ \ / /_\ \
----) | | | | | / _____ \ / _____ \
|_______/ |__| |__| /__/ \__\ /__/ \__\
E N H A N C E D
S U B P I X E L M O R P H O L O G I C A L A N T I A L I A S I N G
http://www.iryoku.com/smaa/
Hi, welcome aboard!
Here you'll find instructions to get the shader up and running as fast as possible.
IMPORTANTE NOTICE: when updating, remember to update both this file and the precomputed textures! They may change from version to version.
The shader has three passes, chained together as follows:
|input|------------------�
v |
[ SMAA*EdgeDetection ] |
v |
|edgesTex| |
v |
[ SMAABlendingWeightCalculation ] |
v |
|blendTex| |
v |
[ SMAANeighborhoodBlending ] <------�
v
|output|
Note that each [pass] has its own vertex and pixel shader. Remember to use over-sized triangles instead of quads to avoid over-shading along the diagonal.
You've three edge detection methods to choose from: luma, color or depth. They represent different quality/performance and anti-aliasing/sharpness tradeoffs, so our recommendation is for you to choose the one that best suits your particular scenario:
For quick-starters: just use luma edge detection.
The general advice is to not rush the integration process and ensure each step is done correctly (don't try to integrate SMAA T2x with predicated edge detection from the start!). Ok then, let's go!
The first step is to create two RGBA temporal render targets for holding |edgesTex| and |blendTex|.
In DX10 or DX11, you can use a RG render target for the edges texture. In the case of NVIDIA GPUs, using RG render targets seems to actually be slower.
On the Xbox 360, you can use the same render target for resolving both |edgesTex| and |blendTex|, as they aren't needed simultaneously.
The next step is loading the two supporting precalculated textures, 'areaTex' and 'searchTex'. You'll find them in the 'Textures' folder as C++ headers, and also as regular DDS files. They'll be needed for the 'SMAABlendingWeightCalculation' pass.
If you use the C++ headers, be sure to load them in the format specified inside of them.
You can also compress 'areaTex' and 'searchTex' using BC5 and BC4 respectively, if you have that option in your content processor pipeline. When compressing then, you get a non-perceptible quality decrease, and a marginal performance increase.
All samplers must be set to linear filtering and clamp.
After you get the technique working, remember that 64-bit inputs have half-rate linear filtering on GCN.
If SMAA is applied to 64-bit color buffers, switching to point filtering when accessing them will increase the performance. Search for 'SMAASamplePoint' to see which textures may benefit from point filtering, and where (which is basically the color input in the edge detection and resolve passes).
All texture reads and buffer writes must be non-sRGB, with the exception of the input read and the output write in 'SMAANeighborhoodBlending' (and only in this pass!). If sRGB reads in this last pass are not possible, the technique will work anyway, but will perform anti-aliasing in gamma space.
IMPORTANT: for best results the input read for the color/luma edge detection should NOT be sRGB.
Before including SMAA.h you'll have to setup the render target metrics, the target and any optional configuration defines. Optionally you can use a preset.
You have the following targets available: SMAA_HLSL_3 SMAA_HLSL_4 SMAA_HLSL_4_1 SMAA_GLSL_3 * SMAA_GLSL_4 *
And four presets: SMAA_PRESET_LOW (%60 of the quality) SMAA_PRESET_MEDIUM (%80 of the quality) SMAA_PRESET_HIGH (%95 of the quality) SMAA_PRESET_ULTRA (%99 of the quality)
For example: define SMAA_RT_METRICS float4(1.0 / 1280.0, 1.0 / 720.0, 1280.0, 720.0) define SMAA_HLSL_4 define SMAA_PRESET_HIGH #include "SMAA.h"
Note that SMAA_RT_METRICS doesn't need to be a macro, it can be a uniform variable. The code is designed to minimize the impact of not using a constant value, but it is still better to hard-code it.
Depending on how you encoded 'areaTex' and 'searchTex', you may have to add (and customize) the following defines before including SMAA.h: define SMAA_AREATEX_SELECT(sample) sample.rg define SMAA_SEARCHTEX_SELECT(sample) sample.r
If your engine is already using porting macros, you can define SMAA_CUSTOM_SL, and define the porting functions by yourself.
After this point you can choose to enable predicated thresholding, temporal supersampling and motion blur integration:
a) If you want to use predicated thresholding, take a look into SMAA_PREDICATION; you'll need to pass an extra texture in the edge detection pass.
b) If you want to enable temporal supersampling (SMAA T2x):
At this point you should already have something usable, but for best results the proper area textures must be set depending on current jitter. For this, the parameter 'subsampleIndices' of 'SMAABlendingWeightCalculationPS' must be set as follows, for our T2x mode:
@SUBSAMPLE_INDICES
| S# | Camera Jitter | subsampleIndices | +-—+---------------—+------------------—+ | 0 | ( 0.25, -0.25) | float4(1, 1, 1, 0) | | 1 | (-0.25, 0.25) | float4(2, 2, 2, 0) |
These jitter positions assume a bottom-to-top y axis. S# stands for the sample number.
More information about temporal supersampling here: http://iryoku.com/aacourse/downloads/13-Anti-Aliasing-Methods-in-CryENGINE-3.pdf
c) If you want to enable spatial multisampling (SMAA S2x):
The scene must be rendered using MSAA 2x. The MSAA 2x buffer must be created with:
This allows to ensure that the subsample order matches the table in @SUBSAMPLE_INDICES.
(*) In the case of DX10, we refer the reader to:
These functions allow matching the standard multisample patterns by detecting the subsample order for a specific GPU, and reordering them appropriately.
d) If you want to enable temporal supersampling on top of SMAA S2x (which actually is SMAA 4x):
SMAA 4x consists on temporally jittering SMAA S2x, so the first step is to calculate SMAA S2x for current frame. In this case, 'subsampleIndices' must be set as follows:
| F# | S# | Camera Jitter | Net Jitter | subsampleIndices | +-—+-—+-----------------—+----------------—+-------------------—+ | 0 | 0 | ( 0.125, 0.125) | ( 0.375, -0.125) | float4(5, 3, 1, 3) | | 0 | 1 | ( 0.125, 0.125) | (-0.125, 0.375) | float4(4, 6, 2, 3) | +-—+-—+-----------------—+----------------—+-------------------—+ | 1 | 2 | (-0.125, -0.125) | ( 0.125, -0.375) | float4(3, 5, 1, 4) | | 1 | 3 | (-0.125, -0.125) | (-0.375, 0.125) | float4(6, 4, 2, 4) |
These jitter positions assume a bottom-to-top y axis. F# stands for the frame number. S# stands for the sample number.
e) If motion blur is used, you may want to do the edge detection pass together with motion blur. This has two advantages:
Note that in this case depth testing should be used instead of stenciling, as we have to write all the pixels in the motion blur pass.
That's it!
Definition at line 290 of file COM_SMAAOperation.cc.
Definition at line 526 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAANeighborhoodBlendingPS().
| #define SMAA_DEPTH_THRESHOLD (0.1f * SMAA_THRESHOLD) |
SMAA_DEPTH_THRESHOLD specifies the threshold for depth edge detection.
Range: depends on the depth range of the scene.
Definition at line 366 of file COM_SMAAOperation.cc.
| #define SMAA_FLATTEN |
Definition at line 305 of file COM_SMAAOperation.cc.
| #define SMAA_INCLUDE_PS 1 |
Definition at line 507 of file COM_SMAAOperation.cc.
| #define SMAA_INCLUDE_VS 1 |
On some compilers, discard cannot be used in vertex shaders. Thus, they need to be compiled separately.
Definition at line 504 of file COM_SMAAOperation.cc.
| #define SMAA_LOCAL_CONTRAST_ADAPTATION_FACTOR 2.0f |
If there is an neighbor edge that has SMAA_LOCAL_CONTRAST_FACTOR times bigger contrast than current edge, current edge will be discarded.
This allows to eliminate spurious crossing edges, and is based on the fact that, if there is too much contrast in a direction, that will hide perceptually contrast in the other neighbors.
Definition at line 419 of file COM_SMAAOperation.cc.
| #define SMAA_MAX_SEARCH_STEPS 16 |
SMAA_MAX_SEARCH_STEPS specifies the maximum steps performed in the horizontal/vertical pattern searches, at each side of the pixel.
In number of pixels, it's actually the double. So the maximum line length perfectly handled by, for example 16, is 64 (by perfectly, we meant that longer lines won't look as good, but still anti-aliased).
Range: [0, 112]
Definition at line 380 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAAOperation::get_area_of_interest(), and blender::compositor::SMAABlendingWeightCalculationVS().
| #define SMAA_MAX_SEARCH_STEPS_DIAG 8 |
SMAA_MAX_SEARCH_STEPS_DIAG specifies the maximum steps performed in the diagonal pattern searches, at each side of the pixel. In this case we jump one pixel at time, instead of two.
Range: [0, 20]
On high-end machines it is cheap (between a 0.8x and 0.9x slower for 16 steps), but it can have a significant impact on older machines.
Define SMAA_DISABLE_DIAG_DETECTION to disable diagonal processing.
Definition at line 396 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAAOperation::get_area_of_interest(), blender::compositor::SMAASearchDiag1(), and blender::compositor::SMAASearchDiag2().
| #define SMAA_PREDICATION 0 |
Predicated thresholding allows to better preserve texture details and to improve performance, by decreasing the number of detected edges using an additional buffer like the light accumulation buffer, object ids or even the depth buffer (the depth buffer usage may be limited to indoor or short range scenes).
It locally decreases the luma or color threshold if an edge is found in an additional buffer (so the global threshold can be higher).
This method was developed by Playstation EDGE MLAA team, and used in Killzone 3, by using the light accumulation buffer. More information here: http://iryoku.com/aacourse/downloads/06-MLAA-on-PS3.pptx
Definition at line 437 of file COM_SMAAOperation.cc.
| #define SMAA_PREDICATION_SCALE 2.0f |
How much to scale the global threshold used for luma or color edge detection when using predication.
Range: [1, 5]
Definition at line 457 of file COM_SMAAOperation.cc.
| #define SMAA_PREDICATION_STRENGTH 0.4f |
How much to locally decrease the threshold.
Range: [0, 1]
Definition at line 466 of file COM_SMAAOperation.cc.
| #define SMAA_PREDICATION_THRESHOLD 0.01f |
Threshold to be used in the additional predication buffer.
Range: depends on the input, so you'll have to find the magic number that works for you.
Definition at line 447 of file COM_SMAAOperation.cc.
| #define SMAA_REPROJECTION 0 |
Temporal reprojection allows to remove ghosting artifacts when using temporal supersampling. We use the CryEngine 3 method which also introduces velocity weighting. This feature is of extreme importance for totally removing ghosting. More information here: http://iryoku.com/aacourse/downloads/13-Anti-Aliasing-Methods-in-CryENGINE-3.pdf
Note that you'll need to setup a velocity buffer for enabling reprojection. For static geometry, saving the previous depth buffer is a viable alternative.
Definition at line 481 of file COM_SMAAOperation.cc.
| #define SMAA_REPROJECTION_WEIGHT_SCALE 30.0f |
SMAA_REPROJECTION_WEIGHT_SCALE controls the velocity weighting. It allows to remove ghosting trails behind the moving object, which are not removed by just using reprojection. Using low values will exhibit ghosting, while using high values will disable temporal supersampling under motion.
Behind the scenes, velocity weighting removes temporal supersampling when the velocity of the subsamples differs (meaning they are different objects).
Range: [0, 80]
Definition at line 496 of file COM_SMAAOperation.cc.
Definition at line 537 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAASearchLength().
Definition at line 292 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAASearchLength().
Definition at line 536 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAASearchLength().
| #define SMAA_THRESHOLD 0.1f |
Note that if you use one of these presets, the following configuration macros will be ignored if set in the "Configurable Defines" section. SMAA_THRESHOLD specifies the threshold or sensitivity to edges. Lowering this value you will be able to detect more edges at the expense of performance.
Range: [0, 0.5] 0.1 is a reasonable value, and allows to catch most visible edges. 0.05 is a rather overkill value, that allows to catch 'em all.
If temporal supersampling is used, 0.2 could be a reasonable value, as low contrast edges are properly filtered by just 2x.
Definition at line 357 of file COM_SMAAOperation.cc.
Definition at line 299 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAANeighborhoodBlendingPS().
Definition at line 295 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAAArea(), blender::compositor::SMAAAreaDiag(), blender::compositor::SMAABlendingWeightCalculationPS(), blender::compositor::SMAANeighborhoodBlendingPS(), blender::compositor::SMAASearchDiag2(), blender::compositor::SMAASearchLength(), blender::compositor::SMAASearchXLeft(), blender::compositor::SMAASearchXRight(), blender::compositor::SMAASearchYDown(), and blender::compositor::SMAASearchYUp().
Definition at line 296 of file COM_SMAAOperation.cc.
| #define SMAASampleOffset | ( | tex, | |
| coord, | |||
| offset, | |||
| size ) tex->texture_bilinear_extend(coord + float2(offset) / float2(size)) |
Definition at line 303 of file COM_SMAAOperation.cc.
Definition at line 300 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAABlendingWeightCalculationPS(), blender::compositor::SMAALumaEdgeDetectionPS(), and blender::compositor::SMAASearchDiag1().
| #define SMAASamplePointOffset | ( | tex, | |
| coord, | |||
| offset, | |||
| size ) tex->texture_nearest_extend(coord + float2(offset) / float2(size)) |
Definition at line 301 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAACalculateDiagWeights().
Definition at line 293 of file COM_SMAAOperation.cc.
Definition at line 294 of file COM_SMAAOperation.cc.
Referenced by blender::compositor::SMAABlendingWeightCalculationPS(), blender::compositor::SMAACalculateDiagWeights(), blender::compositor::SMAALumaEdgeDetectionPS(), blender::compositor::SMAASearchXLeft(), blender::compositor::SMAASearchXRight(), blender::compositor::SMAASearchYDown(), and blender::compositor::SMAASearchYUp().