SMAA Implementation - Weights Pass

Started by
12 comments, last by csirke128 11 years, 6 months ago

Hi FriendlyFire. I'm sorry for the late answer, I'm in total crunch time and deadlines do not forgive !
I eventually got SMAA to work on console aaaannnnnd it took 10 ms to render ! This is the time I gave up.

To have it working on PC, I simply turned the pixel shader interpolated array "offsets[3]" into 3 interpolated values "offset0", "offset1" and "offset2". The compiler did mess with them.


Hey! First of all thanks for updating this.

I've tried to do as you said, but I do not see any significant change. I have tried to only replace the offset array in SMAABlendingWeightCalculationPS and to replace all offset arrays in all functions to no avail.

If you have a few moments, would you be able to detail a bit more what you've done to fix it, perhaps with some code?

Thanks once more.
Advertisement
Here's the code I'm using to integrate the SMAA in our engine shader generator.
The #define ENABLE_SMAA_VS is set only when compiling a vertex shader. The DX9 compiler was messing things up otherwise (as well as our GLSL converter).



// -- Pass 0
void VS_SmaaPass0(
vs_Input _vs_In,
out float4 f4_Position : POSITION,
out float2 f2_TexCoord : TEXCOORD0,
out float4 f4_Offset0 : TEXCOORD1,
out float4 f4_Offset1 : TEXCOORD2,
out float4 f4_Offset2 : TEXCOORD3
)
{
ComputePosUV2D(f4_Position, f2_TexCoord, _vs_In.f4_Position, _vs_In.f2_TexCoord0.xy); // Store the vertex position & its texcoord in f4_Position and f2_TexCoord
#if defined(ENABLE_SMAA_VS)
float4 f4_Offsets[3];
SMAAEdgeDetectionVS(f4_Position, f4_Position, f2_TexCoord, f4_Offsets);
f4_Offset0 = f4_Offsets[0];
f4_Offset1 = f4_Offsets[1];
f4_Offset2 = f4_Offsets[2];
#else
f4_Offset0 = float4(0.0, 0.0, 0.0, 0.0);
f4_Offset1 = float4(0.0, 0.0, 0.0, 0.0);
f4_Offset2 = float4(0.0, 0.0, 0.0, 0.0);
#endif
}
float4 PS_SmaaPass0(
float2 f2_TexCoord : TEXCOORD0,
float4 f4_Offset0 : TEXCOORD1,
float4 f4_Offset1 : TEXCOORD2,
float4 f4_Offset2 : TEXCOORD3
) : COLOR0
{
#if defined(ENABLE_SMAA_VS)
return float4(0.0, 0.0, 0.0, 0.0);
#else
float4 f4_Offsets[3];
f4_Offsets[0] = f4_Offset0;
f4_Offsets[1] = f4_Offset1;
f4_Offsets[2] = f4_Offset2;
return SMAALumaEdgeDetectionPS(f2_TexCoord, f4_Offsets, samp_SmaaSourceTex);
#endif
}

// -- Pass 1
void VS_SmaaPass1(
vs_Input _vs_In,
out float4 f4_Position : POSITION,
out float2 f2_TexCoord : TEXCOORD0,
out float2 f2_PixCoord : TEXCOORD1,
out float4 f4_Offset0 : TEXCOORD2,
out float4 f4_Offset1 : TEXCOORD3,
out float4 f4_Offset2 : TEXCOORD4
)
{
ComputePosUV2D(f4_Position, f2_TexCoord, _vs_In.f4_Position, _vs_In.f2_TexCoord0.xy);
#if defined(ENABLE_SMAA_VS)
float4 f4_Offsets[3];
SMAABlendingWeightCalculationVS(f4_Position, f4_Position, f2_TexCoord, f2_PixCoord, f4_Offsets);
f4_Offset0 = f4_Offsets[0];
f4_Offset1 = f4_Offsets[1];
f4_Offset2 = f4_Offsets[2];
#else
f4_Offset0 = float4(0.0, 0.0, 0.0, 0.0);
f4_Offset1 = float4(0.0, 0.0, 0.0, 0.0);
f4_Offset2 = float4(0.0, 0.0, 0.0, 0.0);
#endif
}
float4 PS_SmaaPass1(float2 f2_TexCoord : TEXCOORD0,
float2 f2_PixCoord : TEXCOORD1,
float4 f4_Offset0 : TEXCOORD2,
float4 f4_Offset1 : TEXCOORD3,
float4 f4_Offset2 : TEXCOORD4) : COLOR0
{
#if defined(ENABLE_SMAA_VS)
return float4(0.0, 0.0, 0.0, 0.0);
#else
float4 f4_Offsets[3];
f4_Offsets[0] = f4_Offset0;
f4_Offsets[1] = f4_Offset1;
f4_Offsets[2] = f4_Offset2;
return SMAABlendingWeightCalculationPS(f2_TexCoord, f2_PixCoord, f4_Offsets, samp_SmaaSourceTex, samp_SmaaAreaTex, samp_SmaaSearchTex, 0);
#endif
}

// -- Pass 2
void VS_SmaaPass2(
vs_Input _vs_In,
out float4 f4_Position : POSITION,
out float2 f2_TexCoord : TEXCOORD0,
out float4 f4_Offset0 : TEXCOORD1,
out float4 f4_Offset1 : TEXCOORD2
)
{
ComputePosUV2D(f4_Position, f2_TexCoord, _vs_In.f4_Position, _vs_In.f2_TexCoord0.xy);
#if defined(ENABLE_SMAA_VS)
float4 f4_Offsets[2];
SMAANeighborhoodBlendingVS(f4_Position, f4_Position, f2_TexCoord, f4_Offsets);
f4_Offset0 = f4_Offsets[0];
f4_Offset1 = f4_Offsets[1];
#else
f4_Offset0 = float4(0.0, 0.0, 0.0, 0.0);
f4_Offset1 = float4(0.0, 0.0, 0.0, 0.0);
#endif
}
float4 PS_SmaaPass2(
float2 f2_TexCoord : TEXCOORD0,
float4 f4_Offset0 : TEXCOORD1,
float4 f4_Offset1 : TEXCOORD2
) : COLOR0
{
#if defined(ENABLE_SMAA_VS)
return float4(0.0, 0.0, 0.0, 0.0);
#else
float4 f4_Offsets[2];
f4_Offsets[0] = f4_Offset0;
f4_Offsets[1] = f4_Offset1;
return SMAANeighborhoodBlendingPS(f2_TexCoord, f4_Offsets, samp_SmaaSourceTex, samp_SmaaBlendTex);
#endif
}
Thanks for the help. I've been trying things following your post but I just can't seem to figure it out. Guess I'll put it on the backburner for a while longer...
Hi,

I've been working on a small 2d drawing app, and i wanted to implement SMAA for it, but i've ran into problems at the 2nd pass, instead of having nice connected lines, i had a lot of dotted lines, and nothing i did in the shaders/c++ code could change it, so i looked around in the SMAA.h and noticed some commented lines:


float SMAASearchLength(SMAATexture2D searchTex, float2 e, float bias, float scale) {
// Not required if searchTex accesses are set to point:
// float2 SEARCH_TEX_PIXEL_SIZE = 1.0 / float2(66.0, 33.0);
// e = float2(bias, 0.0) + 0.5 * SEARCH_TEX_PIXEL_SIZE +
// e * float2(scale, 1.0) * float2(64.0, 32.0) * SEARCH_TEX_PIXEL_SIZE;
e.r = bias + e.r * scale;
return 255.0 * SMAASampleLevelZeroPoint(searchTex, e).r;
}


And after i've changed it to this,


float SMAASearchLength(SMAATexture2D searchTex, float2 e, float bias, float scale) {
// Not required if searchTex accesses are set to point:
float2 SEARCH_TEX_PIXEL_SIZE = 1.0 / float2(66.0, 33.0);
e = float2(bias, 0.0) + 0.5 * SEARCH_TEX_PIXEL_SIZE +
e * float2(scale, 1.0) * float2(64.0, 32.0) * SEARCH_TEX_PIXEL_SIZE;
//e.r = bias + e.r * scale;
return 255.0 * SMAASampleLevelZeroPoint(searchTex, e).r;
}


everything worked fine

for comparison:

Before
[attachment=11856:smaa1.PNG]
After
[attachment=11857:smaa2.PNG]

It might not be the same problem, but i think its worth checking it out

(I was using directX11 on windows8, no techinques/effects just pixel and vertex shader)

This topic is closed to new replies.

Advertisement