Dear All,
I've integrated the SMAA S2X and 4X modes for OpenGL. Getting the integration going was relatively easy (just follow the integration notes in SMAA.hlsl) and don't forget to add some missing defines to SMAA.hlsl in the #if defined(SMAA_GLSL_3) || defined(SMAA_GLSL_4)
section:
#define SMAATexture2DMS2(tex) sampler2DMS tex
#define SMAALoad(tex, pos, sample) texelFetch(tex, pos, sample)
Once I got it running, the 4X mode didn't look as good as expected compared to T2X - some edges look better, but others look worse. I think the reason for this is the difference in MSAA2x subsample positions between DirectX and OpenGL.
The integration notes in SMAA.hlsl call for the scene to be rendered with D3D10_STANDARD_MULTISAMPLE_PATTERN for SMAA 4X. This allows the subsamples to match the order in the @SUBSAMPLE_INDICES table. When the scene is rendered this way, you have the following subsample positions in DirectX:
* Sample positions DirectX:
* _______
* | S1 | S0: 0.25 -0.25
* | | S1: -0.25 0.25
* |____S0_|
*
On the other hand, for MSAA2X in OpenGL you get the following subsample positions (positions adjusted for pixel centre that is reported at (0.5,0.5)
- see below):
* Sample positions OpenGL:
* _______
* | S0 | S0: 0.25 0.25
* | | S1: -0.25 -0.25
* |_S1____|
*
I've been puzzling on how to adjust the subsampleIndices to make SMAA 4X work in OpenGL. Does anyone have some insight here ? In the DX10 demo it is mentioned that the indices have the following layout : Indices layout: indices[4] = { |, --, /, \ }
. How should that be interpreted ?
I suspect I also need to adjust the camera jitter, since with the recommended jitter of (0.125, 0.125)
and (-0.125, -0.125)
for SMAA4X I would end up with a net jitter in OpenGL of:
* ________
* | S0| S0: 0.3750 0.3750
* | S2 | S1: -0.1250 -0.1250
* | S1 | S2: 0.1250 0.1250
* |S3______| S3: -0.3750 -0.3750
*
As a test, I modified the camera jitter offset to use the original, unadjusted subsample positions of MSAA2X instead: (0.75, 0.75)
and (0.25, 0.25)
(obtained with glGetMultisamplefv, (0.5, 0.5)
is the pixel centre). That improved things quite a bit, but I can't help but think I'm still missing something?