3D: Add FXAA

This commit is contained in:
kaetemi 2014-08-04 04:44:27 +02:00
parent 2bd1d8a071
commit b9b497fc1f
14 changed files with 2661 additions and 34 deletions

View file

@ -46,6 +46,7 @@ namespace NL3D {
class ITexture; class ITexture;
class CTextureUser; class CTextureUser;
class CPixelProgram; class CPixelProgram;
class CVertexProgram;
/** /**
* \brief CFXAA * \brief CFXAA
@ -66,8 +67,9 @@ private:
UDriver *m_Driver; UDriver *m_Driver;
NL3D::UMaterial m_Mat; NL3D::UMaterial m_Mat;
NL3D::CVertexBuffer m_VB; // NL3D::CVertexBuffer m_VB;
NLMISC::CQuadUV m_QuadUV; NLMISC::CQuadUV m_QuadUV;
CVertexProgram *m_VP;
CPixelProgram *m_PP; CPixelProgram *m_PP;
uint m_Width; uint m_Width;

View file

@ -264,6 +264,7 @@ void CBloomEffect::applyBloom()
CRect rect1(0, 0, width, height); CRect rect1(0, 0, width, height);
CRect rect2(0, 0, _BlurWidth, _BlurHeight); CRect rect2(0, 0, _BlurWidth, _BlurHeight);
dru->stretchRect(_Scene, txt1, rect1, txt2, rect2); dru->stretchRect(_Scene, txt1, rect1, txt2, rect2);
_Driver->setMatrixMode2D11();
// horizontal blur pass // horizontal blur pass
doBlur(true); doBlur(true);
@ -319,10 +320,7 @@ void CBloomEffect::applyBlur()
matObjectFinal->texConstantColor(0, constCoeff); matObjectFinal->texConstantColor(0, constCoeff);
// display quad // display quad
UCamera pCam = _Scene->getCam();
_Driver->setMatrixMode2D11();
_Driver->drawQuad(_BlurQuad, displayBlurMat); _Driver->drawQuad(_BlurQuad, displayBlurMat);
_Driver->setMatrixMode3D(pCam);
// disable vertex program // disable vertex program
drvInternal->activeVertexProgram(NULL); drvInternal->activeVertexProgram(NULL);
@ -404,15 +402,12 @@ void CBloomEffect::doBlur(bool horizontalBlur)
matObject->setTexture(3, startTexture); matObject->setTexture(3, startTexture);
// display // display
UCamera pCam = _Scene->getCam();
_Driver->setMatrixMode2D11();
_Driver->drawQuad(_BlurQuad, _BlurMat); _Driver->drawQuad(_BlurQuad, _BlurMat);
// disable render target and vertex program // disable render target and vertex program
drvInternal->activeVertexProgram(NULL); drvInternal->activeVertexProgram(NULL);
CTextureUser cu; CTextureUser cu;
((CDriverUser *)_Driver)->setRenderTarget(cu, 0, 0, 0, 0); ((CDriverUser *)_Driver)->setRenderTarget(cu, 0, 0, 0, 0);
_Driver->setMatrixMode3D(pCam);
} }
}; // NL3D }; // NL3D

View file

@ -54,7 +54,7 @@ namespace {
} /* anonymous namespace */ } /* anonymous namespace */
CFXAA::CFXAA(NL3D::UDriver *driver) : m_Driver(driver), m_PP(NULL), m_Width(~0), m_Height(~0) CFXAA::CFXAA(NL3D::UDriver *driver) : m_Driver(driver), m_PP(NULL), m_VP(NULL), m_Width(~0), m_Height(~0)
{ {
nldebug("3D: Create FXAA"); nldebug("3D: Create FXAA");
@ -82,14 +82,54 @@ CFXAA::CFXAA(NL3D::UDriver *driver) : m_Driver(driver), m_PP(NULL), m_Width(~0),
} }
if (!drv->compilePixelProgram(m_PP)) if (!drv->compilePixelProgram(m_PP))
{ {
nlwarning("No supported pixel program for FXAA effect"); nlwarning("3D: No supported pixel program for FXAA effect");
delete m_PP; delete m_PP;
m_PP = NULL; m_PP = NULL;
} }
else
{
nldebug("3D: FXAA pixel program available");
}
} }
if (m_PP) if (!m_PP)
{
return;
}
// create vp
{
m_VP = new CVertexProgram();
// nelvp
{
IProgram::CSource *source = new IProgram::CSource();
source->Features.MaterialFlags = CProgramFeatures::TextureStages;
source->Profile = IProgram::nelvp;
source->setSourcePtr(a_nelvp);
m_VP->addSource(source);
}
if (!drv->compileVertexProgram(m_VP))
{
nlwarning("3D: No supported vertex program for FXAA effect");
delete m_VP;
m_VP = NULL;
delete m_PP;
m_PP = NULL;
}
else
{
nldebug("3D: FXAA vertex program available");
}
}
if (!m_VP)
{
return;
}
// create material and vb
{ {
m_Mat = m_Driver->createMaterial(); m_Mat = m_Driver->createMaterial();
m_Mat.initUnlit(); m_Mat.initUnlit();
@ -113,28 +153,14 @@ CFXAA::CFXAA(NL3D::UDriver *driver) : m_Driver(driver), m_PP(NULL), m_Width(~0),
m_QuadUV.Uv2 = CUV(1.f, 1.f); m_QuadUV.Uv2 = CUV(1.f, 1.f);
m_QuadUV.Uv3 = CUV(0.f, 1.f); m_QuadUV.Uv3 = CUV(0.f, 1.f);
CVertexBuffer &vb = m_VB; /*CVertexBuffer &vb = m_VB;
vb.clearValueEx(); vb.clearValueEx();
vb.addValueEx(CVertexBuffer::Position, CVertexBuffer::Float3); vb.addValueEx(CVertexBuffer::Position, CVertexBuffer::Float3);
vb.addValueEx(CVertexBuffer::TexCoord0, CVertexBuffer::Float2); vb.addValueEx(CVertexBuffer::TexCoord0, CVertexBuffer::Float2);
vb.addValueEx(CVertexBuffer::TexCoord1, CVertexBuffer::Float4); vb.addValueEx(CVertexBuffer::TexCoord1, CVertexBuffer::Float4);
vb.initEx(); vb.initEx();
vb.setPreferredMemory(CVertexBuffer::AGPPreferred, false); vb.setPreferredMemory(CVertexBuffer::RAMVolatile, false);
vb.setNumVertices(4); vb.setNumVertices(4);*/
/*CVertexBufferReadWrite vba;
vb.lock(vba);
vba.setVertexCoord(0, 0.f, 0.f, 0.5f);
vba.setVertexCoord(1, 1.f, 0.f, 0.5f);
vba.setVertexCoord(2, 1.f, 1.f, 0.5f);
vba.setVertexCoord(3, 0.f, 1.f, 0.5f);
vba.setTexCoord(0, 0, 0.f, 0.f);
vba.setTexCoord(1, 0, 1.f, 0.f);
vba.setTexCoord(2, 0, 1.f, 1.f);
vba.setTexCoord(3, 0, 0.f, 1.f);*/
/*vba.setTexCoord(0, 1, 0.f, 0.f);
vba.setTexCoord(1, 1, 1.f, 0.f);
vba.setTexCoord(2, 1, 1.f, 1.f);
vba.setTexCoord(3, 1, 0.f, 1.f);*/
} }
} }
@ -147,6 +173,8 @@ CFXAA::~CFXAA()
m_Driver->deleteMaterial(m_Mat); m_Driver->deleteMaterial(m_Mat);
} }
delete m_VP;
m_VP = NULL;
delete m_PP; delete m_PP;
m_PP = NULL; m_PP = NULL;
@ -172,6 +200,33 @@ void CFXAA::applyEffect()
float fwidth = (float)width; float fwidth = (float)width;
float fheight = (float)height; float fheight = (float)height;
nldebug("%f, %f", fwidth, fheight);
float pwidth = 1.0f / fwidth;
float pheight = 1.0f / fheight;
float hpwidth = pwidth * 0.5f;
float hpheight = pheight * 0.5f;
float n = 0.5f;
//if (width != m_Width || height != m_Height)
/*{
// Build VB
m_Width = width;
m_Height = height;
CVertexBufferReadWrite vba;
m_VB.lock(vba);
vba.setValueFloat3Ex(CVertexBuffer::Position, 0, 0.f, 0.f, 0.5f); // BL
vba.setValueFloat3Ex(CVertexBuffer::Position, 1, 1.f, 0.f, 0.5f); // BR
vba.setValueFloat3Ex(CVertexBuffer::Position, 2, 1.f, 1.f, 0.5f); // TR
vba.setValueFloat3Ex(CVertexBuffer::Position, 3, 0.f, 1.f, 0.5f); // TL
vba.setValueFloat2Ex(CVertexBuffer::TexCoord0, 0, 0.f, 0.f);
vba.setValueFloat2Ex(CVertexBuffer::TexCoord0, 1, 1.f, 0.f);
vba.setValueFloat2Ex(CVertexBuffer::TexCoord0, 2, 1.f, 1.f);
vba.setValueFloat2Ex(CVertexBuffer::TexCoord0, 3, 0.f, 1.f);
vba.setValueFloat4Ex(CVertexBuffer::TexCoord1, 0, 0.f - hpwidth, 0.f - hpheight, 0.f + hpwidth, 0.f + hpheight);
vba.setValueFloat4Ex(CVertexBuffer::TexCoord1, 1, 1.f - hpwidth, 0.f - hpheight, 1.f + hpwidth, 0.f + hpheight);
vba.setValueFloat4Ex(CVertexBuffer::TexCoord1, 2, 1.f - hpwidth, 1.f - hpheight, 1.f + hpwidth, 1.f + hpheight);
vba.setValueFloat4Ex(CVertexBuffer::TexCoord1, 3, 0.f - hpwidth, 1.f - hpheight, 0.f + hpwidth, 1.f + hpheight);
}*/
// create render target // create render target
CTextureUser *otherRenderTarget = m_Driver->getRenderTargetManager().getRenderTarget(width, height, mode2D); CTextureUser *otherRenderTarget = m_Driver->getRenderTargetManager().getRenderTarget(width, height, mode2D);
@ -182,11 +237,30 @@ void CFXAA::applyEffect()
drv->swapTextureHandle(*renderTarget, *otherRenderTarget->getITexture()); drv->swapTextureHandle(*renderTarget, *otherRenderTarget->getITexture());
drv->setRenderTarget(renderTarget); drv->setRenderTarget(renderTarget);
// debug
m_Driver->clearBuffers(CRGBA(128, 128, 128, 128));
// activate program
bool vpok = drv->activeVertexProgram(m_VP);
nlassert(vpok);
bool ppok = drv->activePixelProgram(m_PP);
nlassert(ppok);
drv->setUniform4f(IDriver::PixelProgram, 0, -n / fwidth, -n / fheight, n / fwidth, n / fheight); // fxaaConsoleRcpFrameOpt
drv->setUniform4f(IDriver::PixelProgram, 1, -2.0f / fwidth, -2.0f / fheight, 2.0f / fwidth, 2.0f / fheight); // fxaaConsoleRcpFrameOpt2
drv->setUniformMatrix(IDriver::VertexProgram, 0, IDriver::ModelViewProjection, IDriver::Identity);
drv->setUniform4f(IDriver::VertexProgram, 9, -hpwidth, -hpheight, hpwidth, hpheight);
// render effect // render effect
m_Mat.getObjectPtr()->setTexture(0, otherRenderTarget->getITexture()); m_Mat.getObjectPtr()->setTexture(0, otherRenderTarget->getITexture());
/*drv->activeVertexBuffer(m_VB);
drv->renderRawQuads(*m_Mat.getObjectPtr(), 0, 1);*/
m_Driver->drawQuad(m_QuadUV, m_Mat); m_Driver->drawQuad(m_QuadUV, m_Mat);
m_Mat.getObjectPtr()->setTexture(0, NULL); m_Mat.getObjectPtr()->setTexture(0, NULL);
// deactivate program
drv->activeVertexProgram(NULL);
drv->activePixelProgram(NULL);
// recycle render target // recycle render target
m_Driver->getRenderTargetManager().recycleRenderTarget(otherRenderTarget); m_Driver->getRenderTargetManager().recycleRenderTarget(otherRenderTarget);
} }

View file

@ -1,6 +1,101 @@
const char *a_nelvp =
"!!VP1.0\n"
"DP4 o[HPOS].x, c[0], v[OPOS];\n"
"DP4 o[HPOS].y, c[1], v[OPOS];\n"
"DP4 o[HPOS].z, c[2], v[OPOS];\n"
"DP4 o[HPOS].w, c[3], v[OPOS];\n"
"MOV o[TEX0].xy, v[TEX0];\n"
"ADD o[TEX1], v[TEX0].xyxy, c[9];\n"
"END\n";
const char *a_arbfp1_test =
"!!ARBfp1.0\n"
"OPTION ARB_precision_hint_fastest;\n"
"TEX result.color, fragment.texcoord[1].zwzw, texture[0], 2D;\n"
"END\n";
const char *a_arbfp1 = const char *a_arbfp1 =
"!!ARBfp1.0\n" "!!ARBfp1.0\n"
"OPTION ARB_precision_hint_fastest;\n"
//# cgc version 3.1.0013, build date Apr 18 2012
//# command line args: -profile arbfp1 -O3 -fastmath -fastprecision
//# source file: fxaa_fp.cg
//#vendor NVIDIA Corporation
//#version 3.1.0.13
//#profile arbfp1
//#program fxaa_fp
//#semantic fxaa_fp.fxaaConsoleRcpFrameOpt
//#semantic fxaa_fp.fxaaConsoleRcpFrameOpt2
//#semantic fxaa_fp.nlTex0 : TEX0
//#var float2 pos : $vin.TEXCOORD0 : TEX0 : 0 : 1
//#var float4 fxaaConsolePosPos : $vin.TEXCOORD1 : TEX1 : 1 : 1
//#var float4 fxaaConsoleRcpFrameOpt : : c[0] : 2 : 1
//#var float4 fxaaConsoleRcpFrameOpt2 : : c[1] : 3 : 1
//#var sampler2D nlTex0 : TEX0 : texunit 0 : 4 : 1
//#var float4 oCol : $vout.COLOR : COL : 5 : 1
//#const c[2] = 0.125 0 -2 2
//#const c[3] = 0.001953125 0.5
"PARAM c[4] = { program.env[0..1],\n"
" { 0.125, 0, -2, 2 },\n"
" { 0.001953125, 0.5 } };\n"
"TEMP R0;\n"
"TEMP R1;\n"
"TEMP R2;\n"
"TEMP R3;\n"
"TEMP R4;\n"
"TEMP R5;\n"
"TEX R1.w, fragment.texcoord[1].zyzw, texture[0], 2D;\n"
"ADD R0.x, R1.w, c[3];\n"
"TEX R0.w, fragment.texcoord[1].xwzw, texture[0], 2D;\n"
"TEX R1.w, fragment.texcoord[1], texture[0], 2D;\n"
"ADD R0.y, -R0.x, R0.w;\n"
"ADD R0.z, R1.w, R0.y;\n"
"TEX R2.w, fragment.texcoord[1].zwzw, texture[0], 2D;\n"
"ADD R0.y, -R1.w, R0;\n"
"ADD R1.x, R2.w, R0.y;\n"
"ADD R1.y, R0.z, -R2.w;\n"
"MUL R2.xy, R1, R1;\n"
"ADD R0.y, R2.x, R2;\n"
"RSQ R0.y, R0.y;\n"
"MUL R2.xy, R0.y, R1;\n"
"MAD R3.xy, R2, c[0].zwzw, fragment.texcoord[0];\n"
"ABS R0.z, R2.y;\n"
"ABS R0.y, R2.x;\n"
"MIN R0.y, R0, R0.z;\n"
"RCP R0.y, R0.y;\n"
"MUL R1.xy, R0.y, R2;\n"
"MUL R1.xy, R1, c[2].x;\n"
"MIN R1.xy, R1, c[2].w;\n"
"TEX R4, R3, texture[0], 2D;\n"
"MAD R2.xy, -R2, c[0].zwzw, fragment.texcoord[0];\n"
"TEX R3, R2, texture[0], 2D;\n"
"ADD R3, R3, R4;\n"
"MAX R1.xy, R1, c[2].z;\n"
"MAD R2.xy, R1, c[1].zwzw, fragment.texcoord[0];\n"
"MUL R5, R3, c[3].y;\n"
"MAD R1.xy, -R1, c[1].zwzw, fragment.texcoord[0];\n"
"MIN R0.z, R0.x, R2.w;\n"
"MIN R0.y, R0.w, R1.w;\n"
"MIN R0.y, R0, R0.z;\n"
"MAX R0.z, R0.x, R2.w;\n"
"MAX R0.x, R0.w, R1.w;\n"
"MAX R0.x, R0, R0.z;\n"
"TEX R4, R2, texture[0], 2D;\n"
"TEX R3, R1, texture[0], 2D;\n"
"ADD R3, R3, R4;\n"
"MAD R3, R3, c[3].y, R5;\n"
"MUL R3, R3, c[3].y;\n"
"SLT R0.z, R0.x, R3.w;\n"
"SLT R0.x, R3.w, R0.y;\n"
"ADD_SAT R0.x, R0, R0.z;\n"
"CMP result.color, -R0.x, R5, R3;\n"
"END\n";
//# 45 instructions, 6 R-regs
const char *a_arbfp1_earlyexit =
"!!ARBfp1.0\n"
"OPTION ARB_precision_hint_fastest;\n"
//"# cgc version 3.1.0013, build date Apr 18 2012\n" //"# cgc version 3.1.0013, build date Apr 18 2012\n"
//"# command line args: -profile arbfp1\n" //"# command line args: -profile arbfp1\n"
//"# source file: fxaa_fp.cg\n" //"# source file: fxaa_fp.cg\n"
@ -82,7 +177,127 @@ const char *a_arbfp1 =
"END\n"; "END\n";
//"# 51 instructions, 6 R-regs\n" //"# 51 instructions, 6 R-regs\n"
const char *a_ps_2_0_test_t0 =
"ps_2_x\n"
"dcl_2d s0\n"
"dcl t0.xyz\n"
"mov r0.xy, t0.xy\n"
"texld r0, r0, s0\n"
"mov oC0, r0\n";
const char *a_ps_2_0_test_avg =
"ps_2_x\n"
"dcl_2d s0\n"
"def c0, 0.25000000, 0, 0, 0\n"
"dcl t1\n"
"mov r0.xy, t1.xwzw\n"
"mov r1.xy, t1.zyzw\n"
"texld r0, r0, s0\n"
"texld r1, r1, s0\n"
"add r2, r1, r0\n"
"mov r0.xy, t1.zwzw\n"
"texld r1, t1, s0\n"
"texld r0, r0, s0\n"
"add r1, r2, r1\n"
"add r0, r1, r0\n"
"mul r0, r0, c0.x\n"
"mov oC0, r0\n";
const char *a_ps_2_0 = const char *a_ps_2_0 =
"ps_2_0\n"
// cgc version 3.1.0013, build date Apr 18 2012
// command line args: -profile ps_2_0 -O3 -fastmath -fastprecision
// source file: fxaa_pp.cg
//vendor NVIDIA Corporation
//version 3.1.0.13
//profile ps_2_0
//program fxaa_pp
//semantic fxaa_pp.fxaaConsoleRcpFrameOpt
//semantic fxaa_pp.fxaaConsoleRcpFrameOpt2
//semantic fxaa_pp.nlTex0 : TEX0
//var float2 pos : $vin.TEXCOORD0 : TEX0 : 0 : 1
//var float4 fxaaConsolePosPos : $vin.TEXCOORD1 : TEX1 : 1 : 1
//var float4 fxaaConsoleRcpFrameOpt : : c[0] : 2 : 1
//var float4 fxaaConsoleRcpFrameOpt2 : : c[1] : 3 : 1
//var sampler2D nlTex0 : TEX0 : texunit 0 : 4 : 1
//var float4 oCol : $vout.COLOR : COL : 5 : 1
//const c[2] = 0.001953125 0.125 2 -2
//const c[3] = 0.5 0 1
"dcl_2d s0\n"
"def c2, 0.00195313, 0.12500000, 2.00000000, -2.00000000\n"
"def c3, 0.50000000, 0.00000000, 1.00000000, 0\n"
"dcl t1\n"
"dcl t0.xy\n"
"texld r5, t1, s0\n"
"mov r1.y, t1.w\n"
"mov r1.x, t1.z\n"
"mov r2.xy, r1\n"
"mov r0.y, t1.w\n"
"mov r0.x, t1\n"
"mov r1.y, t1\n"
"mov r1.x, t1.z\n"
"texld r1, r1, s0\n"
"texld r0, r0, s0\n"
"texld r6, r2, s0\n"
"add r0.x, r1.w, c2\n"
"add r2.x, -r0, r0.w\n"
"add r1.x, r5.w, r2\n"
"add r2.z, r1.x, -r6.w\n"
"add r2.x, -r5.w, r2\n"
"add r2.x, r6.w, r2\n"
"mov r3.x, r2\n"
"mov r3.y, r2.z\n"
"mov r2.y, r2.z\n"
"mov r1.y, r2.z\n"
"mov r1.x, r2\n"
"mul r1.xy, r3, r1\n"
"add r1.x, r1, r1.y\n"
"rsq r1.x, r1.x\n"
"mul r4.xy, r1.x, r2\n"
"abs r2.x, r4.y\n"
"abs r1.x, r4\n"
"min r1.x, r1, r2\n"
"rcp r1.x, r1.x\n"
"mul r1.xy, r1.x, r4\n"
"mul r1.xy, r1, c2.y\n"
"min r1.xy, r1, c2.z\n"
"max r2.xy, r1, c2.w\n"
"mov r1.y, c1.w\n"
"mov r1.x, c1.z\n"
"mad r3.xy, r2, r1, t0\n"
"mov r1.y, c1.w\n"
"mov r1.x, c1.z\n"
"mad r5.xy, -r2, r1, t0\n"
"mov r1.y, c0.w\n"
"mov r1.x, c0.z\n"
"mad r2.xy, -r4, r1, t0\n"
"mov r1.y, c0.w\n"
"mov r1.x, c0.z\n"
"mad r1.xy, r4, r1, t0\n"
"texld r4, r5, s0\n"
"texld r3, r3, s0\n"
"texld r1, r1, s0\n"
"texld r2, r2, s0\n"
"add r1, r2, r1\n"
"mul r2, r1, c3.x\n"
"add r1, r4, r3\n"
"max r3.x, r0, r6.w\n"
"mad r1, r1, c3.x, r2\n"
"mul r4, r1, c3.x\n"
"max r1.x, r0.w, r5.w\n"
"max r1.x, r1, r3\n"
"add r1.x, -r4.w, r1\n"
"min r3.x, r0.w, r5.w\n"
"min r0.x, r0, r6.w\n"
"min r0.x, r3, r0\n"
"add r0.x, r4.w, -r0\n"
"cmp r1.x, r1, c3.y, c3.z\n"
"cmp r0.x, r0, c3.y, c3.z\n"
"add_pp_sat r0.x, r0, r1\n"
"cmp r0, -r0.x, r4, r2\n"
"mov oC0, r0\n";
const char *a_ps_2_0_earlyexit =
"ps_2_x\n" "ps_2_x\n"
// cgc version 3.1.0013, build date Apr 18 2012 // cgc version 3.1.0013, build date Apr 18 2012
// command line args: -profile ps_2_x // command line args: -profile ps_2_x

View file

@ -0,0 +1,3 @@
cgc -entry fxaa_pp fxaa_pp.cg -profile arbfp1 -O3 -fastmath -fastprecision -o fxaa_pp_arbfp1.txt
cgc -entry fxaa_pp fxaa_pp.cg -profile ps_2_0 -O3 -fastmath -fastprecision -o fxaa_pp_ps_2_0.txt
cgc -entry fxaa_vp fxaa_vp.cg -profile arbvp1 -fastmath -fastprecision -o fxaa_vp_arbvp1.txt

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,70 @@
#define FXAA_PS3 1
#define FXAA_HLSL_3 1
#define FXAA_QUALITY__PRESET 12
#define FXAA_EARLY_EXIT 0
#define h4tex2Dlod tex2Dlod
#define half4 float4
#define half3 float3
#define half2 float2
#define half float
#include "fxaa3_11.h"
void fxaa_pp(
// Per fragment parameters
float2 pos : TEXCOORD0,
float4 fxaaConsolePosPos : TEXCOORD1,
// Fragment program constants
uniform float4 fxaaConsoleRcpFrameOpt,
uniform float4 fxaaConsoleRcpFrameOpt2,
uniform sampler2D nlTex0 : TEX0,
// Output color
out float4 oCol : COLOR
)
{
oCol = FxaaPixelShader(
pos,
fxaaConsolePosPos,
nlTex0,
fxaaConsoleRcpFrameOpt,
fxaaConsoleRcpFrameOpt2
);
}
/*
Have FXAA vertex shader run as a full screen triangle,
and output "pos" and "fxaaConsolePosPos"
such that inputs in the pixel shader provide,
// {xy} = center of pixel
FxaaFloat2 pos,
// {xy__} = upper left of pixel
// {__zw} = lower right of pixel
FxaaFloat4 fxaaConsolePosPos,
*/
// fxaaConsoleRcpFrameOpt:
// Only used on FXAA Console.
// This must be from a constant/uniform.
// This effects sub-pixel AA quality and inversely sharpness.
// Where N ranges between,
// N = 0.50 (default)
// N = 0.33 (sharper)
// {x___} = -N/screenWidthInPixels
// {_y__} = -N/screenHeightInPixels
// {__z_} = N/screenWidthInPixels
// {___w} = N/screenHeightInPixels
// fxaaConsoleRcpFrameOpt2:
// Only used on FXAA Console.
// Not used on 360, but used on PS3 and PC.
// This must be from a constant/uniform.
// {x___} = -2.0/screenWidthInPixels
// {_y__} = -2.0/screenHeightInPixels
// {__z_} = 2.0/screenWidthInPixels
// {___w} = 2.0/screenHeightInPixels

View file

@ -0,0 +1,76 @@
!!ARBfp1.0
OPTION ARB_precision_hint_fastest;
# cgc version 3.1.0013, build date Apr 18 2012
# command line args: -profile arbfp1 -O3 -fastmath -fastprecision
# source file: fxaa_pp.cg
#vendor NVIDIA Corporation
#version 3.1.0.13
#profile arbfp1
#program fxaa_pp
#semantic fxaa_pp.fxaaConsoleRcpFrameOpt
#semantic fxaa_pp.fxaaConsoleRcpFrameOpt2
#semantic fxaa_pp.nlTex0 : TEX0
#var float2 pos : $vin.TEXCOORD0 : TEX0 : 0 : 1
#var float4 fxaaConsolePosPos : $vin.TEXCOORD1 : TEX1 : 1 : 1
#var float4 fxaaConsoleRcpFrameOpt : : c[0] : 2 : 1
#var float4 fxaaConsoleRcpFrameOpt2 : : c[1] : 3 : 1
#var sampler2D nlTex0 : TEX0 : texunit 0 : 4 : 1
#var float4 oCol : $vout.COLOR : COL : 5 : 1
#const c[2] = 0.125 0 -2 2
#const c[3] = 0.001953125 0.5
PARAM c[4] = { program.local[0..1],
{ 0.125, 0, -2, 2 },
{ 0.001953125, 0.5 } };
TEMP R0;
TEMP R1;
TEMP R2;
TEMP R3;
TEMP R4;
TEMP R5;
TEX R1.w, fragment.texcoord[1].zyzw, texture[0], 2D;
ADD R0.x, R1.w, c[3];
TEX R0.w, fragment.texcoord[1].xwzw, texture[0], 2D;
TEX R1.w, fragment.texcoord[1], texture[0], 2D;
ADD R0.y, -R0.x, R0.w;
ADD R0.z, R1.w, R0.y;
TEX R2.w, fragment.texcoord[1].zwzw, texture[0], 2D;
ADD R0.y, -R1.w, R0;
ADD R1.x, R2.w, R0.y;
ADD R1.y, R0.z, -R2.w;
MUL R2.xy, R1, R1;
ADD R0.y, R2.x, R2;
RSQ R0.y, R0.y;
MUL R2.xy, R0.y, R1;
MAD R3.xy, R2, c[0].zwzw, fragment.texcoord[0];
ABS R0.z, R2.y;
ABS R0.y, R2.x;
MIN R0.y, R0, R0.z;
RCP R0.y, R0.y;
MUL R1.xy, R0.y, R2;
MUL R1.xy, R1, c[2].x;
MIN R1.xy, R1, c[2].w;
TEX R4, R3, texture[0], 2D;
MAD R2.xy, -R2, c[0].zwzw, fragment.texcoord[0];
TEX R3, R2, texture[0], 2D;
ADD R3, R3, R4;
MAX R1.xy, R1, c[2].z;
MAD R2.xy, R1, c[1].zwzw, fragment.texcoord[0];
MUL R5, R3, c[3].y;
MAD R1.xy, -R1, c[1].zwzw, fragment.texcoord[0];
MIN R0.z, R0.x, R2.w;
MIN R0.y, R0.w, R1.w;
MIN R0.y, R0, R0.z;
MAX R0.z, R0.x, R2.w;
MAX R0.x, R0.w, R1.w;
MAX R0.x, R0, R0.z;
TEX R4, R2, texture[0], 2D;
TEX R3, R1, texture[0], 2D;
ADD R3, R3, R4;
MAD R3, R3, c[3].y, R5;
MUL R3, R3, c[3].y;
SLT R0.z, R0.x, R3.w;
SLT R0.x, R3.w, R0.y;
ADD_SAT R0.x, R0, R0.z;
CMP result.color, -R0.x, R5, R3;
END
# 45 instructions, 6 R-regs

View file

@ -0,0 +1,92 @@
ps_2_0
// cgc version 3.1.0013, build date Apr 18 2012
// command line args: -profile ps_2_0 -O3 -fastmath -fastprecision
// source file: fxaa_pp.cg
//vendor NVIDIA Corporation
//version 3.1.0.13
//profile ps_2_0
//program fxaa_pp
//semantic fxaa_pp.fxaaConsoleRcpFrameOpt
//semantic fxaa_pp.fxaaConsoleRcpFrameOpt2
//semantic fxaa_pp.nlTex0 : TEX0
//var float2 pos : $vin.TEXCOORD0 : TEX0 : 0 : 1
//var float4 fxaaConsolePosPos : $vin.TEXCOORD1 : TEX1 : 1 : 1
//var float4 fxaaConsoleRcpFrameOpt : : c[0] : 2 : 1
//var float4 fxaaConsoleRcpFrameOpt2 : : c[1] : 3 : 1
//var sampler2D nlTex0 : TEX0 : texunit 0 : 4 : 1
//var float4 oCol : $vout.COLOR : COL : 5 : 1
//const c[2] = 0.001953125 0.125 2 -2
//const c[3] = 0.5 0 1
dcl_2d s0
def c2, 0.00195313, 0.12500000, 2.00000000, -2.00000000
def c3, 0.50000000, 0.00000000, 1.00000000, 0
dcl t1
dcl t0.xy
texld r5, t1, s0
mov r1.y, t1.w
mov r1.x, t1.z
mov r2.xy, r1
mov r0.y, t1.w
mov r0.x, t1
mov r1.y, t1
mov r1.x, t1.z
texld r1, r1, s0
texld r0, r0, s0
texld r6, r2, s0
add r0.x, r1.w, c2
add r2.x, -r0, r0.w
add r1.x, r5.w, r2
add r2.z, r1.x, -r6.w
add r2.x, -r5.w, r2
add r2.x, r6.w, r2
mov r3.x, r2
mov r3.y, r2.z
mov r2.y, r2.z
mov r1.y, r2.z
mov r1.x, r2
mul r1.xy, r3, r1
add r1.x, r1, r1.y
rsq r1.x, r1.x
mul r4.xy, r1.x, r2
abs r2.x, r4.y
abs r1.x, r4
min r1.x, r1, r2
rcp r1.x, r1.x
mul r1.xy, r1.x, r4
mul r1.xy, r1, c2.y
min r1.xy, r1, c2.z
max r2.xy, r1, c2.w
mov r1.y, c1.w
mov r1.x, c1.z
mad r3.xy, r2, r1, t0
mov r1.y, c1.w
mov r1.x, c1.z
mad r5.xy, -r2, r1, t0
mov r1.y, c0.w
mov r1.x, c0.z
mad r2.xy, -r4, r1, t0
mov r1.y, c0.w
mov r1.x, c0.z
mad r1.xy, r4, r1, t0
texld r4, r5, s0
texld r3, r3, s0
texld r1, r1, s0
texld r2, r2, s0
add r1, r2, r1
mul r2, r1, c3.x
add r1, r4, r3
max r3.x, r0, r6.w
mad r1, r1, c3.x, r2
mul r4, r1, c3.x
max r1.x, r0.w, r5.w
max r1.x, r1, r3
add r1.x, -r4.w, r1
min r3.x, r0.w, r5.w
min r0.x, r0, r6.w
min r0.x, r3, r0
add r0.x, r4.w, -r0
cmp r1.x, r1, c3.y, c3.z
cmp r0.x, r0, c3.y, c3.z
add_pp_sat r0.x, r0, r1
cmp r0, -r0.x, r4, r2
mov oC0, r0

View file

@ -0,0 +1,20 @@
void fxaa_vp(
// Per vertex parameters
float3 position : POSITION,
float2 texCoord0 : TEXCOORD0,
// Vertex program constants
uniform float4x4 modelViewProjection,
uniform float4 fxaaConsolePosPos,
// Output position
out float4 oPosition : POSITION,
out float2 oTexCoord0 : TEXCOORD0,
out float4 oTexCoord1 : TEXCOORD1
)
{
oPosition = mul(modelViewProjection, float4(position, 0.0));
oTexCoord0 = texCoord0;
oTexCoord1 = texCoord0.xyxy + fxaaConsolePosPos;
}

View file

@ -0,0 +1,31 @@
!!ARBvp1.0
# cgc version 3.1.0013, build date Apr 18 2012
# command line args: -profile arbvp1 -fastmath -fastprecision
# source file: fxaa_vp.cg
#vendor NVIDIA Corporation
#version 3.1.0.13
#profile arbvp1
#program fxaa_vp
#semantic fxaa_vp.modelViewProjection
#semantic fxaa_vp.fxaaConsolePosPos
#var float3 position : $vin.POSITION : POSITION : 0 : 1
#var float2 texCoord0 : $vin.TEXCOORD0 : TEXCOORD0 : 1 : 1
#var float4x4 modelViewProjection : : c[1], 4 : 2 : 1
#var float4 fxaaConsolePosPos : : c[5] : 3 : 1
#var float4 oPosition : $vout.POSITION : HPOS : 4 : 1
#var float2 oTexCoord0 : $vout.TEXCOORD0 : TEX0 : 5 : 1
#var float4 oTexCoord1 : $vout.TEXCOORD1 : TEX1 : 6 : 1
#const c[0] = 0
PARAM c[6] = { { 0 },
program.local[1..5] };
TEMP R0;
MOV R0.w, c[0].x;
MOV R0.xyz, vertex.position;
DP4 result.position.w, R0, c[4];
DP4 result.position.z, R0, c[3];
DP4 result.position.y, R0, c[2];
DP4 result.position.x, R0, c[1];
ADD result.texcoord[1], vertex.texcoord[0].xyxy, c[5];
MOV result.texcoord[0].xy, vertex.texcoord[0];
END
# 8 instructions, 1 R-regs

View file

@ -0,0 +1,4 @@
Compiled shaders are embedded in the source.
Must compile and re-embed manually.
FXAA is in public domain.

View file

@ -1730,12 +1730,12 @@ bool mainLoop()
{ {
if (effectRender) if (effectRender)
{ {
if (ClientCfg.Bloom) if (StereoDisplay) Driver->setViewport(NL3D::CViewport());
{ UCamera pCam = Scene->getCam();
if (StereoDisplay) Driver->setViewport(NL3D::CViewport()); Driver->setMatrixMode2D11();
CBloomEffect::instance().applyBloom(); if (ClientCfg.Bloom) CBloomEffect::instance().applyBloom();
if (StereoDisplay) Driver->setViewport(StereoDisplay->getCurrentViewport()); Driver->setMatrixMode3D(pCam);
} if (StereoDisplay) Driver->setViewport(StereoDisplay->getCurrentViewport());
effectRender = false; effectRender = false;
} }

View file

@ -801,8 +801,11 @@ void loopIngame()
if (effectRender) if (effectRender)
{ {
if (StereoDisplay) Driver->setViewport(NL3D::CViewport()); if (StereoDisplay) Driver->setViewport(NL3D::CViewport());
if (s_EnableBloom) CBloomEffect::instance().applyBloom(); UCamera pCam = Scene->getCam();
Driver->setMatrixMode2D11();
if (s_FXAA) s_FXAA->applyEffect(); if (s_FXAA) s_FXAA->applyEffect();
if (s_EnableBloom) CBloomEffect::instance().applyBloom();
Driver->setMatrixMode3D(pCam);
if (StereoDisplay) Driver->setViewport(StereoDisplay->getCurrentViewport()); if (StereoDisplay) Driver->setViewport(StereoDisplay->getCurrentViewport());
effectRender = false; effectRender = false;
} }