Jump to content

  • Log In with Google      Sign In   
  • Create Account

FXAA Woes


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 trock   Members   -  Reputation: 155

Like
0Likes
Like

Posted 26 June 2012 - 12:04 PM

Hi,
I have been wrestling with FXAA for a few days now, and after getting updated to the latest version (3.11) I have finally gotten my FXAA shader to return usable values. I am using deferred rendering for the engine, and am running the FXAA shader immediately after combining my lightMap and Diffuse GBuffer, and outputting to a different renderTarget. The problem is, I am getting the below results; worse (and different) aliasing than before using it:

Posted Image
Posted Image

Do note, that if I comment out the "return FxaaPixelShader(...)" line for a standard texture sampler, the render looks like its normal aliased self (aka much better than the above). My code below comprises the area where I think there would have to be an issue. Any idea where it might be?

Note: I am using the Fxaa3_11.h file as is from Timothy Lottes, so the issue is definitely on my end.

Renderer Call:
[source lang="csharp"]void MakeFinal(GraphicsDevice GraphicsDevice, RenderTarget2D Output) { //Set Composition Target GraphicsDevice.SetRenderTarget(finalRender); //Clear GraphicsDevice.Clear(Color.Transparent); //Set Textures GraphicsDevice.Textures[0] = GBufferTargets[0].RenderTarget; GraphicsDevice.SamplerStates[0] = SamplerState.PointClamp; GraphicsDevice.Textures[1] = lightRT; GraphicsDevice.SamplerStates[1] = SamplerState.PointClamp; //Set Effect Parameters finalCombinedEffect.Parameters["GBufferTextureSize"].SetValue(GBufferTextureSize); //Apply finalCombinedEffect.CurrentTechnique.Passes[0].Apply(); //Draw //game.GraphicsDevice.DepthStencilState = DepthStencilState.None; quadRenderer.Draw(game.GraphicsDevice); //Set Composition Target GraphicsDevice.SetRenderTarget(Output); //Clear GraphicsDevice.Clear(Color.Transparent); FXAA.Parameters["SCREEN_WIDTH"].SetValue(finalRender.Width); FXAA.Parameters["SCREEN_HEIGHT"].SetValue(finalRender.Height); FXAA.Parameters["gScreenTexture"].SetValue(finalRender as Texture2D); //FXAA.Parameters["_rcpFrame"].SetValue(new Vector2(.4f, .4f)); FXAA.CurrentTechnique.Passes[0].Apply(); quadRenderer.Draw(game.GraphicsDevice); }[/source]

"finalCombinedEffect" Pixel Shader (where Luma is encoded):
[source lang="HLSL"]float4 PS(VSO input) : COLOR0{ //Sample Albedo float3 Color = tex2D(Albedo, input.UV).xyz; //Sample Light Map float4 Lighting = tex2D(LightMap, input.UV); //Accumulate to Final Color float4 output = float4(Color.xyz * Lighting.xyz + Lighting.w, 1); output.a = sqrt(dot(output.rgb, float3(0.299, 0.587, 0.114))); //Return return output; //return FxaaPixelShader(input.pos, posPos, tex, rcpFrame, rcpFrameOpt);}[/source]

FXAAShader:
[source lang="HLSL"]uniform extern float SCREEN_WIDTH;uniform extern float SCREEN_HEIGHT;uniform extern texture gScreenTexture;sampler screenSampler = sampler_state{ Texture = <gScreenTexture>; MinFilter = POINT; MagFilter = POINT; MipFilter = POINT; AddressU = Clamp; AddressV = Clamp;};#define FXAA_PC 1//#define FXAA_GREEN_AS_LUMA 1#if SHADER_MODEL >= 0x400 #if SHADER_MODEL >= 0x500 #define FXAA_HLSL_5 1 #else #define FXAA_HLSL_4 1 #endif#elif SHADER_MODEL <= 0x300 #define FXAA_HLSL_3 1#endif#include "Fxaa3_11.h"float4 PS(float2 tc : TEXCOORD0) : COLOR0{ float pixelWidth = (1 / SCREEN_WIDTH); float pixelHeight = (1 / SCREEN_HEIGHT); float2 pixelCenter = float2(tc.x, tc.y); float4 fxaaConsolePosPos = float4(tc.x - .5f, tc.y - .5f, tc.x + .5f, tc.y + .5f); //return tex2D(screenSampler, tc); return FxaaPixelShader( tc, fxaaConsolePosPos, screenSampler, screenSampler, screenSampler, float2(1.0f/SCREEN_WIDTH, 1.0f/SCREEN_HEIGHT), float4(2.0 / SCREEN_WIDTH, 2.0 / SCREEN_HEIGHT, .5 / SCREEN_WIDTH, .5 / SCREEN_HEIGHT), float4(0,0,0,0), float4(0,0,0,0), .75f, .166f, .08f, 8.0f, .125f, .05f, float4(0,0,0,0));}//Techniquetechnique Default{ pass p0 { PixelShader = compile ps_3_0 PS(); }}[/source]

Sponsor:

#2 japro   Members   -  Reputation: 887

Like
1Likes
Like

Posted 26 June 2012 - 03:15 PM

Doesn't fxaa require linear interpolation samplers instead of point ones? Also you can't combine the step that caluclates a with the fxaa step. The whole idea of setting that alpha tingy is that it can also read the alphas of neighbor pixels. So those values already have to be in the texture you read.

#3 trock   Members   -  Reputation: 155

Like
0Likes
Like

Posted 26 June 2012 - 04:03 PM

In case it's not clear, the finalCombine shader above is run first, and drawn to my render target. I then use that render target as the source for the Pixel Shader in my Fxaa PixelShader (separate shader). Are you saying Luma needs to be encoded in the pixel shader above that calls FxaaPixelShader? It might be easiest if you could illustrate where it should be encoded, because there are 3 pixel shaders at work here: finalCombine, my FXAA pixel shader, and then the FxaaPixelShader, which is called by my FXAA pixel shader.

I will try Linear IP tonight, although I did try that and didn't do much, BUT I have changed stuff since then. Also, it seems that my code block for my FXAA shader got cut off (and is breaking the forums maybe :( ). Considering this is a pretty critical peice, I have copied it below without the code box. Might help you explain exactly where a (Luma) should be calculated.

My FXAA Shader (which calls FxaaPixelShader):
uniform extern float SCREEN_WIDTH;

uniform extern float SCREEN_HEIGHT;

uniform extern texture gScreenTexture;


sampler screenSampler = sampler_state

{

Texture = <gScreenTexture>;

MinFilter = POINT;

MagFilter = POINT;

MipFilter = POINT;

AddressU = Clamp;

AddressV = Clamp;

};


#define FXAA_PC 1

//#define FXAA_GREEN_AS_LUMA 1


#if SHADER_MODEL >= 0x400

#if SHADER_MODEL >= 0x500

#define FXAA_HLSL_5 1

#else

#define FXAA_HLSL_4 1

#endif

#elif SHADER_MODEL <= 0x300

#define FXAA_HLSL_3 1

#endif


#include "Fxaa3_11.h"


float4 PS(float2 tc : TEXCOORD0) : COLOR0

{

float pixelWidth = (1 / SCREEN_WIDTH);

float pixelHeight = (1 / SCREEN_HEIGHT);


float2 pixelCenter = float2(tc.x, tc.y);

float4 fxaaConsolePosPos = float4(tc.x - .5f, tc.y - .5f,

tc.x + .5f, tc.y + .5f);


//return tex2D(screenSampler, tc);


return FxaaPixelShader(

tc,

fxaaConsolePosPos,

screenSampler,

screenSampler,

screenSampler,

float2(1.0f/SCREEN_WIDTH, 1.0f/SCREEN_HEIGHT),

float4(2.0 / SCREEN_WIDTH, 2.0 / SCREEN_HEIGHT, .5 / SCREEN_WIDTH, .5 / SCREEN_HEIGHT),

float4(0,0,0,0),

float4(0,0,0,0),

.75f,

.166f,

.08f,

8.0f,

.125f,

.05f,

float4(0,0,0,0));

}


//Technique

technique Default

{

pass p0

{

PixelShader = compile ps_3_0 PS();

}

}


#4 trock   Members   -  Reputation: 155

Like
0Likes
Like

Posted 26 June 2012 - 05:12 PM

I know all of that is probably pretty hard to read, but I can't even go back and edit my posts, so I apologize. I guess something in my initial topic broke the forums. I'll let the admins know.

#5 trock   Members   -  Reputation: 155

Like
0Likes
Like

Posted 27 June 2012 - 11:29 AM

So I updated the code to use linear interpolation and am using the green channel as Luma (to be safe in case I am setting Luma incorrectly), but I'm not certain things are working correctly. Below is an image of what it looks like, as well as my new shader code. Note that I am using above average quality settings and still seeing obvious aliasing:

Posted Image

uniform extern float SCREEN_WIDTH;
uniform extern float SCREEN_HEIGHT;
uniform extern texture gScreenTexture;
sampler screenSampler = sampler_state
{
    Texture = <gScreenTexture>;
    MinFilter = LINEAR;
    MagFilter = LINEAR;
    MipFilter = LINEAR;
    AddressU = Clamp;
    AddressV = Clamp;
};
#define FXAA_PC 1
#define FXAA_QUALITY__PRESET 23
#define FXAA_GREEN_AS_LUMA 1
#if SHADER_MODEL >= 0x400
#if SHADER_MODEL >= 0x500
  #define FXAA_HLSL_5 1
#else
  #define FXAA_HLSL_4 1
#endif
#elif SHADER_MODEL <= 0x300
#define FXAA_HLSL_3 1
#endif
#include "Fxaa3_11.h"
//Texture2D Texture;
SamplerState TextureSampler;
cbuffer cb0
{
float4 _rcpFrame;
float4 _rcpFrameOpt;
};
//Vertex Input Structure
struct VSI
{
float3 Position : POSITION0;
float2 UV : TEXCOORD0;
};
struct FxaaVS_Output { 
float4 Pos : SV_POSITION;			 
    float2 Tex : TEXCOORD0; };
FxaaVS_Output FxaaVS(uint id : SV_VertexID)
{
    FxaaVS_Output Output;
    Output.Tex = float2((id << 1) & 2, id & 2);
    Output.Pos = float4(Output.Tex * float2(2.0f, -2.0f) +
  float2(-1.0f, 1.0f), 0.0f, 1.0f);
    return Output;
}
sampler Texture : register(s0);
struct PS_OUTPUT
{
float4 c : COLOR;
};
float4 PS(FxaaVS_Output input) : COLOR0
{
    float pixelWidth = (1 / SCREEN_WIDTH);
    float pixelHeight = (1 / SCREEN_HEIGHT);
    float2 pixelCenter = float2(input.Tex.x, input.Tex.y);
    float4 fxaaConsolePosPos = float4(input.Tex.x - .5f, input.Tex.y - .5f,
input.Tex.x + .5f, input.Tex.y + .5f);
//FxaaTex =
//return float4(0,1,0,1);
    return FxaaPixelShader(
	    pixelCenter,
	    input.Pos,
  screenSampler,
  screenSampler,
	    screenSampler,
  float2(1.0f/SCREEN_WIDTH, 1.0f/SCREEN_HEIGHT),
	    float4(2.0 / SCREEN_WIDTH, 2.0 / SCREEN_HEIGHT, .5 / SCREEN_WIDTH, .5 / SCREEN_HEIGHT),
  float4(0,0,0,0),
  float4(0,0,0,0),
  1.0f,
  .063f,
  .0833f,
  8.0f,
  .125f,
  .05f,
  float4(0,0,0,0));
}
//Technique
technique Default
{
pass p0
{
  PixelShader = compile ps_3_0 PS();
  //VertexShader = compile vs_3_0 VS();
}
}





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS