• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
trock3155

FXAA Woes

4 posts in this topic

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:

[img]http://i573.photobucket.com/albums/ss178/trock3155/Aliasing1.png[/img]
[img]http://i573.photobucket.com/albums/ss178/trock3155/Aliasing2.png[/img]

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.

[font=arial,helvetica,sans-serif]Renderer Call:[/font]
[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]

[font=arial, sans-serif][size=3]"finalCombinedEffect" Pixel Shader (where Luma is encoded):[/size][/font]
[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]

[font=arial, sans-serif][size=3]FXAAShader:[/size][/font]
[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));
}

//Technique
technique Default
{
pass p0
{
PixelShader = compile ps_3_0 PS();
}
}[/source]
0

Share this post


Link to post
Share on other sites
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.
1

Share this post


Link to post
Share on other sites
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):[color=rgb(34,34,34)][background=rgb(255,255,255)]
uniform extern float SCREEN_WIDTH;[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
uniform extern float SCREEN_HEIGHT;[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
uniform extern texture gScreenTexture;[/background][/color]
[color=rgb(34,34,34)][background=rgb(255,255,255)]
sampler screenSampler = sampler_state[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
{[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
Texture = <gScreenTexture>;[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
MinFilter = POINT;[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
MagFilter = POINT;[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
MipFilter = POINT;[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
AddressU = Clamp;[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
AddressV = Clamp;[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
};[/background][/color]
[color=rgb(34,34,34)][background=rgb(255,255,255)]
#define FXAA_PC 1[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
//#define FXAA_GREEN_AS_LUMA 1[/background][/color]
[color=rgb(34,34,34)][background=rgb(255,255,255)]
#if SHADER_MODEL >= 0x400[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
#if SHADER_MODEL >= 0x500[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
#define FXAA_HLSL_5 1[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
#else [/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
#define FXAA_HLSL_4 1[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
#endif[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
#elif SHADER_MODEL <= 0x300[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
#define FXAA_HLSL_3 1[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
#endif[/background][/color]
[color=rgb(34,34,34)][background=rgb(255,255,255)]
#include "Fxaa3_11.h"[/background][/color]
[color=rgb(34,34,34)][background=rgb(255,255,255)]
float4 PS(float2 tc : TEXCOORD0) : COLOR0[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
{[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
float pixelWidth = (1 / SCREEN_WIDTH);[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
float pixelHeight = (1 / SCREEN_HEIGHT);[/background][/color]
[color=rgb(34,34,34)][background=rgb(255,255,255)]
float2 pixelCenter = float2(tc.x, tc.y);[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
float4 fxaaConsolePosPos = float4(tc.x - .5f, tc.y - .5f, [/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
tc.x + .5f, tc.y + .5f);[/background][/color]
[color=rgb(34,34,34)][background=rgb(255,255,255)]
//return tex2D(screenSampler, tc);[/background][/color]
[color=rgb(34,34,34)][background=rgb(255,255,255)]
return FxaaPixelShader([/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
tc,[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
fxaaConsolePosPos,[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
screenSampler,[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
screenSampler,[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
screenSampler,[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
float2(1.0f/SCREEN_WIDTH, 1.0f/SCREEN_HEIGHT),[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
float4(2.0 / SCREEN_WIDTH, 2.0 / SCREEN_HEIGHT, .5 / SCREEN_WIDTH, .5 / SCREEN_HEIGHT),[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
float4(0,0,0,0),[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
float4(0,0,0,0),[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
.75f,[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
.166f,[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
.08f,[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
8.0f,[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
.125f,[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
.05f,[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
float4(0,0,0,0));[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
}[/background][/color]
[color=rgb(34,34,34)][background=rgb(255,255,255)]
//Technique[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
technique Default[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
{[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
pass p0[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
{[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
PixelShader = compile ps_3_0 PS();[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
}[/background][/color][color=rgb(34,34,34)][background=rgb(255,255,255)]
}[/background][/color]
0

Share this post


Link to post
Share on other sites
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.
0

Share this post


Link to post
Share on other sites
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:

[img]http://i573.photobucket.com/albums/ss178/trock3155/Aliasing3.png[/img]

[CODE]
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();
}
}
[/CODE]
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0