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