Move default render target handling to CDriverUser

--HG--
branch : multipass-stereo
This commit is contained in:
kaetemi 2014-08-04 00:57:43 +02:00
parent e88dedf00c
commit d98f1ede47
12 changed files with 605 additions and 107 deletions

View file

@ -109,6 +109,11 @@ protected:
CMaterial _MatTextInternal; CMaterial _MatTextInternal;
CMaterial _MatTextStretchInternal; CMaterial _MatTextStretchInternal;
// Default render target for effect pipeline
CTextureUser *_EffectRenderTarget;
UMaterial _MatRenderTarget;
CMaterial _MatRenderTargetInt;
NLMISC::CQuadUV _RenderTargetQuad;
// StaticInit // StaticInit
static bool _StaticInit; static bool _StaticInit;
@ -242,6 +247,16 @@ public:
// @} // @}
/// Get the render target manager
virtual CRenderTargetManager &getRenderTargetManager() { return _RenderTargetManager; }
/// Set a texture the size of the window as render target
virtual void beginDefaultRenderTarget();
/// Draw the render target to the back buffer
virtual void endDefaultRenderTarget(UScene *scene);
/// \name Components gestion for Interface 2D/3D. /// \name Components gestion for Interface 2D/3D.
// @{ // @{
@ -254,8 +269,6 @@ public:
/// get cahce information. /// get cahce information.
virtual std::string getFontManagerCacheInformation() const ; virtual std::string getFontManagerCacheInformation() const ;
virtual CRenderTargetManager &getRenderTargetManager() { return _RenderTargetManager; }
/** Create a new texture file, searching in CPath. /** Create a new texture file, searching in CPath.
* \param file filename, local to CPath paths. * \param file filename, local to CPath paths.

View file

@ -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 */

View file

@ -307,6 +307,16 @@ public:
// @} // @}
/// Get the render target manager
virtual CRenderTargetManager &getRenderTargetManager() =0;
/// Set a texture the size of the window as render target
virtual void beginDefaultRenderTarget() =0;
/// Draw the render target to the back buffer
virtual void endDefaultRenderTarget(UScene *scene) =0;
/// \name Components gestion for Interface 2D/3D. /// \name Components gestion for Interface 2D/3D.
// @{ // @{
@ -320,8 +330,6 @@ public:
/// get cahce information. /// get cahce information.
virtual std::string getFontManagerCacheInformation() const =0; virtual std::string getFontManagerCacheInformation() const =0;
virtual CRenderTargetManager &getRenderTargetManager() =0;
/** Create a new texture file, searching in CPath. NB: by default a textureFile created with this /** Create a new texture file, searching in CPath. NB: by default a textureFile created with this
* method has a setAllowDegradation() at false. * method has a setAllowDegradation() at false.

View file

@ -195,6 +195,8 @@ CDriverUser::CDriverUser (uintptr_t windowIcon, TDriver driver, emptyProc exitFu
_RenderTargetManager.m_Driver = this; _RenderTargetManager.m_Driver = this;
_ShapeBank._DriverUser = this; _ShapeBank._DriverUser = this;
_EffectRenderTarget = NULL;
NL_SET_IB_NAME(_PBLine, "CDriverUser::_PBLine"); NL_SET_IB_NAME(_PBLine, "CDriverUser::_PBLine");
NL_SET_IB_NAME(_PBTri, "CDriverUser::_PBTri"); NL_SET_IB_NAME(_PBTri, "CDriverUser::_PBTri");
} }

View file

@ -73,6 +73,63 @@ void CDriverUser::deleteScene(UScene *scene)
_Scenes.erase((CSceneUser*)scene, "deleteScene(): Bad scene ptr"); _Scenes.erase((CSceneUser*)scene, "deleteScene(): Bad scene ptr");
} }
// ***************************************************************************
void CDriverUser::beginDefaultRenderTarget()
{
if (_MatRenderTarget.empty())
{
_MatRenderTarget.attach(&_MatRenderTargetInt);
UMaterial &umat = _MatRenderTarget;
CMaterial &mat = _MatRenderTargetInt;
umat.initUnlit();
umat.setColor(CRGBA::White);
umat.setBlend(false);
umat.setAlphaTest(false);
mat.setBlendFunc(CMaterial::one, CMaterial::zero);
mat.setZWrite(false);
mat.setZFunc(CMaterial::always);
mat.setDoubleSided(true);
_RenderTargetQuad.V0 = CVector(0.f, 0.f, 0.5f);
_RenderTargetQuad.V1 = CVector(1.f, 0.f, 0.5f);
_RenderTargetQuad.V2 = CVector(1.f, 1.f, 0.5f);
_RenderTargetQuad.V3 = CVector(0.f, 1.f, 0.5f);
_RenderTargetQuad.Uv0 = CUV(0.f, 0.f);
_RenderTargetQuad.Uv1 = CUV(1.f, 0.f);
_RenderTargetQuad.Uv2 = CUV(1.f, 1.f);
_RenderTargetQuad.Uv3 = CUV(0.f, 1.f);
}
nlassert(!_EffectRenderTarget);
uint32 winw, winh;
getWindowSize(winw, winh);
_EffectRenderTarget = getRenderTargetManager().getRenderTarget(winw, winh);
setRenderTarget(*_EffectRenderTarget);
}
// ***************************************************************************
void CDriverUser::endDefaultRenderTarget(UScene *scene)
{
nlassert(_EffectRenderTarget);
CTextureUser texNull;
setRenderTarget(texNull);
_MatRenderTarget.getObjectPtr()->setTexture(0, _EffectRenderTarget->getITexture());
UCamera pCam = scene->getCam();
setMatrixMode2D11();
drawQuad(_RenderTargetQuad, _MatRenderTarget);
setMatrixMode3D(pCam);
_MatRenderTarget.getObjectPtr()->setTexture(0, NULL);
getRenderTargetManager().recycleRenderTarget(_EffectRenderTarget);
_EffectRenderTarget = NULL;
}
// *************************************************************************** // ***************************************************************************
UTextContext *CDriverUser::createTextContext(const std::string fontFileName, const std::string fontExFileName) UTextContext *CDriverUser::createTextContext(const std::string fontFileName, const std::string fontExFileName)
{ {

196
code/nel/src/3d/fxaa.cpp Normal file
View 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 */

View 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";

View file

@ -137,9 +137,6 @@ std::string LoadingBitmapFilename;
uint64 StartInitTime = 0; uint64 StartInitTime = 0;
uint64 StartPlayTime = 0; uint64 StartPlayTime = 0;
UMaterial EffectMaterial;
NLMISC::CQuadUV EffectQuad;
// texture for the logos // texture for the logos
std::vector<UTextureFile*> LogoBitmaps; std::vector<UTextureFile*> LogoBitmaps;
@ -572,29 +569,6 @@ void initMainLoop()
// use this scene for bloom effect // use this scene for bloom effect
CBloomEffect::getInstance().setScene(Scene); CBloomEffect::getInstance().setScene(Scene);
if (EffectMaterial.empty())
{
EffectMaterial = Driver->createMaterial();
CMaterial *mat = EffectMaterial.getObjectPtr();
EffectMaterial.initUnlit();
EffectMaterial.setColor(CRGBA::White);
EffectMaterial.setBlend(false);
EffectMaterial.setAlphaTest (false);
mat->setBlendFunc(CMaterial::one, CMaterial::zero);
mat->setZWrite(false);
mat->setZFunc(CMaterial::always);
mat->setDoubleSided(true);
}
EffectQuad.V0 = CVector(0.f, 0.f, 0.5f);
EffectQuad.V1 = CVector(1.f, 0.f, 0.5f);
EffectQuad.V2 = CVector(1.f, 1.f, 0.5f);
EffectQuad.V3 = CVector(0.f, 1.f, 0.5f);
EffectQuad.Uv0 = CUV(0.f, 0.f);
EffectQuad.Uv1 = CUV(1.f, 0.f);
EffectQuad.Uv2 = CUV(1.f, 1.f);
EffectQuad.Uv3 = CUV(0.f, 1.f);
CLandscapePolyDrawer::getInstance().initLandscapePolyDrawingCallback(); CLandscapePolyDrawer::getInstance().initLandscapePolyDrawingCallback();

View file

@ -185,9 +185,6 @@ extern std::vector<UTextureFile*> LogoBitmaps;
extern bool IsInRingSession; extern bool IsInRingSession;
extern std::string UsedFSAddr; extern std::string UsedFSAddr;
extern UMaterial EffectMaterial;
extern NLMISC::CQuadUV EffectQuad;
// temp // temp
extern NLMISC::CValueSmoother smoothFPS; extern NLMISC::CValueSmoother smoothFPS;
extern NLMISC::CValueSmoother moreSmoothFPS; extern NLMISC::CValueSmoother moreSmoothFPS;
@ -574,10 +571,7 @@ void renderScene(bool forceFullDetail, bool bloom)
CBloomEffect::getInstance().setDensityBloom((uint8)ClientCfg.DensityBloom); CBloomEffect::getInstance().setDensityBloom((uint8)ClientCfg.DensityBloom);
// init effect render target // init effect render target
uint32 winw, winh; Driver->beginDefaultRenderTarget();
Driver->getWindowSize(winw, winh);
effectRenderTarget = Driver->getRenderTargetManager().getRenderTarget(winw, winh);
static_cast<CDriverUser *>(Driver)->setRenderTarget(*effectRenderTarget);
} }
if (forceFullDetail) if (forceFullDetail)
{ {
@ -596,22 +590,7 @@ void renderScene(bool forceFullDetail, bool bloom)
CBloomEffect::getInstance().applyBloom(); CBloomEffect::getInstance().applyBloom();
// draw final result to backbuffer // draw final result to backbuffer
CDriverUser *dru = static_cast<CDriverUser *>(Driver); Driver->endDefaultRenderTarget(Scene);
CTextureUser texNull;
dru->setRenderTarget(texNull);
EffectMaterial.getObjectPtr()->setTexture(0, effectRenderTarget->getITexture());
UCamera pCam = Scene->getCam();
Driver->setMatrixMode2D11();
Driver->drawQuad(EffectQuad, EffectMaterial);
Driver->setMatrixMode3D(pCam);
EffectMaterial.getObjectPtr()->setTexture(0, NULL);
Driver->getRenderTargetManager().recycleRenderTarget(effectRenderTarget);
effectRenderTarget = NULL;
} }
} }
@ -1650,15 +1629,15 @@ bool mainLoop()
uint i = 0; uint i = 0;
bool effectRender = false; bool effectRender = false;
CTextureUser *effectRenderTarget = NULL; CTextureUser *effectRenderTarget = NULL;
bool haveEffects = Render && ClientCfg.Bloom; bool haveEffects = Render && Driver->getPolygonMode() == UDriver::Filled
&& ClientCfg.Bloom;
bool defaultRenderTarget = false;
if (haveEffects) if (haveEffects)
{ {
if (!StereoDisplay) if (!StereoDisplay)
{ {
uint32 winw, winh; Driver->beginDefaultRenderTarget();
Driver->getWindowSize(winw, winh); defaultRenderTarget = true;
effectRenderTarget = Driver->getRenderTargetManager().getRenderTarget(winw, winh);
static_cast<CDriverUser *>(Driver)->setRenderTarget(*effectRenderTarget);
} }
if (ClientCfg.Bloom) if (ClientCfg.Bloom)
{ {
@ -2199,25 +2178,10 @@ bool mainLoop()
} }
} /* stereo pass */ } /* stereo pass */
if (effectRenderTarget) if (defaultRenderTarget)
{ {
// draw final result to backbuffer // draw final result to backbuffer
CDriverUser *dru = static_cast<CDriverUser *>(Driver); Driver->endDefaultRenderTarget(Scene);
CTextureUser texNull;
dru->setRenderTarget(texNull);
EffectMaterial.getObjectPtr()->setTexture(0, effectRenderTarget->getITexture());
UCamera pCam = Scene->getCam();
Driver->setMatrixMode2D11();
Driver->drawQuad(EffectQuad, EffectMaterial);
Driver->setMatrixMode3D(pCam);
EffectMaterial.getObjectPtr()->setTexture(0, NULL);
Driver->getRenderTargetManager().recycleRenderTarget(effectRenderTarget);
effectRenderTarget = NULL;
} }
// Draw to screen. // Draw to screen.

View file

@ -120,8 +120,6 @@ extern bool userChar;
extern bool serverReceivedReady; extern bool serverReceivedReady;
extern bool CharNameValidArrived; extern bool CharNameValidArrived;
extern UMaterial EffectMaterial;
extern void releaseContextualCursor(); extern void releaseContextualCursor();
extern void selectTipsOfTheDay (uint tips); extern void selectTipsOfTheDay (uint tips);
@ -586,9 +584,6 @@ void release()
// Delete the driver. // Delete the driver.
if(Driver) if(Driver)
{ {
if (!EffectMaterial.empty())
Driver->deleteMaterial(EffectMaterial);
// Release the prim // Release the prim
PrimFiles.release (*Driver); PrimFiles.release (*Driver);

View file

@ -296,7 +296,7 @@ void initCommands()
CommandsMaterial.setBlend(true); CommandsMaterial.setBlend(true);
#if SBCLIENT_DEV_PIXEL_PROGRAM #if SBCLIENT_DEV_PIXEL_PROGRAM
CommandsMaterial.getObjectPtr()->setShader(NL3D::CMaterial::PostProcessing); CommandsMaterial.getObjectPtr()->setShader(NL3D::CMaterial::Program);
a_NelLogo = Driver->createTextureFile("nel128.tga"); a_NelLogo = Driver->createTextureFile("nel128.tga");
CommandsMaterial.setTexture(dynamic_cast<NL3D::UTexture *>(a_NelLogo)); CommandsMaterial.setTexture(dynamic_cast<NL3D::UTexture *>(a_NelLogo));
static const char *program_arbfp1 = static const char *program_arbfp1 =
@ -340,7 +340,24 @@ void initCommands()
"mov oC0.xzw, c0.xyyx\n" "mov oC0.xzw, c0.xyyx\n"
"texld oC0.y, v0, s0\n"; "texld oC0.y, v0, s0\n";
NL3D::IDriver *d = dynamic_cast<NL3D::CDriverUser *>(Driver)->getDriver(); NL3D::IDriver *d = dynamic_cast<NL3D::CDriverUser *>(Driver)->getDriver();
if (d->supportPixelProgram(CPixelProgram::fp40)) a_DevPixelProgram = new CPixelProgram();
// arbfp1
{
IProgram::CSource *source = new IProgram::CSource();
source->Features.MaterialFlags = CProgramFeatures::TextureStages;
source->Profile = IProgram::arbfp1;
source->setSourcePtr(program_arbfp1);
a_DevPixelProgram->addSource(source);
}
// ps_2_0
{
IProgram::CSource *source = new IProgram::CSource();
source->Features.MaterialFlags = CProgramFeatures::TextureStages;
source->Profile = IProgram::ps_2_0;
source->setSourcePtr(program_ps_2_0);
a_DevPixelProgram->addSource(source);
}
/*if (d->supportPixelProgram(CPixelProgram::fp40))
{ {
nldebug("fp40"); nldebug("fp40");
a_DevPixelProgram = new CPixelProgram(program_fp40); a_DevPixelProgram = new CPixelProgram(program_fp40);
@ -349,14 +366,14 @@ void initCommands()
{ {
nldebug("arbfp1"); nldebug("arbfp1");
a_DevPixelProgram = new CPixelProgram(program_arbfp1); a_DevPixelProgram = new CPixelProgram(program_arbfp1);
} }*/
/*else if (d->supportPixelProgram(CPixelProgram::ps_3_0)) /*else if (d->supportPixelProgram(CPixelProgram::ps_3_0))
{ {
nldebug("ps_3_0"); nldebug("ps_3_0");
a_DevPixelProgram = new CPixelProgram(program_ps_3_0); a_DevPixelProgram = new CPixelProgram(program_ps_3_0);
// Textures do not seem to work with ps_3_0... // Textures do not seem to work with ps_3_0...
}*/ }*/
else if (d->supportPixelProgram(CPixelProgram::ps_2_0)) /*else if (d->supportPixelProgram(CPixelProgram::ps_2_0))
{ {
nldebug("ps_2_0"); nldebug("ps_2_0");
a_DevPixelProgram = new CPixelProgram(program_ps_2_0); a_DevPixelProgram = new CPixelProgram(program_ps_2_0);
@ -365,7 +382,7 @@ void initCommands()
{ {
nldebug("ps_1_1"); nldebug("ps_1_1");
a_DevPixelProgram = new CPixelProgram(program_ps_1_1); a_DevPixelProgram = new CPixelProgram(program_ps_1_1);
} }*/
#endif #endif
} }

View file

@ -48,6 +48,7 @@
#include <nel/3d/u_material.h> #include <nel/3d/u_material.h>
#include <nel/3d/u_text_context.h> #include <nel/3d/u_text_context.h>
#include <nel/3d/bloom_effect.h> #include <nel/3d/bloom_effect.h>
#include <nel/3d/fxaa.h>
#if SBCLIENT_DEV_STEREO #if SBCLIENT_DEV_STEREO
# include <nel/3d/stereo_render.h> # include <nel/3d/stereo_render.h>
#endif /* #if SBCLIENT_DEV_STEREO */ #endif /* #if SBCLIENT_DEV_STEREO */
@ -153,6 +154,7 @@ static IStereoRender *_StereoRender = NULL;
#endif /* #if SBCLIENT_DEV_STEREO */ #endif /* #if SBCLIENT_DEV_STEREO */
static bool s_EnableBloom = false; static bool s_EnableBloom = false;
static CFXAA *s_FXAA = NULL;
// //
// Prototypes // Prototypes
@ -185,6 +187,7 @@ void cbGraphicsDriver(CConfigFile::CVar &var);
void cbSquareBloom(CConfigFile::CVar &var); void cbSquareBloom(CConfigFile::CVar &var);
void cbDensityBloom(CConfigFile::CVar &var); void cbDensityBloom(CConfigFile::CVar &var);
void cbEnableBloom(CConfigFile::CVar &var); void cbEnableBloom(CConfigFile::CVar &var);
void cbEnableFXAA(CConfigFile::CVar &var);
// //
// Functions // Functions
@ -377,6 +380,7 @@ void initIngame()
CConfiguration::setAndCallback("SquareBloom", cbSquareBloom); CConfiguration::setAndCallback("SquareBloom", cbSquareBloom);
CConfiguration::setAndCallback("DensityBloom", cbDensityBloom); CConfiguration::setAndCallback("DensityBloom", cbDensityBloom);
CConfiguration::setAndCallback("EnableBloom", cbEnableBloom); CConfiguration::setAndCallback("EnableBloom", cbEnableBloom);
CConfiguration::setAndCallback("EnableFXAA", cbEnableFXAA);
// Init the landscape using the previously created UScene // Init the landscape using the previously created UScene
displayLoadingState("Initialize Landscape"); displayLoadingState("Initialize Landscape");
initLandscape(); initLandscape();
@ -740,7 +744,19 @@ void loopIngame()
else else
{ {
uint i = 0; uint i = 0;
uint bloomStage = 0; bool effectRender = false;
CTextureUser *effectRenderTarget = NULL;
bool haveEffects = Driver->getPolygonMode() == UDriver::Filled
&& (s_EnableBloom || s_FXAA);
bool defaultRenderTarget = false;
if (haveEffects)
{
if (!StereoDisplay)
{
Driver->beginDefaultRenderTarget();
defaultRenderTarget = true;
}
}
while ((!StereoDisplay && i == 0) || (StereoDisplay && StereoDisplay->nextPass())) while ((!StereoDisplay && i == 0) || (StereoDisplay && StereoDisplay->nextPass()))
{ {
++i; ++i;
@ -762,13 +778,7 @@ void loopIngame()
if (!StereoDisplay || StereoDisplay->wantClear()) if (!StereoDisplay || StereoDisplay->wantClear())
{ {
effectRender = haveEffects;
/*if (s_EnableBloom)
{
nlassert(bloomStage == 0);
CBloomEffect::instance().initBloom(); // start bloom effect (just before the first scene element render)
bloomStage = 1;
}*/
// 01. Render Driver (background color) // 01. Render Driver (background color)
Driver->clearBuffers(CRGBA(0, 0, 127)); // clear all buffers, if you see this blue there's a problem with scene rendering Driver->clearBuffers(CRGBA(0, 0, 127)); // clear all buffers, if you see this blue there's a problem with scene rendering
@ -788,14 +798,14 @@ void loopIngame()
if (!StereoDisplay || StereoDisplay->wantInterface3D()) if (!StereoDisplay || StereoDisplay->wantInterface3D())
{ {
/*if (s_EnableBloom && bloomStage == 1) if (effectRender)
{ {
// End the actual bloom effect visible in the scene.
if (StereoDisplay) Driver->setViewport(NL3D::CViewport()); if (StereoDisplay) Driver->setViewport(NL3D::CViewport());
CBloomEffect::instance().endBloom(); if (s_EnableBloom) CBloomEffect::instance().applyBloom();
if (s_FXAA) s_FXAA->applyEffect();
if (StereoDisplay) Driver->setViewport(StereoDisplay->getCurrentViewport()); if (StereoDisplay) Driver->setViewport(StereoDisplay->getCurrentViewport());
bloomStage = 2; effectRender = false;
}*/ }
// 06. Render Interface 3D (player names) // 06. Render Interface 3D (player names)
// ... // ...
@ -803,15 +813,6 @@ void loopIngame()
if (!StereoDisplay || StereoDisplay->wantInterface2D()) if (!StereoDisplay || StereoDisplay->wantInterface2D())
{ {
/*if (s_EnableBloom && bloomStage == 2)
{
// End bloom effect system after drawing the 3d interface (z buffer related).
if (StereoDisplay) Driver->setViewport(NL3D::CViewport());
CBloomEffect::instance().endInterfacesDisplayBloom();
if (StereoDisplay) Driver->setViewport(StereoDisplay->getCurrentViewport());
bloomStage = 0;
}*/
// 07. Render Interface 2D (chatboxes etc, optionally does have 3d) // 07. Render Interface 2D (chatboxes etc, optionally does have 3d)
updateCompass(); // Update the compass updateCompass(); // Update the compass
updateRadar(); // Update the radar updateRadar(); // Update the radar
@ -833,6 +834,11 @@ void loopIngame()
} }
// 09. Render Buffer // 09. Render Buffer
if (defaultRenderTarget)
{
// draw final result to backbuffer
Driver->endDefaultRenderTarget(Scene);
}
Driver->swapBuffers(); Driver->swapBuffers();
} }
@ -965,6 +971,22 @@ void cbEnableBloom(CConfigFile::CVar &var)
s_EnableBloom = var.asBool(); s_EnableBloom = var.asBool();
} }
void cbEnableFXAA(CConfigFile::CVar &var)
{
bool enable = var.asBool();
if (enable != (s_FXAA != NULL))
{
if (enable)
{
s_FXAA = new CFXAA(Driver);
}
else
{
delete s_FXAA;
}
}
}
// //
// Loading state procedure // Loading state procedure
// //