Source code for "Pratical Morphological Anti-Aliasing" is out
by Manoel Neto · in Torque 3D Professional · 03/19/2011 (3:38 pm) · 31 replies
www.iryoku.com/mlaa
I haven't read it yet but since there is a DX9 implementation it should be possible to integrate into T3D and we might finally have a solution for the lack of MSAA in Advanced Lighting.
-- EDIT --
After a quick glance at the source, all of the magic is in a .fx file, the source code just setting render targets, binding textures and setting some shader constants. It seems entirely possible to re-create it using a PostEffect, probably with zero source code modifications.
I haven't read it yet but since there is a DX9 implementation it should be possible to integrate into T3D and we might finally have a solution for the lack of MSAA in Advanced Lighting.
-- EDIT --
After a quick glance at the source, all of the magic is in a .fx file, the source code just setting render targets, binding textures and setting some shader constants. It seems entirely possible to re-create it using a PostEffect, probably with zero source code modifications.
About the author
Recent Threads
#22
04/01/2011 (1:51 pm)
That's really neat.
#23
So first i got the stencil hooked up. Seems like with it MLAA is ~1ms. Having trouble getting an accurate measurement because of some other system in Torque causing as much as 3ms of frame rate fluctuation.
Also i saw this in the edge shader...
I suspect that the 10 is far plane dependent and we probably need a separate 'depthThreshold' value to tweak it.
04/02/2011 (3:00 pm)
@ManoelSo first i got the stencil hooked up. Seems like with it MLAA is ~1ms. Having trouble getting an accurate measurement because of some other system in Torque causing as much as 3ms of frame rate fluctuation.
Also i saw this in the edge shader...
// Dividing by 10 give us results similar to the color-based detection. edges += step(threshold.xxxx / 10.0, delta);
I suspect that the 10 is far plane dependent and we probably need a separate 'depthThreshold' value to tweak it.
#24
While you're at it, you can remove this hack from edgeDetectopnP.hlsl:
04/02/2011 (3:44 pm)
That's how it came from the MLAA source code, but I agree it should be tweakable.While you're at it, you can remove this hack from edgeDetectopnP.hlsl:
float3 weights = float3(0.2126,0.7152, 0.0722); // These ones are from the ITU-R Recommendation BT. 709 // Increase red weight weights.x *= 2;...and expose "weights" into the postEffect like the threshold is. The "Increase red weight" was a hack I added there because I felt it wasn't detecting many edges in scenes with too much brown/reds/oranges. I think people might want to tinker with it depending on the dominant color tones used in their scenes.
#25
04/02/2011 (9:45 pm)
Cool... done.
#26
04/02/2011 (10:30 pm)
I think this breaks sun flares, well, flares
#27
I just tested a few different kinds of light flares and they seem to be working ok for me. If you can give me more details on the issue your seeing i can maybe debug it.
Also consider there are a couple of other known light flare bugs... could be one of those.
04/03/2011 (2:00 am)
@deepscratchI just tested a few different kinds of light flares and they seem to be working ok for me. If you can give me more details on the issue your seeing i can maybe debug it.
Also consider there are a couple of other known light flare bugs... could be one of those.
#28
what I am seeing is: when adding vehicles to the scene, by the 3rd one, the sun flare disappears.
flare bug then.
I had added this at the same time, so thought there was a connection
04/03/2011 (2:09 am)
yes Tom, you are correct, not related to this,what I am seeing is: when adding vehicles to the scene, by the 3rd one, the sun flare disappears.
flare bug then.
I had added this at the same time, so thought there was a connection
#29
Just in case anyone has not read it yet; www.crytek.com/sites/default/files/Crysis%202%20Key%20Rendering%20Features.pdf (only posted for reading for knowledge, no other reason intended.)
04/04/2011 (12:28 am)
Off angle post:Just in case anyone has not read it yet; www.crytek.com/sites/default/files/Crysis%202%20Key%20Rendering%20Features.pdf (only posted for reading for knowledge, no other reason intended.)
#30
04/24/2011 (7:45 pm)
Implemented in 1.1 Final and Preview.
#31
05/28/2011 (11:41 am)
Hey Guys, good news. I talked with Jorge about this thread (I helped him with some of the different options for measuring the performance in the original paper) and he's since been using Torque for a lot of his experimenting. He sent me a diff w/ some suggested updates to the Torque implementation. I sneaked a couple of these changes into 1.1 for the release.diff -ur game.orig/core/scripts/client/postFx/MLAA.cs game/core/scripts/client/postFx/MLAA.cs
--- game.orig/core/scripts/client/postFx/MLAA.cs Thu May 26 15:24:23 2011
+++ game/core/scripts/client/postFx/MLAA.cs Thu May 26 15:25:42 2011
@@ -69,9 +69,9 @@
stencilRef = 1;
samplersDefined = true;
- samplerStates[0] = SamplerClampLinear;
+ samplerStates[0] = SamplerClampPoint;
samplerStates[1] = SamplerClampLinear;
- samplerStates[2] = SamplerClampLinear;
+ samplerStates[2] = SamplerClampPoint;
};
singleton ShaderData( MLAA_NeighborhoodBlendingShader )
@@ -124,6 +124,7 @@
target = "$outTex";
targetClear = PFXTargetClear_OnDraw;
+ targetClearColor = "0 0 0 0";
shader = MLAA_BlendWeightCalculationShader;
stateBlock = MLAA_BlendWeightCalculationStateBlock;
diff -ur game.orig/shaders/common/postFx/mlaa/functions.hlsl game/shaders/common/postFx/mlaa/functions.hlsl
--- game.orig/shaders/common/postFx/mlaa/functions.hlsl Thu May 26 15:23:55 2011
+++ game/shaders/common/postFx/mlaa/functions.hlsl Thu May 26 15:25:26 2011
@@ -14,8 +14,8 @@
#if !defined(PIXEL_SIZE)
#define PIXEL_SIZE (1.0 / texSize0)
-#define MAX_SEARCH_STEPS 8
-#define MAX_DISTANCE 32
+#define MAX_SEARCH_STEPS 16
+#define MAX_DISTANCE 33
#endif
// Typical Multiply-Add operation to ease translation to assembly code.
Torque 3D Owner Ray Batts
Sickhead Games
Just wanted to let you know that we have this MLAA checked in for 1.1 final. Big thanks to Manoel for looking into this! For those that want to check it out and are too lazy to read an entire forum thread, download and apply the files from htere: www.mediafire.com/?z1izbxtf5idz7ei
And make the following changes to disable the old AA.:
in ...\game\core\scripts\client\postFx\edgeAA.cs
singleton PostEffect( EdgeDetectPostEffect ) { renderTime = "PFXBeforeBin"; renderBin = "ObjTranslucentBin"; //renderPriority = 0.1; targetScale = "0.5 0.5"; shader = PFX_EdgeAADetectShader; stateBlock = PFX_DefaultEdgeAAStateBlock; texture[0] = "#prepass"; target = "#edge"; isEnabled = false; //BOOLEAN CHANGED TO FALSE };Also make the following change:
...\game\core\scripts\client\canvas.cs
As usual, let us know if there are any problems or concerns.