Render from multiple cameras, see #43

--HG--
branch : multipass-stereo
hg/feature/sound
kaetemi 12 years ago
parent a5c9592165
commit 32a187a199

@ -49,11 +49,15 @@
// NeL includes // NeL includes
#include <nel/misc/smart_ptr.h> #include <nel/misc/smart_ptr.h>
#include <nel/3d/frustum.h>
#include <nel/3d/viewport.h>
// Project includes // Project includes
namespace NL3D { namespace NL3D {
class UCamera;
struct CStereoDeviceInfo struct CStereoDeviceInfo
{ {
public: public:
@ -80,6 +84,20 @@ public:
CStereoOVR(const CStereoDeviceInfo &deviceInfo); CStereoOVR(const CStereoDeviceInfo &deviceInfo);
virtual ~CStereoOVR(); virtual ~CStereoOVR();
/// Gets the required screen resolution for this device
virtual void getScreenResolution(uint &width, uint &height);
/// Set latest camera position etcetera
virtual void updateCamera(const NL3D::UCamera *camera);
/// Is there a next pass
virtual bool nextPass();
/// Gets the current viewport
virtual const NL3D::CViewport &getCurrentViewport();
/// Gets the current camera frustum
virtual void getCurrentFrustum(NL3D::UCamera *camera);
/// Gets the current camera matrix
virtual void getCurrentMatrix(NL3D::UCamera *camera);
virtual NLMISC::CQuat getOrientation(); virtual NLMISC::CQuat getOrientation();
static void listDevices(std::vector<CStereoDeviceInfo> &devicesOut); static void listDevices(std::vector<CStereoDeviceInfo> &devicesOut);
@ -87,10 +105,19 @@ public:
static bool isLibraryInUse(); static bool isLibraryInUse();
static void releaseLibrary(); static void releaseLibrary();
/// Calculates internal camera information based on the reference camera
void initCamera(const NL3D::UCamera *camera);
bool isDeviceCreated(); bool isDeviceCreated();
private: private:
CStereoOVRDevicePtr *m_DevicePtr; CStereoOVRDevicePtr *m_DevicePtr;
int m_Stage;
CViewport m_LeftViewport;
CViewport m_RightViewport;
CFrustum m_LeftFrustum;
CFrustum m_RightFrustum;
CMatrix m_CameraMatrix;
}; /* class CStereoOVR */ }; /* class CStereoOVR */

@ -51,6 +51,7 @@
// NeL includes // NeL includes
// #include <nel/misc/debug.h> // #include <nel/misc/debug.h>
#include <nel/3d/u_camera.h>
// Project includes // Project includes
@ -142,9 +143,10 @@ public:
OVR::Ptr<OVR::HMDDevice> HMDDevice; OVR::Ptr<OVR::HMDDevice> HMDDevice;
OVR::Ptr<OVR::SensorDevice> SensorDevice; OVR::Ptr<OVR::SensorDevice> SensorDevice;
OVR::SensorFusion SensorFusion; OVR::SensorFusion SensorFusion;
OVR::HMDInfo HMDInfo;
}; };
CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo) CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo) : m_Stage(2)
{ {
++s_DeviceCounter; ++s_DeviceCounter;
m_DevicePtr = new CStereoOVRDevicePtr(); m_DevicePtr = new CStereoOVRDevicePtr();
@ -155,11 +157,30 @@ CStereoOVR::CStereoOVR(const CStereoDeviceInfo &deviceInfo)
if (m_DevicePtr->HMDDevice) if (m_DevicePtr->HMDDevice)
{ {
m_DevicePtr->HMDDevice->GetDeviceInfo(&m_DevicePtr->HMDInfo);
nldebug("OVR: HScreenSize: %f, VScreenSize: %f", m_DevicePtr->HMDInfo.HScreenSize, m_DevicePtr->HMDInfo.VScreenSize);
nldebug("OVR: VScreenCenter: %f", m_DevicePtr->HMDInfo.VScreenCenter);
nldebug("OVR: EyeToScreenDistance: %f", m_DevicePtr->HMDInfo.EyeToScreenDistance);
nldebug("OVR: LensSeparationDistance: %f", m_DevicePtr->HMDInfo.LensSeparationDistance);
nldebug("OVR: InterpupillaryDistance: %f", m_DevicePtr->HMDInfo.InterpupillaryDistance);
nldebug("OVR: HResolution: %i, VResolution: %i", m_DevicePtr->HMDInfo.HResolution, m_DevicePtr->HMDInfo.VResolution);
nldebug("OVR: DistortionK[0]: %f, DistortionK[1]: %f", m_DevicePtr->HMDInfo.DistortionK[0], m_DevicePtr->HMDInfo.DistortionK[1]);
nldebug("OVR: DistortionK[2]: %f, DistortionK[3]: %f", m_DevicePtr->HMDInfo.DistortionK[2], m_DevicePtr->HMDInfo.DistortionK[3]);
//2013/06/26 05:31:51 DBG 17a0 snowballs_client.exe stereo_ovr.cpp 160 NL3D::CStereoOVR::CStereoOVR : OVR: HScreenSize: 0.149760, VScreenSize: 0.093600
//2013/06/26 05:31:51 DBG 17a0 snowballs_client.exe stereo_ovr.cpp 161 NL3D::CStereoOVR::CStereoOVR : OVR: VScreenCenter: 0.046800
//2013/06/26 05:31:51 DBG 17a0 snowballs_client.exe stereo_ovr.cpp 162 NL3D::CStereoOVR::CStereoOVR : OVR: EyeToScreenDistance: 0.041000
//2013/06/26 05:31:51 DBG 17a0 snowballs_client.exe stereo_ovr.cpp 163 NL3D::CStereoOVR::CStereoOVR : OVR: LensSeparationDistance: 0.063500
//2013/06/26 05:31:51 DBG 17a0 snowballs_client.exe stereo_ovr.cpp 164 NL3D::CStereoOVR::CStereoOVR : OVR: InterpupillaryDistance: 0.064000
//2013/06/26 05:31:51 DBG 17a0 snowballs_client.exe stereo_ovr.cpp 165 NL3D::CStereoOVR::CStereoOVR : OVR: HResolution: 1280, VResolution: 800
//2013/06/26 05:31:51 DBG 17a0 snowballs_client.exe stereo_ovr.cpp 166 NL3D::CStereoOVR::CStereoOVR : OVR: DistortionK[0]: 1.000000, DistortionK[1]: 0.220000
//2013/06/26 05:31:51 DBG 17a0 snowballs_client.exe stereo_ovr.cpp 167 NL3D::CStereoOVR::CStereoOVR : OVR: DistortionK[2]: 0.240000, DistortionK[3]: 0.000000
m_DevicePtr->SensorDevice = m_DevicePtr->HMDDevice->GetSensor(); m_DevicePtr->SensorDevice = m_DevicePtr->HMDDevice->GetSensor();
m_DevicePtr->SensorFusion.AttachToSensor(m_DevicePtr->SensorDevice); m_DevicePtr->SensorFusion.AttachToSensor(m_DevicePtr->SensorDevice);
m_DevicePtr->SensorFusion.SetGravityEnabled(true); m_DevicePtr->SensorFusion.SetGravityEnabled(true);
m_DevicePtr->SensorFusion.SetPredictionEnabled(true); m_DevicePtr->SensorFusion.SetPredictionEnabled(true);
m_DevicePtr->SensorFusion.SetYawCorrectionEnabled(true); m_DevicePtr->SensorFusion.SetYawCorrectionEnabled(true);
m_LeftViewport.init(0.f, 0.f, 0.5f, 1.0f);
m_RightViewport.init(0.5f, 0.f, 0.5f, 1.0f);
} }
} }
@ -177,6 +198,74 @@ CStereoOVR::~CStereoOVR()
--s_DeviceCounter; --s_DeviceCounter;
} }
void CStereoOVR::getScreenResolution(uint &width, uint &height)
{
width = m_DevicePtr->HMDInfo.HResolution;
height = m_DevicePtr->HMDInfo.VResolution;
}
void CStereoOVR::initCamera(const NL3D::UCamera *camera)
{
float ar = (float)m_DevicePtr->HMDInfo.HResolution / ((float)m_DevicePtr->HMDInfo.VResolution * 2.0f);
float fov = 2.0f * atanf((m_DevicePtr->HMDInfo.VScreenSize / 2.0f) / m_DevicePtr->HMDInfo.EyeToScreenDistance); //(float)NLMISC::Pi/2.f; // 2.0f * atanf(m_DevicePtr->HMDInfo.VScreenSize / 2.0f * m_DevicePtr->HMDInfo.EyeToScreenDistance);
m_LeftFrustum.initPerspective(fov, ar, camera->getFrustum().Near, camera->getFrustum().Far);
m_RightFrustum = m_LeftFrustum;
float viewCenter = m_DevicePtr->HMDInfo.HScreenSize * 0.25f;
float eyeProjectionShift = viewCenter - m_DevicePtr->HMDInfo.LensSeparationDistance * 0.5f;
float projectionCenterOffset = 4.0f * eyeProjectionShift / m_DevicePtr->HMDInfo.HScreenSize;
nldebug("OVR: projectionCenterOffset = %f", projectionCenterOffset);
projectionCenterOffset *= (m_LeftFrustum.Left - m_LeftFrustum.Right) * 0.5f; // made this up ...
m_LeftFrustum.Left += projectionCenterOffset;
m_LeftFrustum.Right += projectionCenterOffset;
m_RightFrustum.Left -= projectionCenterOffset;
m_RightFrustum.Right -= projectionCenterOffset;
}
void CStereoOVR::updateCamera(const NL3D::UCamera *camera)
{
if (camera->getFrustum().Near != m_LeftFrustum.Near
|| camera->getFrustum().Far != m_LeftFrustum.Far)
CStereoOVR::initCamera(camera);
m_CameraMatrix = camera->getMatrix();
}
bool CStereoOVR::nextPass()
{
switch (m_Stage)
{
case 0:
++m_Stage;
return true;
case 1:
++m_Stage;
return false;
case 2:
m_Stage = 0;
return true;
}
}
const NL3D::CViewport &CStereoOVR::getCurrentViewport()
{
if (m_Stage) return m_RightViewport;
else return m_LeftViewport;
}
void CStereoOVR::getCurrentFrustum(NL3D::UCamera *camera)
{
if (m_Stage) camera->setFrustum(m_RightFrustum);
else camera->setFrustum(m_LeftFrustum);
}
void CStereoOVR::getCurrentMatrix(NL3D::UCamera *camera)
{
CMatrix translate;
if (m_Stage) 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?
}
NLMISC::CQuat CStereoOVR::getOrientation() NLMISC::CQuat CStereoOVR::getOrientation()
{ {
OVR::Quatf quatovr = m_DevicePtr->SensorFusion.GetPredictedOrientation(); OVR::Quatf quatovr = m_DevicePtr->SensorFusion.GetPredictedOrientation();
@ -225,7 +314,11 @@ void CStereoOVR::listDevices(std::vector<CStereoDeviceInfo> &devicesOut)
CStereoOVR *CStereoOVR::createDevice(const CStereoDeviceInfo &deviceInfo) CStereoOVR *CStereoOVR::createDevice(const CStereoDeviceInfo &deviceInfo)
{ {
return new CStereoOVR(deviceInfo); CStereoOVR *stereo = new CStereoOVR(deviceInfo);
if (stereo->isDeviceCreated())
return stereo;
delete stereo;
return NULL;
} }
bool CStereoOVR::isLibraryInUse() bool CStereoOVR::isLibraryInUse()

@ -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 = 0; ScreenFull = 1;
// 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 };

@ -64,13 +64,13 @@ UVisualCollisionEntity *CamCollisionEntity = NULL;
static UInstance Snow = NULL; static UInstance Snow = NULL;
// The sky 3D objects // The sky 3D objects
static UScene *SkyScene = NULL; UScene *SkyScene = NULL;
static UCamera SkyCamera = NULL; UCamera SkyCamera = NULL;
static UInstance Sky = NULL; static UInstance Sky = NULL;
static UCloudScape *Clouds = NULL; static UCloudScape *Clouds = NULL;
static CStereoOVR *s_StereoHMD = NULL; CStereoOVR *StereoHMD = NULL;
// //
// Functions // Functions
@ -111,7 +111,7 @@ void initCamera()
if (deviceInfo) if (deviceInfo)
{ {
nlinfo("Create HMD device!"); nlinfo("Create HMD device!");
s_StereoHMD = CStereoOVR::createDevice(*deviceInfo); StereoHMD = CStereoOVR::createDevice(*deviceInfo);
} }
} }
@ -129,6 +129,13 @@ void initCamera()
CamCollisionEntity = VisualCollisionManager->createEntity(); CamCollisionEntity = VisualCollisionManager->createEntity();
CamCollisionEntity->setCeilMode(true); CamCollisionEntity->setCeilMode(true);
if (StereoHMD)
{
StereoHMD->nextPass(); // test
StereoHMD->initCamera(&Camera);
}
// Create the snowing particle system // Create the snowing particle system
Snow = Scene->createInstance("snow.ps"); Snow = Scene->createInstance("snow.ps");
// And setup it // And setup it
@ -159,16 +166,16 @@ void releaseCamera()
Scene->deleteInstance(Snow); Scene->deleteInstance(Snow);
VisualCollisionManager->deleteEntity(CamCollisionEntity); VisualCollisionManager->deleteEntity(CamCollisionEntity);
delete s_StereoHMD; delete StereoHMD;
s_StereoHMD = NULL; StereoHMD = NULL;
CStereoOVR::releaseLibrary(); CStereoOVR::releaseLibrary();
} }
void updateCamera() void updateCamera()
{ {
if (s_StereoHMD) if (StereoHMD)
{ {
NLMISC::CQuat hmdOrient = s_StereoHMD->getOrientation(); NLMISC::CQuat hmdOrient = StereoHMD->getOrientation();
NLMISC::CMatrix camMatrix = Camera.getMatrix(); NLMISC::CMatrix camMatrix = Camera.getMatrix();
NLMISC::CMatrix hmdMatrix; NLMISC::CMatrix hmdMatrix;
hmdMatrix.setRot(hmdOrient); hmdMatrix.setRot(hmdOrient);
@ -217,6 +224,7 @@ void updateSky()
// Must clear ZBuffer For incoming rendering. // Must clear ZBuffer For incoming rendering.
Driver->clearZBuffer(); Driver->clearZBuffer();
if (!StereoHMD) // Cloudscape not supported (fix Viewport please)
Clouds->render(); Clouds->render();
} }

@ -30,6 +30,7 @@
namespace NL3D namespace NL3D
{ {
class UVisualCollisionEntity; class UVisualCollisionEntity;
class CStereoOVR;
}; };
namespace SBCLIENT { namespace SBCLIENT {
@ -39,7 +40,10 @@ namespace SBCLIENT {
// //
extern NL3D::UCamera Camera; extern NL3D::UCamera Camera;
extern NL3D::UCamera SkyCamera;
extern NL3D::UVisualCollisionEntity *CamCollisionEntity; extern NL3D::UVisualCollisionEntity *CamCollisionEntity;
extern NL3D::CStereoOVR *StereoHMD;
extern NL3D::UScene *SkyScene;
// //
// External functions // External functions

@ -51,6 +51,7 @@
#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 */
#include <nel/3d/stereo_ovr.h>
// Project includes // Project includes
#include "pacs.h" #include "pacs.h"
@ -709,6 +710,7 @@ void loopIngame()
// 09. Update Camera (depends on entities) // 09. Update Camera (depends on entities)
updateCamera(); updateCamera();
StereoHMD->updateCamera(&Camera);
// 10. Update Interface (login, ui, etc) // 10. Update Interface (login, ui, etc)
// ... // ...
@ -729,17 +731,28 @@ void loopIngame()
else else
{ {
// call all 3d render thingies // call all 3d render thingies
Driver->clearBuffers(CRGBA(127, 0, 0)); // if you see red, there's a problem with bloom or stereo render // 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 #if SBCLIENT_DEV_STEREO
_StereoRender->calculateCameras(Camera.getObjectPtr()); // calculate modified matrices for the current camera _StereoRender->calculateCameras(Camera.getObjectPtr()); // calculate modified matrices for the current camera
for (uint cameraId = 0; cameraId < _StereoRender->getCameraCount(); ++cameraId) for (uint cameraId = 0; cameraId < _StereoRender->getCameraCount(); ++cameraId)
{ {
_StereoRender->getCamera(cameraId, Camera.getObjectPtr()); // get the matrix details for this camera _StereoRender->getCamera(cameraId, Camera.getObjectPtr()); // get the matrix details for this camera
#endif /* #if SBCLIENT_DEV_STEREO */
// 01. Render Driver (background color) #endif /* #if SBCLIENT_DEV_STEREO */
CBloomEffect::instance().initBloom(); // start bloom effect (just before the first scene element render) while (StereoHMD->nextPass())
Driver->clearBuffers(CRGBA(0, 0, 127)); // clear all buffers, if you see this blue there's a problem with scene rendering {
const CViewport &vp = StereoHMD->getCurrentViewport();
Driver->setViewport(vp);
Scene->setViewport(vp);
SkyScene->setViewport(vp);
StereoHMD->getCurrentFrustum(&Camera);
StereoHMD->getCurrentFrustum(&SkyCamera);
StereoHMD->getCurrentMatrix(&Camera);
// 02. Render Sky (sky scene) // 02. Render Sky (sky scene)
updateSky(); // Render the sky scene before the main scene updateSky(); // Render the sky scene before the main scene
@ -749,10 +762,10 @@ void loopIngame()
// 05. Render Effects (flare) // 05. Render Effects (flare)
updateLensFlare(); // Render the lens flare updateLensFlare(); // Render the lens flare
CBloomEffect::instance().endBloom(); // end the actual bloom effect visible in the scene // BLOOM CBloomEffect::instance().endBloom(); // end the actual bloom effect visible in the scene
// 06. Render Interface 3D (player names) // 06. Render Interface 3D (player names)
CBloomEffect::instance().endInterfacesDisplayBloom(); // end bloom effect system after drawing the 3d interface (z buffer related) // BLOOM CBloomEffect::instance().endInterfacesDisplayBloom(); // end bloom effect system after drawing the 3d interface (z buffer related)
#if SBCLIENT_DEV_STEREO #if SBCLIENT_DEV_STEREO
_StereoRender->copyBufferToTexture(cameraId); // copy current buffer to the active stereorender texture _StereoRender->copyBufferToTexture(cameraId); // copy current buffer to the active stereorender texture
@ -774,6 +787,7 @@ void loopIngame()
// 08. Render Debug (stuff for dev) // 08. Render Debug (stuff for dev)
// ... // ...
}
// 09. Render Buffer // 09. Render Buffer
Driver->swapBuffers(); Driver->swapBuffers();

Loading…
Cancel
Save