Move default render target handling to CDriverUser
--HG-- branch : multipass-stereohg/feature/qt5
parent
e88dedf00c
commit
d98f1ede47
@ -0,0 +1,82 @@
|
||||
/**
|
||||
* \file fxaa.h
|
||||
* \brief CFXAA
|
||||
* \date 2014-08-03 21:41GMT
|
||||
* \author Jan Boon (Kaetemi)
|
||||
* CFXAA
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014 by authors
|
||||
*
|
||||
* This file is part of NL3D.
|
||||
* NL3D is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* NL3D is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with NL3D. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef NL3D_FXAA_H
|
||||
#define NL3D_FXAA_H
|
||||
#include <nel/misc/types_nl.h>
|
||||
|
||||
// STL includes
|
||||
|
||||
// NeL includes
|
||||
#include <nel/misc/smart_ptr.h>
|
||||
#include <nel/misc/geom_ext.h>
|
||||
|
||||
// Project includes
|
||||
#include <nel/3d/u_material.h>
|
||||
#include <nel/3d/vertex_buffer.h>
|
||||
|
||||
#define NL_STEREO_MAX_USER_CAMERAS 8
|
||||
|
||||
namespace NL3D {
|
||||
|
||||
class ITexture;
|
||||
class CTextureUser;
|
||||
class CPixelProgram;
|
||||
|
||||
/**
|
||||
* \brief CFXAA
|
||||
* \date 2014-08-03 21:41GMT
|
||||
* \author Jan Boon (Kaetemi)
|
||||
* CFXAA
|
||||
*/
|
||||
class CFXAA
|
||||
{
|
||||
public:
|
||||
CFXAA(NL3D::UDriver *driver);
|
||||
virtual ~CFXAA();
|
||||
|
||||
/// Apply effect to current render target. Render target must be managed by render target manager
|
||||
virtual void applyEffect();
|
||||
|
||||
private:
|
||||
UDriver *m_Driver;
|
||||
|
||||
NL3D::UMaterial m_Mat;
|
||||
NL3D::CVertexBuffer m_VB;
|
||||
NLMISC::CQuadUV m_QuadUV;
|
||||
CPixelProgram *m_PP;
|
||||
|
||||
uint m_Width;
|
||||
uint m_Height;
|
||||
|
||||
}; /* class CFXAA */
|
||||
|
||||
} /* namespace NL3D */
|
||||
|
||||
#endif /* #ifndef NL3D_FXAA_H */
|
||||
|
||||
/* end of file */
|
@ -0,0 +1,196 @@
|
||||
/**
|
||||
* \file fxaa.cpp
|
||||
* \brief CFXAA
|
||||
* \date 2014-08-03 21:41GMT
|
||||
* \author Jan Boon (Kaetemi)
|
||||
* CFXAA
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (C) 2014 by authors
|
||||
*
|
||||
* This file is part of NL3D.
|
||||
* NL3D is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* NL3D is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public
|
||||
* License along with NL3D. If not, see
|
||||
* <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <nel/misc/types_nl.h>
|
||||
#include <nel/3d/fxaa.h>
|
||||
|
||||
// STL includes
|
||||
|
||||
// NeL includes
|
||||
// #include <nel/misc/debug.h>
|
||||
|
||||
// Project includes
|
||||
#include <nel/3d/u_camera.h>
|
||||
#include <nel/3d/u_driver.h>
|
||||
#include <nel/3d/material.h>
|
||||
#include <nel/3d/texture_bloom.h>
|
||||
#include <nel/3d/texture_user.h>
|
||||
#include <nel/3d/driver_user.h>
|
||||
#include <nel/3d/u_texture.h>
|
||||
#include <nel/3d/render_target_manager.h>
|
||||
|
||||
using namespace std;
|
||||
// using namespace NLMISC;
|
||||
|
||||
namespace NL3D {
|
||||
|
||||
namespace {
|
||||
|
||||
#include "fxaa_program.h"
|
||||
|
||||
} /* anonymous namespace */
|
||||
|
||||
CFXAA::CFXAA(NL3D::UDriver *driver) : m_Driver(driver), m_PP(NULL), m_Width(~0), m_Height(~0)
|
||||
{
|
||||
nldebug("3D: Create FXAA");
|
||||
|
||||
CDriverUser *dru = static_cast<CDriverUser *>(driver);
|
||||
NL3D::IDriver *drv = (dru)->getDriver();
|
||||
|
||||
if (drv->supportBloomEffect() && drv->supportNonPowerOfTwoTextures())
|
||||
{
|
||||
m_PP = new CPixelProgram();
|
||||
// arbfp1
|
||||
{
|
||||
IProgram::CSource *source = new IProgram::CSource();
|
||||
source->Features.MaterialFlags = CProgramFeatures::TextureStages;
|
||||
source->Profile = IProgram::arbfp1;
|
||||
source->setSourcePtr(a_arbfp1);
|
||||
m_PP->addSource(source);
|
||||
}
|
||||
// ps_2_0
|
||||
{
|
||||
IProgram::CSource *source = new IProgram::CSource();
|
||||
source->Features.MaterialFlags = CProgramFeatures::TextureStages;
|
||||
source->Profile = IProgram::ps_2_0;
|
||||
source->setSourcePtr(a_ps_2_0);
|
||||
m_PP->addSource(source);
|
||||
}
|
||||
if (!drv->compilePixelProgram(m_PP))
|
||||
{
|
||||
nlwarning("No supported pixel program for FXAA effect");
|
||||
|
||||
delete m_PP;
|
||||
m_PP = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (m_PP)
|
||||
{
|
||||
m_Mat = m_Driver->createMaterial();
|
||||
m_Mat.initUnlit();
|
||||
m_Mat.setColor(CRGBA::White);
|
||||
m_Mat.setBlend (false);
|
||||
m_Mat.setAlphaTest (false);
|
||||
NL3D::CMaterial *mat = m_Mat.getObjectPtr();
|
||||
mat->setShader(NL3D::CMaterial::Normal);
|
||||
mat->setBlendFunc(CMaterial::one, CMaterial::zero);
|
||||
mat->setZWrite(false);
|
||||
mat->setZFunc(CMaterial::always);
|
||||
mat->setDoubleSided(true);
|
||||
|
||||
m_QuadUV.V0 = CVector(0.f, 0.f, 0.5f);
|
||||
m_QuadUV.V1 = CVector(1.f, 0.f, 0.5f);
|
||||
m_QuadUV.V2 = CVector(1.f, 1.f, 0.5f);
|
||||
m_QuadUV.V3 = CVector(0.f, 1.f, 0.5f);
|
||||
|
||||
m_QuadUV.Uv0 = CUV(0.f, 0.f);
|
||||
m_QuadUV.Uv1 = CUV(1.f, 0.f);
|
||||
m_QuadUV.Uv2 = CUV(1.f, 1.f);
|
||||
m_QuadUV.Uv3 = CUV(0.f, 1.f);
|
||||
|
||||
CVertexBuffer &vb = m_VB;
|
||||
vb.clearValueEx();
|
||||
vb.addValueEx(CVertexBuffer::Position, CVertexBuffer::Float3);
|
||||
vb.addValueEx(CVertexBuffer::TexCoord0, CVertexBuffer::Float2);
|
||||
vb.addValueEx(CVertexBuffer::TexCoord1, CVertexBuffer::Float4);
|
||||
vb.initEx();
|
||||
vb.setPreferredMemory(CVertexBuffer::AGPPreferred, false);
|
||||
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);*/
|
||||
}
|
||||
}
|
||||
|
||||
CFXAA::~CFXAA()
|
||||
{
|
||||
nldebug("3D: Destroy FXAA");
|
||||
|
||||
if (!m_Mat.empty())
|
||||
{
|
||||
m_Driver->deleteMaterial(m_Mat);
|
||||
}
|
||||
|
||||
delete m_PP;
|
||||
m_PP = NULL;
|
||||
|
||||
m_Driver = NULL;
|
||||
}
|
||||
|
||||
void CFXAA::applyEffect()
|
||||
{
|
||||
if (!m_PP)
|
||||
return;
|
||||
|
||||
CDriverUser *dru = static_cast<CDriverUser *>(m_Driver);
|
||||
IDriver *drv = dru->getDriver();
|
||||
|
||||
NL3D::ITexture *renderTarget = drv->getRenderTarget();
|
||||
nlassert(renderTarget);
|
||||
nlassert(renderTarget->isBloomTexture());
|
||||
|
||||
uint width = renderTarget->getWidth();
|
||||
uint height = renderTarget->getHeight();
|
||||
bool mode2D = static_cast<CTextureBloom *>(renderTarget)->isMode2D();
|
||||
nlassert(renderTarget->getUploadFormat() == ITexture::Auto);
|
||||
|
||||
float fwidth = (float)width;
|
||||
float fheight = (float)height;
|
||||
|
||||
// create render target
|
||||
CTextureUser *otherRenderTarget = m_Driver->getRenderTargetManager().getRenderTarget(width, height, mode2D);
|
||||
|
||||
// swap render target
|
||||
CTextureUser texNull;
|
||||
dru->setRenderTarget(texNull);
|
||||
drv->swapTextureHandle(*renderTarget, *otherRenderTarget->getITexture());
|
||||
drv->setRenderTarget(renderTarget);
|
||||
|
||||
// render effect
|
||||
m_Mat.getObjectPtr()->setTexture(0, otherRenderTarget->getITexture());
|
||||
m_Driver->drawQuad(m_QuadUV, m_Mat);
|
||||
m_Mat.getObjectPtr()->setTexture(0, NULL);
|
||||
|
||||
// recycle render target
|
||||
m_Driver->getRenderTargetManager().recycleRenderTarget(otherRenderTarget);
|
||||
}
|
||||
|
||||
} /* namespace NL3D */
|
||||
|
||||
/* end of file */
|
@ -0,0 +1,168 @@
|
||||
|
||||
const char *a_arbfp1 =
|
||||
"!!ARBfp1.0\n"
|
||||
//"# cgc version 3.1.0013, build date Apr 18 2012\n"
|
||||
//"# command line args: -profile arbfp1\n"
|
||||
//"# source file: fxaa_fp.cg\n"
|
||||
//"#vendor NVIDIA Corporation\n"
|
||||
//"#version 3.1.0.13\n"
|
||||
//"#profile arbfp1\n"
|
||||
//"#program fxaa_fp\n"
|
||||
//"#semantic fxaa_fp.fxaaConsoleRcpFrameOpt\n"
|
||||
//"#semantic fxaa_fp.fxaaConsoleRcpFrameOpt2\n"
|
||||
//"#semantic fxaa_fp.nlTex0 : TEX0\n"
|
||||
//"#var float2 pos : $vin.TEXCOORD0 : TEX0 : 0 : 1\n"
|
||||
//"#var float4 fxaaConsolePosPos : $vin.TEXCOORD1 : TEX1 : 1 : 1\n"
|
||||
//"#var float4 fxaaConsoleRcpFrameOpt : : c[0] : 2 : 1\n"
|
||||
//"#var float4 fxaaConsoleRcpFrameOpt2 : : c[1] : 3 : 1\n"
|
||||
//"#var sampler2D nlTex0 : TEX0 : texunit 0 : 4 : 1\n"
|
||||
//"#var float4 oCol : $vout.COLOR : COL : 5 : 1\n"
|
||||
//"#const c[2] = 0.125 0 8 0.001953125\n"
|
||||
//"#const c[3] = -2 2 0.5\n"
|
||||
"PARAM c[4] = { program.env[0..1],\n"
|
||||
" { 0.125, 0, 8, 0.001953125 },\n"
|
||||
" { -2, 2, 0.5 } };\n"
|
||||
"TEMP R0;\n"
|
||||
"TEMP R1;\n"
|
||||
"TEMP R2;\n"
|
||||
"TEMP R3;\n"
|
||||
"TEMP R4;\n"
|
||||
"TEMP R5;\n"
|
||||
"TEX R0.w, fragment.texcoord[1].zyzw, texture[0], 2D;\n"
|
||||
"ADD R0.x, R0.w, c[2].w;\n"
|
||||
"TEX R1.w, fragment.texcoord[1].xwzw, texture[0], 2D;\n"
|
||||
"TEX R0.w, fragment.texcoord[1], texture[0], 2D;\n"
|
||||
"ADD R0.y, R1.w, -R0.x;\n"
|
||||
"ADD R0.z, R0.w, R0.y;\n"
|
||||
"TEX R2.w, fragment.texcoord[1].zwzw, texture[0], 2D;\n"
|
||||
"ADD R0.y, -R0.w, R0;\n"
|
||||
"ADD R1.z, -R2.w, R0;\n"
|
||||
"ADD R1.x, R2.w, R0.y;\n"
|
||||
"MOV R1.y, c[2];\n"
|
||||
"DP3 R0.y, R1, R1;\n"
|
||||
"RSQ R0.y, R0.y;\n"
|
||||
"MUL R2.xy, R0.y, R1.xzzw;\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[3].y;\n"
|
||||
"MIN R0.y, R0.w, R1.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[3].x;\n"
|
||||
"MAD R2.xy, R1, c[1].zwzw, fragment.texcoord[0];\n"
|
||||
"MAD R1.xy, -R1, c[1].zwzw, fragment.texcoord[0];\n"
|
||||
"MUL R5, R3, c[3].z;\n"
|
||||
"TEX R4, R2, texture[0], 2D;\n"
|
||||
"TEX R3, R1, texture[0], 2D;\n"
|
||||
"MIN R0.z, R0.x, R2.w;\n"
|
||||
"MIN R1.x, R0.y, R0.z;\n"
|
||||
"MAX R0.y, R0.x, R2.w;\n"
|
||||
"MAX R0.x, R0.w, R1.w;\n"
|
||||
"MAX R2.x, R0, R0.y;\n"
|
||||
"ADD R3, R3, R4;\n"
|
||||
"MAD R3, R3, c[3].z, R5;\n"
|
||||
"MUL R3, R3, c[3].z;\n"
|
||||
"SLT R1.z, R2.x, R3.w;\n"
|
||||
"SLT R1.y, R3.w, R1.x;\n"
|
||||
"TEX R0, fragment.texcoord[0], texture[0], 2D;\n"
|
||||
"ADD_SAT R1.y, R1, R1.z;\n"
|
||||
"MIN R1.z, R0.w, R1.x;\n"
|
||||
"MAX R1.x, R2, R0.w;\n"
|
||||
"ADD R2.y, R1.x, -R1.z;\n"
|
||||
"CMP R1, -R1.y, R5, R3;\n"
|
||||
"MAD R2.x, R2.y, c[2].z, -R2;\n"
|
||||
"CMP result.color, R2.x, R0, R1;\n"
|
||||
"END\n";
|
||||
//"# 51 instructions, 6 R-regs\n"
|
||||
|
||||
const char *a_ps_2_0 =
|
||||
"ps_2_x\n"
|
||||
// cgc version 3.1.0013, build date Apr 18 2012
|
||||
// command line args: -profile ps_2_x
|
||||
// source file: fxaa_fp.cg
|
||||
//vendor NVIDIA Corporation
|
||||
//version 3.1.0.13
|
||||
//profile ps_2_x
|
||||
//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.001953125 0 0.125 2
|
||||
//const c[3] = -2 0.5 0 1
|
||||
//const c[4] = 8
|
||||
"dcl_2d s0\n"
|
||||
"def c2, 0.00195313, 0.00000000, 0.12500000, 2.00000000\n"
|
||||
"def c3, -2.00000000, 0.50000000, 0.00000000, 1.00000000\n"
|
||||
"def c4, 8.00000000, 0, 0, 0\n"
|
||||
"dcl t1\n"
|
||||
"dcl t0.xy\n"
|
||||
"mov r0.xy, t1.zyzw\n"
|
||||
"texld r0, r0, s0\n"
|
||||
"mov r0.xy, t1.xwzw\n"
|
||||
"texld r5, t1, s0\n"
|
||||
"texld r4, r0, s0\n"
|
||||
"add r4.x, r0.w, c2\n"
|
||||
"mov r0.xy, t1.zwzw\n"
|
||||
"texld r3, r0, s0\n"
|
||||
"add r0.w, r4, -r4.x\n"
|
||||
"add r0.x, r5.w, r0.w\n"
|
||||
"add r0.z, -r3.w, r0.x\n"
|
||||
"add r0.x, -r5.w, r0.w\n"
|
||||
"add r0.x, r3.w, r0\n"
|
||||
"mov r0.y, c2\n"
|
||||
"dp3 r0.y, r0, r0\n"
|
||||
"rsq r0.y, r0.y\n"
|
||||
"mul r0.zw, r0.y, r0.xyxz\n"
|
||||
"mad r1.xy, -r0.zwzw, c0.zwzw, t0\n"
|
||||
"texld r1, r1, s0\n"
|
||||
"abs r0.y, r0.w\n"
|
||||
"abs r0.x, r0.z\n"
|
||||
"min r0.x, r0, r0.y\n"
|
||||
"rcp r0.x, r0.x\n"
|
||||
"mul r0.xy, r0.x, r0.zwzw\n"
|
||||
"mul r0.xy, r0, c2.z\n"
|
||||
"min r2.xy, r0, c2.w\n"
|
||||
"mad r0.xy, r0.zwzw, c0.zwzw, t0\n"
|
||||
"texld r0, r0, s0\n"
|
||||
"add r0, r1, r0\n"
|
||||
"max r1.xy, r2, c3.x\n"
|
||||
"mul r2, r0, c3.y\n"
|
||||
"mad r0.xy, r1, c1.zwzw, t0\n"
|
||||
"mad r1.xy, -r1, c1.zwzw, t0\n"
|
||||
"texld r0, r0, s0\n"
|
||||
"texld r1, r1, s0\n"
|
||||
"add r0, r1, r0\n"
|
||||
"mad r0, r0, c3.y, r2\n"
|
||||
"mul r1, r0, c3.y\n"
|
||||
"min r0.y, r4.x, r3.w\n"
|
||||
"min r0.x, r5.w, r4.w\n"
|
||||
"min r3.y, r0.x, r0\n"
|
||||
"add r0.x, -r3.y, r1.w\n"
|
||||
"max r0.z, r4.x, r3.w\n"
|
||||
"max r0.y, r5.w, r4.w\n"
|
||||
"max r3.x, r0.y, r0.z\n"
|
||||
"cmp r3.z, r0.x, c3, c3.w\n"
|
||||
"add r3.w, r3.x, -r1\n"
|
||||
"cmp r3.w, r3, c3.z, c3\n"
|
||||
"add_pp_sat r3.z, r3, r3.w\n"
|
||||
"texld r0, t0, s0\n"
|
||||
"min r3.w, r0, r3.y\n"
|
||||
"max r3.y, r3.x, r0.w\n"
|
||||
"cmp r1, -r3.z, r1, r2\n"
|
||||
"add r3.y, r3, -r3.w\n"
|
||||
"mad r2.x, r3.y, c4, -r3\n"
|
||||
"cmp r0, r2.x, r1, r0\n"
|
||||
"mov oC0, r0\n";
|
Loading…
Reference in New Issue