Make bloom work together with render target used for the rift shader, ref #43

This commit is contained in:
kaetemi 2013-07-03 03:53:32 +02:00
parent 9516851bee
commit 299b3ec401
6 changed files with 47 additions and 22 deletions

View file

@ -138,6 +138,8 @@ private:
NLMISC::CSmartPtr<NL3D::ITexture> _BlurFinalTex;
// used as render target in first blur pass, and as displayed texture on second blur pass.
NLMISC::CSmartPtr<NL3D::ITexture> _BlurHorizontalTex;
// original render target
NLMISC::CSmartPtr<NL3D::ITexture> _OriginalRenderTarget;
// materials

View file

@ -121,9 +121,9 @@ public:
/// 2D Interface
virtual bool wantInterface2D() = 0;
/// Returns non-NULL if a new render target was set
virtual UTexture *beginRenderTarget(bool set) = 0;
/// Returns true if a render target was fully drawn
/// Returns true if a new render target was set, always fase if not using render targets
virtual bool beginRenderTarget() = 0;
/// Returns true if a render target was fully drawn, always false if not using render targets
virtual bool endRenderTarget() = 0;
static const char *getLibraryName(CStereoDeviceInfo::TStereoDeviceLibrary library);

View file

@ -109,8 +109,8 @@ public:
/// 2D Interface
virtual bool wantInterface2D();
/// Returns non-NULL if a new render target was set, always NULL if not using render targets
virtual UTexture *beginRenderTarget(bool set);
/// Returns true if a new render target was set, always fase if not using render targets
virtual bool beginRenderTarget();
/// Returns true if a render target was fully drawn, always false if not using render targets
virtual bool endRenderTarget();

View file

@ -285,6 +285,8 @@ void CBloomEffect::initBloom() // clientcfg
if(!_Init)
init();
_OriginalRenderTarget = static_cast<CDriverUser *>(_Driver)->getDriver()->getRenderTarget();
// if window resize, reinitialize textures
if(_WndWidth!=_Driver->getWindowWidth() || _WndHeight!=_Driver->getWindowHeight())
{
@ -349,12 +351,15 @@ void CBloomEffect::initBloom() // clientcfg
}
}
if (!_OriginalRenderTarget)
{
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");
return;
}
}
}
//-----------------------------------------------------------------------------------------------------------
@ -370,7 +375,7 @@ void CBloomEffect::endBloom() // clientcfg
if(_Driver->getWindowWidth()==0 || _Driver->getWindowHeight()==0)
return;
CTextureUser txt1 = (_InitBloomEffect) ? (CTextureUser(_InitText)) : (CTextureUser());
CTextureUser txt1 = _OriginalRenderTarget ? CTextureUser(_OriginalRenderTarget) : ((_InitBloomEffect) ? (CTextureUser(_InitText)) : (CTextureUser()));
CTextureUser txt2(_BlurFinalTex);
CRect rect1(0, 0, _WndWidth, _WndHeight);
CRect rect2(0, 0, _BlurWidth, _BlurHeight);
@ -394,15 +399,30 @@ void CBloomEffect::applyBlur()
{
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
if(_InitBloomEffect)
else if(_InitBloomEffect)
{
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");
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
@ -459,7 +479,7 @@ void CBloomEffect::endInterfacesDisplayBloom() // clientcfg
{
// 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.
if (_InitBloomEffect)
if ((_OriginalRenderTarget.getPtr() == NULL) && _InitBloomEffect)
{
if(!_Driver->supportBloomEffect() || !_Init)
return;
@ -492,6 +512,8 @@ void CBloomEffect::endInterfacesDisplayBloom() // clientcfg
_Driver->drawQuad(_DisplayQuad, _DisplayInitMat);
_Driver->setMatrixMode3D(pCam);
}
_OriginalRenderTarget = NULL;
}

View file

@ -488,19 +488,16 @@ bool CStereoOVR::wantInterface2D()
/// 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
// nlassert(m_SubStage <= 1);
if (m_Driver && m_Stage == 1)
{
if (set)
{
(static_cast<CDriverUser *>(m_Driver))->setRenderTarget(*m_BarrelTexU, 0, 0, 0, 0);
static_cast<CDriverUser *>(m_Driver)->setRenderTarget(*m_BarrelTexU, 0, 0, 0, 0);
return true;
}
return m_BarrelTexU;
}
return NULL;
return false;
}
/// Returns true if a render target was fully drawn

View file

@ -755,14 +755,18 @@ void loopIngame()
StereoDisplay->getCurrentMatrix(0, &Camera);
}
if (StereoDisplay)
{
StereoDisplay->beginRenderTarget();
}
if (!StereoDisplay || StereoDisplay->wantClear())
{
NL3D::UTexture *rt = StereoDisplay ? StereoDisplay->beginRenderTarget(!s_EnableBloom) : NULL;
if (s_EnableBloom)
{
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;
}