Page MenuHome

Compositor: Add Anti-Aliasing node
Needs ReviewPublic

Authored by Shinsuke Irie (irie) on Dec 12 2016, 7:05 PM.

Details

Summary

This is an implementation of Enhanced Subpixel Morphological Antialiasing (SMAA)

The algorithm was proposed by:

Jorge Jimenez, Jose I. Echevarria, Tiago Sousa, Diego Gutierrez

Homepage URL:

http://www.iryoku.com/smaa/

This node provides only SMAA 1x mode, so the operation will be done with no spatial multisampling nor temporal supersampling.
Since the "depth edge detection" simply calculates differences between neighboring pixels, we can use arbitrary grayscale or binary image such as alpha channel or object IDs instead of depth.

Here is a comparison between existing antialiasing (Scale3x, imported from GIMP) and the Anti-Aliasing Node (SMAA 1x):


SMAA 1x produces much higher quality results than Scale3x.

The existing AA operation seems to be used only for binary images by some other nodes. Using SMAA for binary images needs no important parameter such as "threshold", so we perhaps can switch the operation to SMAA, though that changes existing behavior.

Currently, Anti-Aliasiing Node shows a lot of options. I merely implemented them for testing all configurable parameters, so I plan to remove unimportant options later.

Example: Using Anti-Aliasing Node as an alternative of OLM smoother that is widely used in Japanese animation studios:

Notes:

  1. The program code assumes the screen coordinates are DirectX style that the vertical direction is upside-down, so "top" and "bottom" actually represent bottom and top, respectively
  2. smaa_areatex.cpp is a stand-alone software I wrote for another project, so its copyright is still owned by me and under MIT-style license
  3. Unfortunately, this patch doesn't include OpenCL support (I'm not familiar with it...), though SMAA is not so slow

Tested on Ubuntu 16.10 and Windows 10.

Diff Detail

Repository
rB Blender
Branch
smaa_node
Build Status
Buildable 2382
Build 2382: arc lint + arc unit

Event Timeline

Shinsuke Irie (irie) retitled this revision from to Compositor: Add Anti-Aliasing node.
Shinsuke Irie (irie) updated this object.

For such patches it's always a good idea to include render tests demonstrating the results. How does this compares to existing AA operation? If it's considered more superior quality, can existing AA operation be switched to this code?

General notes:

  • You're re-implementing fair amount of utility functions, use blenlib instead.
  • If some utility is missing better to generalize that a bit and put to blenlib.
  • Any code which is added to source/blender/ should follow a blender convention, which is not really a case for smaa_areatex.cpp. Possible solutions:
    • Make it a proper Blender-style utility
    • Keep it in extern/
    • Keep it fully external and only include a generated files into Blender's git with clear instructions how to re-generate them.

I would also like this patch be tested by real compositor artists, like @Sean Kennedy (hype). The amount of controls there doesn't seem friendly at all.

That's first pass of review anyway.

source/blender/compositor/operations/COM_SMAAOperation.cpp
53

Do not re-implement those, use blenlib utilities instead.

source/blender/compositor/operations/COM_SMAAOperation.h
27

It can't be a shader. Guess you used code from some GLSL or so application, but "shader" in terms of compositor is meaningless word.

source/blender/compositor/operations/smaa_areatex.cpp
1 ↗(On Diff #7980)

This is a confusing location for files like this. This directory is supposed to be used by compositor operations.

43 ↗(On Diff #7980)

We have quite comprehensive math operations library already. Adding an "abstraction" for just a specific node should not be happening.

57 ↗(On Diff #7980)

Any specific reason why you use doubles? Rest of Blender works in floats, so i assume that using doubles here will do quite a bit of float->double->float conversions.

126 ↗(On Diff #7980)

Make it static so it's not in the global symbol table.

129 ↗(On Diff #7980)

Same as above.

196 ↗(On Diff #7980)

Better to use enum with reasonable human-readable names.

This also does not follow Blender code style.

391 ↗(On Diff #7980)

Use bool.

450 ↗(On Diff #7980)

Style and meaningful names.

source/blender/makesrna/intern/rna_nodetree.c
7052

Am not convinced this is really artist-friendly controls.

source/blender/nodes/composite/nodes/node_composite_antiAliasing.c
19

Be careful about license header please. Doublecheck all of the new files.

Here it can't be 2006, we are decade above that now.

Shinsuke Irie (irie) edited edge metadata.
source/blender/compositor/operations/smaa_areatex.cpp
1 ↗(On Diff #7980)

Maybe I'll move this to extern/.

57 ↗(On Diff #7980)

Initially I used floats, but confirmed using floats produces non-negligible precision errors after iterative calculations.
This program couldn't generate same result as the original AreaTex.py if using floats, even though the values in the texture are quantized to only 256 levels.

source/blender/makesrna/intern/rna_nodetree.c
7052

Agreed, currently this merely uses the same parameters/namings as the original GLSL version that mainly used by game developers.
I think most of all options can be removed or changed to more friendly naming.
Especially, "Depth Edge Detection" is the most confusing name, this also can be used for the other various perposes (e.g. removing jaggies from alpha blended images).

Looks neat! I'd be happy to test it on some vfx type things.

Here is a test build for Windows 64bit.

Note, maybe I'll do incompatible changes later.

Style and comment fixes, remove own utility functions

  • Also update smaa_areatex.cpp to v0.1
  • smaa_areatex.cpp still isn't placed in proper location
  • No functional change except for smaa_areatex.cpp

I tested this new node for some cases, and I'm really impressed.

Material Index masking.

  • I get some "edges" if the masks overlap, but I think this has to do how Blender defines the edges.
  • Other than that it works very well, much better than the current anti-aliasing in the Index MA node.


Replacing a color

  • This also works very well for single masking.


Creating a mask from z values

  • Works fine.


Image without anti-aliasing

  • Renderd an OpenGL image without anti-aliasing
  • Added anti-aliasing to image in compositor. Looks very good.


This would be a great addition to the Blender compositor.

  • Improve render quality
  • Fix several render issues
  • Remove unimportant options such as Predicated thresholding
  • Remove "Blending Weights" output that is useful only for debugging
  • Rename "Depth" to "Value"
  • Modify UI texts
  • Move smaa_areatex.cpp to extern/smaa_areatex/
  • Optimization
  • Style cleanup
  • Update copyright year

Also update the test build for Windows 64bit.

  • Forgot to update extern/smaa_areatex/README.blender

Hi,

@Shinsuke Irie (irie) these are greate improvements to the node.

  1. First the node was simplified, which is great and works like intended.
  2. Second the node supports now GPU rendering and is therefore super fast. :-)
  3. The quality has also improved.

Could you check the file and possible bug here? Please open the file and mute/unmute the anti-aliasing node.
The edge of the blue sphere seems not to change (get smoother).

Thank you for your hard work!

@Michael P. (forest-house) You forgot to set parameters of the Dilate/Erode Node. Setting the Distance -1 removes the artifact.

Also, in this case you should use the edge detection type "Value" rather than "Color". If using the "Value" type and connecting the Z mask to "Value" input, antialiasing will be performed along only the outline of the Z mask.

Attached a modified .blend file:

Rebased on the latest master.

Any chance to get this into the 2.79 release?

Any progress here? I ask, because this is a useful feature. And there seems to be no activity here.

Hi @Brecht Van Lommel (brecht), I know you have a lot to do, but could this feature someday included in Blender? (Only asking)

Rebased on the latest master.