diff options
author | Jeroen Bakker <jeroen@blender.org> | 2021-02-16 10:59:17 +0300 |
---|---|---|
committer | Jeroen Bakker <jeroen@blender.org> | 2021-02-16 11:05:44 +0300 |
commit | 36814ddc94b56a66675b854bc0d7485828ddcd31 (patch) | |
tree | 32d4a28a562294a13d77a46e8c11157dca1ff592 /source/blender/draw/engines/workbench/shaders | |
parent | dd79a715c98147dd1603b867502d3d8a0c8ca777 (diff) |
Workbench: Improve AntiAliasing sampling
This improves stability and convergence speed of Workbench Temporal AntiAliasing.
This adds a filtering kernel (blackmann-haris, same as EEVEE/Cycles) to the
temporal antialiasing sampling. We also gather neighbor pixels since they might
end up in the pixel footprint.
We use a 1px radius for the filter window which is a bit less than the 1.5 default
of cycles and EEVEE since it does blur quite a bit more than what we have now.
Another improvement is that the filtering is now in log space which improves
AntiAliasing around highlights.
Theses improvement may not be very useful for every day case but it was an
experiment to try to make TAA usable for GPencil.
Test file used :
{F9798807}
|filtered+logspace|filtered|original|
|{F9798847}|{F9798848}|{F9798849}|
Reviewed By: jbakker
Differential Revision: https://developer.blender.org/D10414
Diffstat (limited to 'source/blender/draw/engines/workbench/shaders')
-rw-r--r-- | source/blender/draw/engines/workbench/shaders/workbench_effect_smaa_frag.glsl | 10 | ||||
-rw-r--r-- | source/blender/draw/engines/workbench/shaders/workbench_effect_taa_frag.glsl | 17 |
2 files changed, 22 insertions, 5 deletions
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_effect_smaa_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_effect_smaa_frag.glsl index 2dea2fc4883..9797a5e3301 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_effect_smaa_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_effect_smaa_frag.glsl @@ -5,7 +5,7 @@ uniform sampler2D searchTex; uniform sampler2D blendTex; uniform sampler2D colorTex; uniform float mixFactor; -uniform float taaSampleCountInv; +uniform float taaAccumulatedWeight; in vec2 uvs; in vec2 pixcoord; @@ -39,6 +39,12 @@ void main() if (mixFactor < 1.0) { fragColor += texture(colorTex, uvs) * (1.0 - mixFactor); } - fragColor *= taaSampleCountInv; + fragColor /= taaAccumulatedWeight; + fragColor = exp2(fragColor) - 0.5; + + /* Avoid float precision issue. */ + if (fragColor.a > 0.999) { + fragColor.a = 1.0; + } #endif } diff --git a/source/blender/draw/engines/workbench/shaders/workbench_effect_taa_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_effect_taa_frag.glsl index b877c2c3f76..d021e4696f7 100644 --- a/source/blender/draw/engines/workbench/shaders/workbench_effect_taa_frag.glsl +++ b/source/blender/draw/engines/workbench/shaders/workbench_effect_taa_frag.glsl @@ -1,11 +1,22 @@ uniform sampler2D colorBuffer; - -in vec4 uvcoordsvar; +uniform float samplesWeights[9]; out vec4 fragColor; void main() { - fragColor = texture(colorBuffer, uvcoordsvar.st); + vec2 texel_size = 1.0 / vec2(textureSize(colorBuffer, 0)); + vec2 uv = gl_FragCoord.xy * texel_size; + + fragColor = vec4(0.0); + int i = 0; + for (int x = -1; x <= 1; x++) { + for (int y = -1; y <= 1; y++, i++) { + /* Use log2 space to avoid highlights creating too much aliasing. */ + vec4 color = log2(texture(colorBuffer, uv + vec2(x, y) * texel_size) + 0.5); + + fragColor += color * samplesWeights[i]; + } + } } |