Make bloom work together with render target used for the rift shader, ref #43
This commit is contained in:
parent
afe8b1a8e6
commit
783c15b072
6 changed files with 47 additions and 22 deletions
|
@ -138,6 +138,8 @@ private:
|
||||||
NLMISC::CSmartPtr<NL3D::ITexture> _BlurFinalTex;
|
NLMISC::CSmartPtr<NL3D::ITexture> _BlurFinalTex;
|
||||||
// used as render target in first blur pass, and as displayed texture on second blur pass.
|
// used as render target in first blur pass, and as displayed texture on second blur pass.
|
||||||
NLMISC::CSmartPtr<NL3D::ITexture> _BlurHorizontalTex;
|
NLMISC::CSmartPtr<NL3D::ITexture> _BlurHorizontalTex;
|
||||||
|
// original render target
|
||||||
|
NLMISC::CSmartPtr<NL3D::ITexture> _OriginalRenderTarget;
|
||||||
|
|
||||||
|
|
||||||
// materials
|
// materials
|
||||||
|
|
|
@ -121,9 +121,9 @@ public:
|
||||||
/// 2D Interface
|
/// 2D Interface
|
||||||
virtual bool wantInterface2D() = 0;
|
virtual bool wantInterface2D() = 0;
|
||||||
|
|
||||||
/// Returns non-NULL if a new render target was set
|
/// Returns true if a new render target was set, always fase if not using render targets
|
||||||
virtual UTexture *beginRenderTarget(bool set) = 0;
|
virtual bool beginRenderTarget() = 0;
|
||||||
/// Returns true if a render target was fully drawn
|
/// Returns true if a render target was fully drawn, always false if not using render targets
|
||||||
virtual bool endRenderTarget() = 0;
|
virtual bool endRenderTarget() = 0;
|
||||||
|
|
||||||
static const char *getLibraryName(CStereoDeviceInfo::TStereoDeviceLibrary library);
|
static const char *getLibraryName(CStereoDeviceInfo::TStereoDeviceLibrary library);
|
||||||
|
|
|
@ -109,8 +109,8 @@ public:
|
||||||
/// 2D Interface
|
/// 2D Interface
|
||||||
virtual bool wantInterface2D();
|
virtual bool wantInterface2D();
|
||||||
|
|
||||||
/// Returns non-NULL if a new render target was set, always NULL if not using render targets
|
/// Returns true if a new render target was set, always fase if not using render targets
|
||||||
virtual UTexture *beginRenderTarget(bool set);
|
virtual bool beginRenderTarget();
|
||||||
/// Returns true if a render target was fully drawn, always false if not using render targets
|
/// Returns true if a render target was fully drawn, always false if not using render targets
|
||||||
virtual bool endRenderTarget();
|
virtual bool endRenderTarget();
|
||||||
|
|
||||||
|
|
|
@ -285,6 +285,8 @@ void CBloomEffect::initBloom() // clientcfg
|
||||||
if(!_Init)
|
if(!_Init)
|
||||||
init();
|
init();
|
||||||
|
|
||||||
|
_OriginalRenderTarget = static_cast<CDriverUser *>(_Driver)->getDriver()->getRenderTarget();
|
||||||
|
|
||||||
// if window resize, reinitialize textures
|
// if window resize, reinitialize textures
|
||||||
if(_WndWidth!=_Driver->getWindowWidth() || _WndHeight!=_Driver->getWindowHeight())
|
if(_WndWidth!=_Driver->getWindowWidth() || _WndHeight!=_Driver->getWindowHeight())
|
||||||
{
|
{
|
||||||
|
@ -349,12 +351,15 @@ void CBloomEffect::initBloom() // clientcfg
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!_OriginalRenderTarget)
|
||||||
|
{
|
||||||
NL3D::CTextureUser txt = (_InitBloomEffect) ? (CTextureUser(_InitText)) : (CTextureUser());
|
NL3D::CTextureUser txt = (_InitBloomEffect) ? (CTextureUser(_InitText)) : (CTextureUser());
|
||||||
if(!((CDriverUser *) _Driver)->setRenderTarget(txt, 0, 0, _WndWidth, _WndHeight))
|
if(!(static_cast<CDriverUser *>(_Driver)->setRenderTarget(txt, 0, 0, _WndWidth, _WndHeight)))
|
||||||
{
|
{
|
||||||
nlwarning("setRenderTarget return false with initial texture for bloom effect\n");
|
nlwarning("setRenderTarget return false with initial texture for bloom effect\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------------------------------------
|
||||||
|
@ -370,7 +375,7 @@ void CBloomEffect::endBloom() // clientcfg
|
||||||
if(_Driver->getWindowWidth()==0 || _Driver->getWindowHeight()==0)
|
if(_Driver->getWindowWidth()==0 || _Driver->getWindowHeight()==0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
CTextureUser txt1 = (_InitBloomEffect) ? (CTextureUser(_InitText)) : (CTextureUser());
|
CTextureUser txt1 = _OriginalRenderTarget ? CTextureUser(_OriginalRenderTarget) : ((_InitBloomEffect) ? (CTextureUser(_InitText)) : (CTextureUser()));
|
||||||
CTextureUser txt2(_BlurFinalTex);
|
CTextureUser txt2(_BlurFinalTex);
|
||||||
CRect rect1(0, 0, _WndWidth, _WndHeight);
|
CRect rect1(0, 0, _WndWidth, _WndHeight);
|
||||||
CRect rect2(0, 0, _BlurWidth, _BlurHeight);
|
CRect rect2(0, 0, _BlurWidth, _BlurHeight);
|
||||||
|
@ -394,15 +399,30 @@ void CBloomEffect::applyBlur()
|
||||||
{
|
{
|
||||||
NL3D::IDriver *drvInternal = ((CDriverUser *) _Driver)->getDriver();
|
NL3D::IDriver *drvInternal = ((CDriverUser *) _Driver)->getDriver();
|
||||||
|
|
||||||
|
/*if (_OriginalRenderTarget)
|
||||||
|
{
|
||||||
|
CTextureUser txt(_OriginalRenderTarget);
|
||||||
|
if(!(static_cast<CDriverUser *>(_Driver)->setRenderTarget(txt, 0, 0, _WndWidth, _WndHeight)))
|
||||||
|
{
|
||||||
|
nlwarning("setRenderTarget return false with original render target for bloom effect\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
// in opengl, display in init texture
|
// in opengl, display in init texture
|
||||||
if(_InitBloomEffect)
|
else if(_InitBloomEffect)
|
||||||
{
|
{
|
||||||
CTextureUser txt(_InitText);
|
CTextureUser txt(_InitText);
|
||||||
if(!((CDriverUser *) _Driver)->setRenderTarget(txt, 0, 0, _WndWidth, _WndHeight))
|
if(!(static_cast<CDriverUser *>(_Driver)->setRenderTarget(txt, 0, 0, _WndWidth, _WndHeight)))
|
||||||
{
|
{
|
||||||
nlwarning("setRenderTarget return false with initial texture for bloom effect\n");
|
nlwarning("setRenderTarget return false with initial texture for bloom effect\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}*/
|
||||||
|
CTextureUser txtApply = _OriginalRenderTarget ? CTextureUser(_OriginalRenderTarget) : ((_InitBloomEffect) ? (CTextureUser(_InitText)) : (CTextureUser()));
|
||||||
|
if(!(static_cast<CDriverUser *>(_Driver)->setRenderTarget(txtApply, 0, 0, _WndWidth, _WndHeight)))
|
||||||
|
{
|
||||||
|
nlwarning("setRenderTarget return false with initial texture for bloom effect\n");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// display blur texture
|
// display blur texture
|
||||||
|
@ -459,7 +479,7 @@ void CBloomEffect::endInterfacesDisplayBloom() // clientcfg
|
||||||
{
|
{
|
||||||
// Render from render target to screen if necessary.
|
// Render from render target to screen if necessary.
|
||||||
// Don't do this when the blend was done to the screen or when rendering to a user provided rendertarget.
|
// Don't do this when the blend was done to the screen or when rendering to a user provided rendertarget.
|
||||||
if (_InitBloomEffect)
|
if ((_OriginalRenderTarget.getPtr() == NULL) && _InitBloomEffect)
|
||||||
{
|
{
|
||||||
if(!_Driver->supportBloomEffect() || !_Init)
|
if(!_Driver->supportBloomEffect() || !_Init)
|
||||||
return;
|
return;
|
||||||
|
@ -492,6 +512,8 @@ void CBloomEffect::endInterfacesDisplayBloom() // clientcfg
|
||||||
_Driver->drawQuad(_DisplayQuad, _DisplayInitMat);
|
_Driver->drawQuad(_DisplayQuad, _DisplayInitMat);
|
||||||
_Driver->setMatrixMode3D(pCam);
|
_Driver->setMatrixMode3D(pCam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_OriginalRenderTarget = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -488,19 +488,16 @@ bool CStereoOVR::wantInterface2D()
|
||||||
|
|
||||||
|
|
||||||
/// Returns non-NULL if a new render target was set
|
/// Returns non-NULL if a new render target was set
|
||||||
UTexture *CStereoOVR::beginRenderTarget(bool set)
|
bool CStereoOVR::beginRenderTarget()
|
||||||
{
|
{
|
||||||
// render target always set before driver clear
|
// render target always set before driver clear
|
||||||
// nlassert(m_SubStage <= 1);
|
// nlassert(m_SubStage <= 1);
|
||||||
if (m_Driver && m_Stage == 1)
|
if (m_Driver && m_Stage == 1)
|
||||||
{
|
{
|
||||||
if (set)
|
static_cast<CDriverUser *>(m_Driver)->setRenderTarget(*m_BarrelTexU, 0, 0, 0, 0);
|
||||||
{
|
return true;
|
||||||
(static_cast<CDriverUser *>(m_Driver))->setRenderTarget(*m_BarrelTexU, 0, 0, 0, 0);
|
|
||||||
}
|
}
|
||||||
return m_BarrelTexU;
|
return false;
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if a render target was fully drawn
|
/// Returns true if a render target was fully drawn
|
||||||
|
|
|
@ -755,14 +755,18 @@ void loopIngame()
|
||||||
StereoDisplay->getCurrentMatrix(0, &Camera);
|
StereoDisplay->getCurrentMatrix(0, &Camera);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (StereoDisplay)
|
||||||
|
{
|
||||||
|
StereoDisplay->beginRenderTarget();
|
||||||
|
}
|
||||||
|
|
||||||
if (!StereoDisplay || StereoDisplay->wantClear())
|
if (!StereoDisplay || StereoDisplay->wantClear())
|
||||||
{
|
{
|
||||||
NL3D::UTexture *rt = StereoDisplay ? StereoDisplay->beginRenderTarget(!s_EnableBloom) : NULL;
|
|
||||||
|
|
||||||
if (s_EnableBloom)
|
if (s_EnableBloom)
|
||||||
{
|
{
|
||||||
nlassert(bloomStage == 0);
|
nlassert(bloomStage == 0);
|
||||||
CBloomEffect::instance().initBloom(/*rt*/); // start bloom effect (just before the first scene element render)
|
CBloomEffect::instance().initBloom(); // start bloom effect (just before the first scene element render)
|
||||||
bloomStage = 1;
|
bloomStage = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue