Jump to content



FXAA Help

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

#1 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 30 August 2011 - 01:48 PM

I have the FXAA shader but it's so convolouted. Looked for a tutorial online but nothing turned up.


Anyone know where I can find documentation on FXAA and it's implememtation?

Ad:

#2 smasherprog   Members   -  Reputation: 303

Like
0Likes
Like

Posted 30 August 2011 - 02:41 PM

Hrmmm...

Download the shader from the website http://timothylottes.blogspot.com/

The FXAA shader only needs your color buffer as input, but this means you need an extra render target.

So, create an extra render target the same size as your backbuffer.
the FXAA pass should be after all of your game drawing and effects are done.
Copy the color buffer to a temp buffer.
Then, use the copied buffer as input to create the final image.

I am not sure which part you are having a difficult time with.
As for the shader itself, it contains many different implementations for Playstatio, XBox and PC versions. Read the comments, you can safely remove the unneeded code, which will improve your compile times.
Wisdom is knowing when to shut up, so try it.
--Game Development http://nolimitsdesigns.com: Reliable UDP library, Threading library, Math Library, UI Library. Take a look, its all free.

#3 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 31 August 2011 - 07:38 AM

View Postsmasherprog, on 30 August 2011 - 02:41 PM, said:


I am not sure which part you are having a difficult time with.


The download is a "h" file (header) with tons of macro's (defines). I only need it for the PC. My existing shaders are all FX files and for this specific application (not a game) that requires the AA, it is not written in C++.

Prior to the new requirements, hardware multisampling was sufficient but now they want to take screenshots. I was unable to provide multisampling when rendering to a surface for screen shots- hence, I need an AA alternative.

Will FXAA work with PS v2.0?

Does FXAA access require C++ implementation?

How does FXAA hold up on non- nvidia hardware?

These are the things I'm having a difficult time with...








#4 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 01 September 2011 - 10:12 AM

To add to this, I'm also finding it difficult to create a full screen triangle. How can a triangle be full screen when my backbuffer and monitor are rectangular in shape?

#5 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 01 September 2011 - 01:33 PM

Is it possible to use a sprite and pass that in?

#6 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 01 September 2011 - 04:29 PM

My shader fails after adding the line:#include "Fxaa3_11.h"

IS FXAA SM 2.0 Compatible?






#7 B_old   Members   -  Reputation: 158

Like
0Likes
Like

Posted 02 September 2011 - 07:26 AM

View PostDJTN, on 01 September 2011 - 10:12 AM, said:

To add to this, I'm also finding it difficult to create a full screen triangle. How can a triangle be full screen when my backbuffer and monitor are rectangular in shape?
The way to do this is to create a triangle that is big enough so that the rectangle of the backbuffer fits inside. You can also use a full screen quad, if it is easier for you.


View PostDJTN, on 01 September 2011 - 10:12 AM, said:

My shader fails after adding the line:#include "Fxaa3_11.h"
IS FXAA SM 2.0 Compatible?

I think it is. Did you put #define FXAA_PC 1 before the include?

#8 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 02 September 2011 - 10:03 AM

View PostB_old, on 02 September 2011 - 07:26 AM, said:

Did you put #define FXAA_PC 1 before the include?


Yes, at the top of my shader I put the following:
#define FXAA_PC 1

#include "Fxaa3_11.h"



and it fails to compile. If I only add the include or only the define, then it compiles but with both of them it fails.

#9 B_old   Members   -  Reputation: 158

Like
0Likes
Like

Posted 02 September 2011 - 10:33 AM

Do you have a way to tell why it fails to compile? Looking at the error message of the compiler e.g.

#10 ATEFred   Members   -  Reputation: 138

Like
0Likes
Like

Posted 02 September 2011 - 10:48 AM

View PostDJTN, on 31 August 2011 - 07:38 AM, said:

View Postsmasherprog, on 30 August 2011 - 02:41 PM, said:

I am not sure which part you are having a difficult time with.


The download is a "h" file (header) with tons of macro's (defines). I only need it for the PC. My existing shaders are all FX files and for this specific application (not a game) that requires the AA, it is not written in C++.

Prior to the new requirements, hardware multisampling was sufficient but now they want to take screenshots. I was unable to provide multisampling when rendering to a surface for screen shots- hence, I need an AA alternative.

Will FXAA work with PS v2.0?

Does FXAA access require C++ implementation?

How does FXAA hold up on non- nvidia hardware?

These are the things I'm having a difficult time with...


FXAA works great, even on non NV hw. We used it in our commercial project, and this was a concern for us as well. Turns out it was not a problem.
FXAA requires no c++ side implementation, other than a full screen pass. (draw fullscreen quad, set shader, pass in main RT, output to backbuffer or RT of choice).
I don't remember any problems with FXAA on sm2, other than we had to disable the higher quality versions as it resulted in more instructions than supported by sm2. (Memory is a bit hazy though, so don't take my word for it).

#11 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 02 September 2011 - 10:53 AM

View PostB_old, on 02 September 2011 - 10:33 AM, said:

Do you have a way to tell why it fails to compile? Looking at the error message of the compiler e.g.


PIX is being buggy as hell and I cannot get it working -however, I did notice that if I switch the order it compiles, I.E.

#include "Fxaa3_11.h"

#define FXAA_PC 1





Once I get pass that problem, how do I call it's method? Looking through to the define I'm working with (FXAA_PC 1) the method ask for all these inputs:

FxaaFloat2 fxaaQualityRcpFrame,
FxaaFloat4 fxaaConsoleRcpFrameOpt,
FxaaFloat4 fxaaConsoleRcpFrameOpt2,
FxaaFloat4 fxaaConsole360RcpFrameOpt2,
FxaaFloat fxaaQualitySubpix,
FxaaFloat fxaaQualityEdgeThreshold,
FxaaFloat fxaaQualityEdgeThresholdMin,
FxaaFloat fxaaConsoleEdgeSharpness,
FxaaFloat fxaaConsoleEdgeThreshold,
FxaaFloat fxaaConsoleEdgeThresholdMin,
FxaaFloat4 fxaaConsole360ConstDir

The documentation says:

Then call the FXAA pixel shader from within your desired shader.
Look at the FXAA Quality FxaaPixelShader() for docs on inputs.
As for FXAA 3.11 all inputs for all shaders are the same
to enable easy porting between platforms.


return FxaaPixelShader(...);

I searched the entire doc for "FXAA Quality FxaaPixelShader()" and never found anything that resembles definitions for these constants / inputs.

SMASHERPROG posted the following earlier in this post saying "The FXAA shader only needs your color buffer as input". Am I missing something here?





#12 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 02 September 2011 - 11:07 AM

I thought I might be hitting an instruc limit so I through together a very simple PS and it still fails to compile:



#define FXAA_PC 1

#include "Fxaa3_11.h"

//texture

texture ScreenTexture;





sampler2D TextureSampler = sampler_state    

{   

    Texture = <ScreenTexture>;   

    MinFilter = Linear;   

    MagFilter = Linear;   

    MipFilter = Linear;   

    AddressU = Clamp;   

    AddressV = Clamp;   

};   





float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0

{

    float4 color = tex2D(TextureSampler, TextureCoordinate);

    return color;

}

technique TransformTexture

{

    pass P0

    {

        PixelShader  = compile ps_2_0 PixelShaderFunction();

    }

}









I'd like to simplify the Fxaa3_11.h file but not sure what I can and cannot remove since all the methods have inputs to handle every major platform.

#13 B_old   Members   -  Reputation: 158

Like
0Likes
Like

Posted 02 September 2011 - 11:18 AM

Placing the define after the inclusion of the FXAA.h makes no sense though, I believe.
The function you want to call inside your full screen pass is FxaaPixelShader. Try defining #define FXAA_QUALITY__PRESET 10 and see if it helps, as ATEFred said something about running out of instructions.

#14 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 02 September 2011 - 11:29 AM

View PostB_old, on 02 September 2011 - 11:18 AM, said:

Placing the define after the inclusion of the FXAA.h makes no sense though, I believe.
The function you want to call inside your full screen pass is FxaaPixelShader. Try defining #define FXAA_QUALITY__PRESET 10 and see if it helps, as ATEFred said something about running out of instructions.

If I replace #define FXAA_PC 1 with #define FXAA_QUALITY__PRESET 10 it compiles. Should I have added the define or replaced it?

#15 B_old   Members   -  Reputation: 158

Like
0Likes
Like

Posted 02 September 2011 - 11:40 AM

Adding it.
BTW, how are you compiling your shaders? Shouldn't there be a way to see the compile errors?

#16 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 02 September 2011 - 12:08 PM

Ok, I kind of got something going here with my simple pixel shader I posted earlier. I noticed in the Fxaa3_11.h file there are defines for HLSL versions ( #define FXAA_HLSL_3, 4 and 5) but there is no SM 2.0 define. If I switch my PS to:


#define FXAA_PC 1
#define FXAA_QUALITY__PRESET 10
#define FXAA_HLSL_3 1
#include "Fxaa3_11.h"



//texture
texture ScreenTexture;


sampler2D TextureSampler = sampler_state    
{   
    Texture = <ScreenTexture>;   
    MinFilter = Linear;   
    MagFilter = Linear;   
    MipFilter = Linear;   
    AddressU = Clamp;   
    AddressV = Clamp;   
};   

 

float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0
{
    float4 color = tex2D(TextureSampler, TextureCoordinate);

    float value = (color.r + color.g + color.b) / 3; 
    color.r = value;
    color.g = value;
    color.b = value;

    return color;
}

technique TransformTexture
{
    pass P0
    {

        PixelShader  = compile ps_3_0 PixelShaderFunction();
    }
}







It compiles but now I'm only getting one color returned and I havn't called any FXAA methods. I need to look at the specs on SM 3 vers SM 2 to see what's going on with that.

I wonder if an older version of FXAA supports SM 2.0? At this time the 3_11 version of FXAA does not. I'm not sure if I can get the requirments lifted to SM 3.0 and how will that impact other areas of this project.

At least I've made "some" progress : - /


Any input would be greatly appreciated....

#17 B_old   Members   -  Reputation: 158

Like
0Likes
Like

Posted 02 September 2011 - 12:13 PM

Oh, I assumed not defining a SM version would default to 2. Seem that I was wrong.
What do you mean by only getting one color returned? Your shader looks like it outputs different shades of gray.

#18 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 02 September 2011 - 12:22 PM

View PostB_old, on 02 September 2011 - 12:13 PM, said:

Oh, I assumed not defining a SM version would default to 2. Seem that I was wrong.
What do you mean by only getting one color returned? Your shader looks like it outputs different shades of gray.

Actully it's returning a black and white image. I passed in a simple cloud texture and it when it's Sm 2.0 it returns the texture black and white like it should. When I switch to Sm 3 it returns one color for the entire image.

SM 2.0:

Posted Image






SM 3.0:
Posted Image

#19 B_old   Members   -  Reputation: 158

Like
0Likes
Like

Posted 02 September 2011 - 02:04 PM

Are you getting the same result if you don't include any of the FXAA stuff?

#20 DJTN   Members   -  Reputation: 118

Like
0Likes
Like

Posted 02 September 2011 - 02:18 PM

View PostB_old, on 02 September 2011 - 02:04 PM, said:

Are you getting the same result if you don't include any of the FXAA stuff?

Yes, I think the issue is that you cannot ignore a vertex shader on a PS 3.0 target. To make sure FXAA wold work with my current rig, I simply rendered everything to a rendertarget/surface and then took that texture and used the Sprite class to draw a full screen sprite with that texture. It works fine for PS 2.0 but not 3.0.

Uggg it's one probelm after another.






We are working on generating results for this topic
PARTNERS