mirror of
https://port.numenaute.org/aleajactaest/khanat-opennel-code.git
synced 2024-11-25 00:26:17 +00:00
Cleanup and make bloom work with stereo rendering, re #43
This commit is contained in:
parent
826da99473
commit
4c4640c954
6 changed files with 209 additions and 70 deletions
|
@ -84,6 +84,7 @@ public:
|
|||
CStereoOVR(const CStereoDeviceInfo &deviceInfo);
|
||||
virtual ~CStereoOVR();
|
||||
|
||||
|
||||
/// Gets the required screen resolution for this device
|
||||
virtual void getScreenResolution(uint &width, uint &height);
|
||||
/// Set latest camera position etcetera
|
||||
|
@ -92,19 +93,33 @@ public:
|
|||
/// Is there a next pass
|
||||
virtual bool nextPass();
|
||||
/// Gets the current viewport
|
||||
virtual const NL3D::CViewport &getCurrentViewport();
|
||||
virtual const NL3D::CViewport &getCurrentViewport() const;
|
||||
/// Gets the current camera frustum
|
||||
virtual void getCurrentFrustum(NL3D::UCamera *camera);
|
||||
virtual void getCurrentFrustum(NL3D::UCamera *camera) const;
|
||||
/// Gets the current camera matrix
|
||||
virtual void getCurrentMatrix(NL3D::UCamera *camera);
|
||||
virtual void getCurrentMatrix(NL3D::UCamera *camera) const;
|
||||
|
||||
virtual bool beginClear();
|
||||
virtual void endClear();
|
||||
|
||||
virtual bool beginScene();
|
||||
virtual void endScene();
|
||||
|
||||
virtual bool beginInterface3D();
|
||||
virtual void endInterface3D();
|
||||
|
||||
virtual bool beginInterface2D();
|
||||
virtual void endInterface2D();
|
||||
|
||||
virtual NLMISC::CQuat getOrientation() const;
|
||||
|
||||
virtual NLMISC::CQuat getOrientation();
|
||||
|
||||
static void listDevices(std::vector<CStereoDeviceInfo> &devicesOut);
|
||||
static CStereoOVR *createDevice(const CStereoDeviceInfo &deviceInfo);
|
||||
static bool isLibraryInUse();
|
||||
static void releaseLibrary();
|
||||
|
||||
|
||||
/// Calculates internal camera information based on the reference camera
|
||||
void initCamera(const NL3D::UCamera *camera);
|
||||
|
||||
|
|
|
@ -146,7 +146,7 @@ public:
|
|||
OVR::HMDInfo HMDInfo;
|
||||
};
|
||||
|
||||
CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo) : m_Stage(2)
|
||||
CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo) : m_Stage(0)
|
||||
{
|
||||
++s_DeviceCounter;
|
||||
m_DevicePtr = new CStereoOVRDevicePtr();
|
||||
|
@ -235,38 +235,130 @@ bool CStereoOVR::nextPass()
|
|||
{
|
||||
case 0:
|
||||
++m_Stage;
|
||||
// stage 1:
|
||||
// (initBloom)
|
||||
// clear buffer
|
||||
// draw scene left
|
||||
return true;
|
||||
case 1:
|
||||
++m_Stage;
|
||||
return false;
|
||||
case 2:
|
||||
m_Stage = 0;
|
||||
// stage 2:
|
||||
// draw scene right
|
||||
return true;
|
||||
case 2:
|
||||
++m_Stage;
|
||||
// stage 3:
|
||||
// (endBloom)
|
||||
// draw interface 3d left
|
||||
return true;
|
||||
case 3:
|
||||
++m_Stage;
|
||||
// stage 4:
|
||||
// draw interface 3d right
|
||||
return true;
|
||||
case 4:
|
||||
++m_Stage;
|
||||
// stage 5:
|
||||
// (endInterfacesDisplayBloom)
|
||||
// draw interface 2d left
|
||||
return true;
|
||||
case 5:
|
||||
++m_Stage;
|
||||
// stage 6:
|
||||
// draw interface 2d right
|
||||
return true;
|
||||
case 6:
|
||||
m_Stage = 0;
|
||||
// present
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
const NL3D::CViewport &CStereoOVR::getCurrentViewport()
|
||||
const NL3D::CViewport &CStereoOVR::getCurrentViewport() const
|
||||
{
|
||||
if (m_Stage) return m_RightViewport;
|
||||
else return m_LeftViewport;
|
||||
if (m_Stage % 2) return m_LeftViewport;
|
||||
else return m_RightViewport;
|
||||
}
|
||||
|
||||
void CStereoOVR::getCurrentFrustum(NL3D::UCamera *camera)
|
||||
void CStereoOVR::getCurrentFrustum(NL3D::UCamera *camera) const
|
||||
{
|
||||
if (m_Stage) camera->setFrustum(m_RightFrustum);
|
||||
else camera->setFrustum(m_LeftFrustum);
|
||||
if (m_Stage % 2) camera->setFrustum(m_LeftFrustum);
|
||||
else camera->setFrustum(m_RightFrustum);
|
||||
}
|
||||
|
||||
void CStereoOVR::getCurrentMatrix(NL3D::UCamera *camera)
|
||||
void CStereoOVR::getCurrentMatrix(NL3D::UCamera *camera) const
|
||||
{
|
||||
CMatrix translate;
|
||||
if (m_Stage) translate.translate(CVector(m_DevicePtr->HMDInfo.InterpupillaryDistance * -0.5f, 0.f, 0.f));
|
||||
if (m_Stage % 2) translate.translate(CVector(m_DevicePtr->HMDInfo.InterpupillaryDistance * -0.5f, 0.f, 0.f));
|
||||
else translate.translate(CVector(m_DevicePtr->HMDInfo.InterpupillaryDistance * 0.5f, 0.f, 0.f));
|
||||
camera->setTransformMode(NL3D::UTransformable::DirectMatrix);
|
||||
camera->setMatrix(m_CameraMatrix * translate); // or switch?
|
||||
camera->setMatrix(m_CameraMatrix * translate);
|
||||
}
|
||||
|
||||
NLMISC::CQuat CStereoOVR::getOrientation()
|
||||
bool CStereoOVR::beginClear()
|
||||
{
|
||||
switch (m_Stage)
|
||||
{
|
||||
case 1:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CStereoOVR::endClear()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CStereoOVR::beginScene()
|
||||
{
|
||||
switch (m_Stage)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CStereoOVR::endScene()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CStereoOVR::beginInterface3D()
|
||||
{
|
||||
switch (m_Stage)
|
||||
{
|
||||
case 3:
|
||||
case 4:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CStereoOVR::endInterface3D()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool CStereoOVR::beginInterface2D()
|
||||
{
|
||||
switch (m_Stage)
|
||||
{
|
||||
case 5:
|
||||
case 6:
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void CStereoOVR::endInterface2D()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
NLMISC::CQuat CStereoOVR::getOrientation() const
|
||||
{
|
||||
OVR::Quatf quatovr = m_DevicePtr->SensorFusion.GetPredictedOrientation();
|
||||
NLMISC::CMatrix coordsys;
|
||||
|
|
|
@ -52,7 +52,7 @@ ScreenHeight = 800;
|
|||
ScreenDepth = 32;
|
||||
|
||||
// If 1, run in fullscreen mode, 0 for windowed
|
||||
ScreenFull = 1;
|
||||
ScreenFull = 0;
|
||||
|
||||
// Start position of the player (the z is always 0)
|
||||
StartPoint = { 1840.0, -970.0, 0.0 };
|
||||
|
|
|
@ -131,8 +131,6 @@ void initCamera()
|
|||
|
||||
if (StereoHMD)
|
||||
{
|
||||
StereoHMD->nextPass(); // test
|
||||
|
||||
StereoHMD->initCamera(&Camera);
|
||||
}
|
||||
|
||||
|
|
|
@ -427,6 +427,11 @@ void C3dMouseListener::updateCamera()
|
|||
cpos = snapped+CVector(0.0f, 0.0f, GroundCamLimit);
|
||||
_ViewHeight = cpos.z - getPosition().z;
|
||||
}
|
||||
if (StereoHMD)
|
||||
{
|
||||
// look at straight forward
|
||||
tpos.z = cpos.z;
|
||||
}
|
||||
_Camera.lookAt(cpos, tpos);
|
||||
}
|
||||
|
||||
|
|
|
@ -710,7 +710,7 @@ void loopIngame()
|
|||
|
||||
// 09. Update Camera (depends on entities)
|
||||
updateCamera();
|
||||
StereoHMD->updateCamera(&Camera);
|
||||
if (StereoHMD) StereoHMD->updateCamera(&Camera);
|
||||
|
||||
// 10. Update Interface (login, ui, etc)
|
||||
// ...
|
||||
|
@ -730,63 +730,92 @@ void loopIngame()
|
|||
if (Driver->isLost()) nlSleep(10);
|
||||
else
|
||||
{
|
||||
// call all 3d render thingies
|
||||
// Driver->clearBuffers(CRGBA(127, 0, 0)); // if you see red, there's a problem with bloom or stereo render
|
||||
|
||||
// 01. Render Driver (background color)
|
||||
// BLOOM CBloomEffect::instance().initBloom(); // start bloom effect (just before the first scene element render)
|
||||
Driver->clearBuffers(CRGBA(0, 0, 127)); // clear all buffers, if you see this blue there's a problem with scene rendering
|
||||
|
||||
#if SBCLIENT_DEV_STEREO
|
||||
_StereoRender->calculateCameras(Camera.getObjectPtr()); // calculate modified matrices for the current camera
|
||||
for (uint cameraId = 0; cameraId < _StereoRender->getCameraCount(); ++cameraId)
|
||||
uint i = 0;
|
||||
uint bloomStage = 0;
|
||||
while ((!StereoHMD && i == 0) || (StereoHMD && StereoHMD->nextPass()))
|
||||
{
|
||||
_StereoRender->getCamera(cameraId, Camera.getObjectPtr()); // get the matrix details for this camera
|
||||
++i;
|
||||
if (StereoHMD)
|
||||
{
|
||||
const CViewport &vp = StereoHMD->getCurrentViewport();
|
||||
Driver->setViewport(vp);
|
||||
Scene->setViewport(vp);
|
||||
SkyScene->setViewport(vp);
|
||||
StereoHMD->getCurrentFrustum(&Camera);
|
||||
StereoHMD->getCurrentFrustum(&SkyCamera);
|
||||
StereoHMD->getCurrentMatrix(&Camera);
|
||||
}
|
||||
|
||||
#endif /* #if SBCLIENT_DEV_STEREO */
|
||||
while (StereoHMD->nextPass())
|
||||
{
|
||||
const CViewport &vp = StereoHMD->getCurrentViewport();
|
||||
Driver->setViewport(vp);
|
||||
Scene->setViewport(vp);
|
||||
SkyScene->setViewport(vp);
|
||||
StereoHMD->getCurrentFrustum(&Camera);
|
||||
StereoHMD->getCurrentFrustum(&SkyCamera);
|
||||
StereoHMD->getCurrentMatrix(&Camera);
|
||||
if (!StereoHMD || StereoHMD->beginClear())
|
||||
{
|
||||
nlassert(bloomStage == 0);
|
||||
CBloomEffect::instance().initBloom(); // start bloom effect (just before the first scene element render)
|
||||
bloomStage = 1;
|
||||
|
||||
// 02. Render Sky (sky scene)
|
||||
updateSky(); // Render the sky scene before the main scene
|
||||
// 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
|
||||
|
||||
// 04. Render Scene (entity scene)
|
||||
Scene->render(); // Render
|
||||
if (StereoHMD) StereoHMD->endClear();
|
||||
}
|
||||
|
||||
// 05. Render Effects (flare)
|
||||
updateLensFlare(); // Render the lens flare
|
||||
// BLOOM CBloomEffect::instance().endBloom(); // end the actual bloom effect visible in the scene
|
||||
if (!StereoHMD || StereoHMD->beginScene())
|
||||
{
|
||||
// 02. Render Sky (sky scene)
|
||||
updateSky(); // Render the sky scene before the main scene
|
||||
|
||||
// 06. Render Interface 3D (player names)
|
||||
// BLOOM CBloomEffect::instance().endInterfacesDisplayBloom(); // end bloom effect system after drawing the 3d interface (z buffer related)
|
||||
// 04. Render Scene (entity scene)
|
||||
Scene->render(); // Render
|
||||
|
||||
#if SBCLIENT_DEV_STEREO
|
||||
_StereoRender->copyBufferToTexture(cameraId); // copy current buffer to the active stereorender texture
|
||||
}
|
||||
_StereoRender->restoreCamera(Camera.getObjectPtr()); // restore the camera
|
||||
_StereoRender->render(); // render everything together in the current mode
|
||||
#endif /* #if SBCLIENT_DEV_STEREO */
|
||||
// 05. Render Effects (flare)
|
||||
if (!StereoHMD) updateLensFlare(); // Render the lens flare (left eye stretched with stereo...)
|
||||
|
||||
// 07. Render Interface 2D (chatboxes etc, optionally does have 3d)
|
||||
updateCompass(); // Update the compass
|
||||
updateRadar(); // Update the radar
|
||||
updateGraph(); // Update the radar
|
||||
if (ShowCommands) updateCommands(); // Update the commands panel
|
||||
updateAnimation();
|
||||
renderEntitiesNames(); // Render the name on top of the other players
|
||||
updateInterface(); // Update interface
|
||||
renderInformation();
|
||||
update3dLogo();
|
||||
if (StereoHMD) StereoHMD->endScene();
|
||||
}
|
||||
|
||||
// 08. Render Debug (stuff for dev)
|
||||
// ...
|
||||
if (!StereoHMD || StereoHMD->beginInterface3D())
|
||||
{
|
||||
if (bloomStage == 1)
|
||||
{
|
||||
// End the actual bloom effect visible in the scene.
|
||||
if (StereoHMD) Driver->setViewport(NL3D::CViewport());
|
||||
CBloomEffect::instance().endBloom();
|
||||
if (StereoHMD) Driver->setViewport(StereoHMD->getCurrentViewport());
|
||||
bloomStage = 2;
|
||||
}
|
||||
|
||||
// 06. Render Interface 3D (player names)
|
||||
// ...
|
||||
|
||||
if (StereoHMD) StereoHMD->endInterface3D();
|
||||
}
|
||||
|
||||
if (!StereoHMD || StereoHMD->beginInterface2D())
|
||||
{
|
||||
if (bloomStage == 2)
|
||||
{
|
||||
// End bloom effect system after drawing the 3d interface (z buffer related).
|
||||
if (StereoHMD) Driver->setViewport(NL3D::CViewport());
|
||||
CBloomEffect::instance().endInterfacesDisplayBloom();
|
||||
if (StereoHMD) Driver->setViewport(StereoHMD->getCurrentViewport());
|
||||
bloomStage = 0;
|
||||
}
|
||||
|
||||
// 07. Render Interface 2D (chatboxes etc, optionally does have 3d)
|
||||
updateCompass(); // Update the compass
|
||||
updateRadar(); // Update the radar
|
||||
updateGraph(); // Update the radar
|
||||
if (ShowCommands) updateCommands(); // Update the commands panel
|
||||
updateAnimation();
|
||||
renderEntitiesNames(); // Render the name on top of the other players
|
||||
updateInterface(); // Update interface
|
||||
renderInformation();
|
||||
if (!StereoHMD) update3dLogo(); // broken with stereo
|
||||
|
||||
// 08. Render Debug (stuff for dev)
|
||||
// ...
|
||||
|
||||
if (StereoHMD) StereoHMD->endInterface2D();
|
||||
}
|
||||
}
|
||||
|
||||
// 09. Render Buffer
|
||||
|
|
Loading…
Reference in a new issue