bjornblissing / osgoculusviewer Goto Github PK
View Code? Open in Web Editor NEWAn OsgViewer with support for the Oculus Rift
License: Other
An OsgViewer with support for the Oculus Rift
License: Other
Just tested the viewer in my setup. Works really well, thank you.
Just one bug I came across: When the viewer is closed, it can't be restarted.
I will look into it myself too.
Here just a simple modification of the viewerexample.cpp, demonstrating the issue:
#include <osgDB/ReadFile>
#include <osgGA/TrackballManipulator>
#include "oculusviewer.h"
#include "oculuseventhandler.h"
#include <osgViewer/Viewer>
#include <osgViewer/ViewerEventHandlers>
#include <osgUtil/GLObjectsVisitor>
void view()
{
// read the scene from the list of file specified command line arguments.
osg::ref_ptr<osg::Node> loadedModel = osgDB::readNodeFile("cow.osgt");
// Create Trackball manipulator
osg::ref_ptr<osgGA::CameraManipulator> cameraManipulator = new osgGA::TrackballManipulator;
const osg::BoundingSphere& bs = loadedModel->getBound();
if (bs.valid()) {
// Adjust view to object view
osg::Vec3 modelCenter = bs.center();
osg::Vec3 eyePos = bs.center() + osg::Vec3(0, bs.radius(), 0);
cameraManipulator->setHomePosition(eyePos, modelCenter, osg::Vec3(0, 0, 1));
}
// Open the HMD
float nearClip = 0.01f;
float farClip = 10000.0f;
float pixelsPerDisplayPixel = 1.0;
float worldUnitsPerMetre = 1.0f;
osg::ref_ptr<OculusDevice> oculusDevice = new OculusDevice(nearClip, farClip, pixelsPerDisplayPixel, worldUnitsPerMetre);
// Get the suggested context traits
osg::ref_ptr<osg::GraphicsContext::Traits> traits = oculusDevice->graphicsContextTraits();
traits->windowName = "OsgOculusViewerExample";
// Create a graphic context based on our desired traits
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits);
if (!gc) {
osg::notify(osg::NOTICE) << "Error, GraphicsWindow has not been created successfully" << std::endl;
}
if (gc.valid()) {
gc->setClearColor(osg::Vec4(0.2f, 0.2f, 0.4f, 1.0f));
gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
osgViewer::Viewer viewer;
// Force single threaded to make sure that no other thread can use the GL context
viewer.setThreadingModel(osgViewer::Viewer::SingleThreaded);
viewer.getCamera()->setGraphicsContext(gc);
viewer.getCamera()->setViewport(0, 0, traits->width, traits->height);
// Disable automatic computation of near and far plane
viewer.getCamera()->setComputeNearFarMode( osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );
viewer.setCameraManipulator(cameraManipulator);
// Things to do when viewer is realized
osg::ref_ptr<OculusRealizeOperation> oculusRealizeOperation = new OculusRealizeOperation(oculusDevice);
viewer.setRealizeOperation(oculusRealizeOperation.get());
osg::ref_ptr<OculusViewer> oculusViewer = new OculusViewer(&viewer, oculusDevice, oculusRealizeOperation);
oculusViewer->addChild(loadedModel);
viewer.setSceneData(oculusViewer);
// Add statistics handler
viewer.addEventHandler(new osgViewer::StatsHandler);
viewer.addEventHandler(new OculusEventHandler(oculusDevice));
// Realize viewer
viewer.realize();
// Start Viewer
while (!viewer.done()) {
viewer.frame();
}
}
int main( int argc, char** argv )
{
view();
view();
return 0;
}
Implement support for TimeWarp. This will require changes to distortionMesh and shaders.
When running in extended mode we need to disable desktop composition in Windows to avoid judder.
This can be done by code by calling the DwmEnableComposition
function. This function is deprecated in Windows 8 and later.
The perfHUD state gets remembered from last time the application was run. Which can result in both HealthAndSafetyWarning and perfHUD getting displayed at the same time during application start.
This may be a misunderstanding on my part, but I'm wondering why the function "OculusDevice::calculateEyeAdjustment()" does not seem to pickup the IPD setting from the Oculus Configuration Utility (at least in SDK 0.5.0.1)?
I seem to get the same values for left and right eye positions regardless of the IPD setting in the configuration. I always get positions x=-0.032m and x=+0.032m i.e. IPD=64mm.
Am I missing something, or do I need to pickup the IPD configuration in some other way?
Thanks.
Chris.
Support direct mode rendering in Windows.
Oculus VR requires every application to display the Oculus Health and Safety Warnings before each session.
Hi,
When I use the vierwer in combination with osgEarth, the memory usages get very high. This is especially true when using osgEarth image layers in the earth files.
Do you have any idea what could cause this?
I've tested this with osg 3.2.1 and the latest osgEarth master version. I could send you the code I used to run the osgEarth with your osgoculusviewer if you'd like.
Any hint would be very much appriciated!
Thanks!
Roy
Add support for the Oculus SDK based distortion rendering.
Currently there is no support for antialiasing. To be able to support antialiasing via MSAA the FBOs must be initialized with osg::Texture2DMultisample
instead of osg::Texture2D
.
Both the color buffer and the depth buffer must have the same dimensions and number of multi-samples.
It can be good to be able to reset the sensor, since the orientation can start to drift or be initialized in wrong direction.
The Oculus Rift HMDs operate in the sRGB color. So the applications are expected to create sRGB-correct swap texture sets.
When compiling on Kubnutu 14.10 the following error:
In file included from /usr/include/c++/4.9/cstdint:35:0, from oculushealthwarning.cpp:10: /usr/include/c++/4.9/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
Support dynamical switching between having positional tracking on or off.
Enable users to interactively toggle HMD capabilities such as:
Currently we are spending rendering resources by rendering the main camera. Even though this result is overwritten by the blitting from the swap texture.
Hi bjornblissing,
Observing objects at close range (less than 1 meters), and rotating head (ear to shoulder), can cause the eyes to misfocus.I found in the code of the matrix multiplication sequence of head rotation and eye offset may be wrong, according to the following code modifications, the problem disappears. This problem also exists in OculusCompositeViewer and OculusViewConfig.
Sorry about my English.
void OculusViewer::traverse(osg::NodeVisitor& nv)
{
if (!m_configured) {
configure();
}
if (m_configured) {
m_device.get()->updatePose(m_swapCallback->frameIndex());
osg::Vec3 position = m_device.get()->position();
osg::Quat orientation = m_device.get()->orientation();
osg::Matrix hmdMatrix;
hmdMatrix.makeRotate(orientation);
hmdMatrix.preMultTranslate(position);
osg::Matrix viewOffsetLeft = hmdMatrix*m_device.get()->viewMatrixLeft();
osg::Matrix viewOffsetRight = hmdMatrix*m_device.get()->viewMatrixRight();
//osg::Matrix viewOffsetLeft = m_device.get()->viewMatrixLeft();
//osg::Matrix viewOffsetRight = m_device.get()->viewMatrixRight();
//viewOffsetLeft.preMultTranslate(position);
//viewOffsetRight.preMultTranslate(position);
//viewOffsetLeft.postMultRotate(orientation);
//viewOffsetRight.postMultRotate(orientation);
// Nasty hack to update the view offset for each of the slave cameras
// There doesn't seem to be an accessor for this, fortunately the offsets are public
m_view->findSlaveForCamera(m_cameraRTTLeft.get())->_viewOffset = viewOffsetLeft;
m_view->findSlaveForCamera(m_cameraRTTRight.get())->_viewOffset = viewOffsetRight;
}
osg::Group::traverse(nv);
}
To be able to use positional time warp the layer needs to be submitted as EyeFovDepth instead of EyeFov.
ovrHmd has been marked as deprecated and will be removed in future SDK versions.
DK1 version has this function, not now, I think this method can increase the Fov, do not know the new version is considered contain the function.
Thanks.
Don't know if it is configuration issue or what.
Starting the example looking strait ahead is looking up.
Looking strait down looks at the cow.
I have a fix but I am trying to figure out if it is just a configuration issue or if I am missing something.
camera->setcullmarsk
Try to set process as HIGH_PRIORITY_CLASS
when running in windows to make sure that as few other processes as possible interfere.
Implement support for chromatic aberration correction. This will require changes to distortionMesh and shaders.
Add support for the performance HUD available inside the SDK.
Stack trace:
Thread 7 Crashed:
0 com.apple.driver.AppleIntelHD5000GraphicsGLDriver 0x00001234003a5708 IntelVertexArray::setElemData(unsigned int, unsigned int, unsigned short, unsigned int) + 140
1 com.apple.driver.AppleIntelHD5000GraphicsGLDriver 0x00001234003a5667 IntelVertexArray::extractState(GLDVertexArrayDataRec const*, unsigned long long) + 81
2 libGPUSupportMercury.dylib 0x00007fff917096b6 gpusLoadCurrentVertexArray + 188
3 com.apple.driver.AppleIntelHD5000GraphicsGLDriver 0x00001234003a3227 updateDispatch + 1355
4 GLEngine 0x00007fff92d7b2a0 gleDoDrawDispatchCore + 502
5 GLEngine 0x00007fff92d22712 gleSetupAndDrawArraysOrElementsOutOfLine_ListExec + 841
6 GLEngine 0x00007fff92cb7c91 gleCallList + 165
7 libosgUtil.100.dylib 0x000000010727ba59 osgUtil::RenderLeaf::render(osg::RenderInfo&, osgUtil::RenderLeaf*) + 181
8 libosgUtil.100.dylib 0x0000000107278665 osgUtil::RenderBin::drawImplementation(osg::RenderInfo&, osgUtil::RenderLeaf*&) + 309
9 libosgUtil.100.dylib 0x000000010727fe27 osgUtil::RenderStage::drawImplementation(osg::RenderInfo&, osgUtil::RenderLeaf*&) + 709
10 libosgUtil.100.dylib 0x000000010727ef31 osgUtil::RenderStage::drawInner(osg::RenderInfo&, osgUtil::RenderLeaf*&, bool&) + 293
11 libosgUtil.100.dylib 0x000000010727f8c8 osgUtil::RenderStage::draw(osg::RenderInfo&, osgUtil::RenderLeaf*&) + 1058
12 libosgUtil.100.dylib 0x0000000107287724 osgUtil::SceneView::draw() + 938
13 libosgViewer.100.dylib 0x0000000107141396 osgViewer::Renderer::draw() + 856
14 libosg.100.dylib 0x0000000106dc9673 osg::GraphicsContext::runOperations() + 185
15 libosg.100.dylib 0x0000000106e08325 osg::OperationThread::run() + 413
16 libosg.100.dylib 0x0000000106dcbe31 osg::GraphicsThread::run() + 89
17 libOpenThreads.20.dylib 0x0000000106d4cbc2 OpenThreads::ThreadPrivateActions::StartThread(void*) + 178
18 libsystem_pthread.dylib 0x00007fff98cba899 _pthread_body + 138
19 libsystem_pthread.dylib 0x00007fff98cba72a _pthread_start + 137
20 libsystem_pthread.dylib 0x00007fff98cbefc9 thread_start + 13
The new SDK (v0.3.1) contains a brand new C interface. There also exists two different options for rendering SDK assisted rendering, and game rendering aka DIY-rendering.
Maybe I'm missing something but the viewer does not seem to pick up and use the tracker for orienting the items on the display.
Disclaimer is that I don't have a real Rift instead I am using this project, which works with the official Oculus SDK....
https://github.com/yetifrisstlama/Foculus_Rift_Tracker_STM32F3DISCOVERY
Is it possible to enable the tracker, even when the (proper) display device is not found? Terminal reports following
$ bin/OsgOculusViewer_deprecated cone_down.ac
OVR::DeviceManagerThread - running (ThreadId=0x7f08cb14d700).
OVR::DeviceManager - initialized.
Warning: Unable to find HMD Device, will use default renderpath instead.
Error: can't open file ""
Error: can't open file ""
glLinkProgram "" FAILED
Program "" infolog:
Vertex info
osg::FboExtensions
do not exist in osg 3.4.0. Instead the FBO calls are made using osg::GLExtensions
.
The call:
const osg::FBOExtensions* fbo_ext = osg::FBOExtensions::instance(ctx, true);
Will have to be replaced with:
const osg::GLExtensions* fbo_ext = state.get<osg::GLExtensions>();
Implement support for positional tracking. Oculus Rift Developer Kit 2 and camera required for testing.
I'm trying to build FlightGear (http://www.flightgear.org/) flight simulator using this library. Changing the default OSGView library for OSGOculusViewer library will help ?
Previous version (ie. Oct 27) worked OK, now I am getting a segfault when running the Composite viewer. Other viewers function OK.
Seen below without Rift connected, I have a 'fake' rift and don't want that to confuse the issue.
simon@bigbox:/storage/osgoculusviewer-git$ git log | head
commit ceca3c16a5a9af739e7abd3eb5c0eddee286fe5e
Author: Björn Blissing <[email protected]>
Date: Mon Nov 3 14:45:29 2014 +0100
Xinerama is not a dependency for OVR since 0.4.x
commit 097852a9eb5a81a43b39437a7c402f4094d1d3d5
Merge: 1120932 0bd1158
Author: Björn Blissing <[email protected]>
Date: Fri Oct 31 14:54:36 2014 +0100
simon@bigbox:/storage/osgoculusviewer-git$ gdb ./bin/OculusCompositeViewerExample
GNU gdb (Ubuntu 7.7-0ubuntu3.1) 7.7
Copyright (C) 2014 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./bin/OculusCompositeViewerExample...done.
(gdb) r /storage/speed-dreams-git-svn/data/data/objects/wheel2.ac
Starting program: /storage/osgoculusviewer-git/bin/OculusCompositeViewerExample /storage/speed-dreams-git-svn/data/data/objects/wheel2.ac
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff7fcd700 (LWP 3316)]
Warning: No device could be found. Creating emulated device
Product: Oculus Rift DK1
Manufacturer: Oculus VR
VendorId: -1
ProductId: -1
SerialNumber:
FirmwareVersion: -1.-1
osgDB ac3d reader: could not find texture "wheel3d.png"
osgDB ac3d reader: could not find texture "wheel3d.png"
Program received signal SIGSEGV, Segmentation fault.
0x0000000000446db2 in osg::ref_ptr<osg::GraphicsContext::Traits>::get (this=0x40) at /usr/include/osg/ref_ptr:92
92 T* get() const { return _ptr; }
(gdb) bt
#0 0x0000000000446db2 in osg::ref_ptr<osg::GraphicsContext::Traits>::get (this=0x40) at /usr/include/osg/ref_ptr:92
#1 0x000000000044656a in osg::GraphicsContext::getTraits (this=0x0) at /usr/include/osg/GraphicsContext:286
#2 0x0000000000444397 in OculusDevice::createRTTCamera (this=0x73cd60, texture=0x745420, eye=OculusDevice::LEFT,
referenceFrame=osg::Transform::ABSOLUTE_RF, gc=0x0) at oculusdevice.cpp:469
#3 0x000000000043e177 in main (argc=2, argv=0x7fffffffdf88) at compositeviewerexample.cpp:45
(gdb)
Should include something like the SDK version:
float percievedHalfRTDistance = (HMD.VScreenSize / 2) * Distortion.Scale;
YFov = 2.0f * atan(percievedHalfRTDistance/HMD.EyeToScreenDistance);
On Ubuntu 14.10, my DK2 display shows up in portrait orientation, but the viewer creates a window seems to assume landscape. I'm interested in helping to debug the issue, but I wanted to make sure this was actually a bug and not a failure on my part to properly configure the display settings.
As far as I can tell, this results in the left eye being rendered where the right eye should be, with the right eye off the screen, and the image rotated by 90 degrees.
The Oculus world demo functions properly on my display.
The function printHMDDebugInfo()
only prints garbage.
oculusdevice.h
contains variable initializations using C++11 style. This breaks compilation on Visual Studio 2010.
The new version of the Oculus SDK requires some reworking. Only SDK based distortion rendering is supported. So the client distortion rendering code have to be removed.
Oculus have also paused all support for Linux and Mac, so this version will be for Windows only.
Since updating to the 0.6.0.1 version, I've noticed that I seem to need to call OculusDevice::resetSensorOrientation() i.e. ovrHmd_RecenterPose(m_hmdDevice); every time I restart my application because the default orientation seems to be different from the recentered pose.
Am I doing something wrong? Or do we need to add an explicit call to recenter pose on application/viewer startup?
During testing I have experienced some odd near clipping issues. Investigate if near/far cull settings should be moved from slave camera to main camera.
In short moving the following statement from RTT Camera to main viewer camera.
camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR );
Can anyone give a pointer in the right direction? It doesn't seem to detect the OculusSDK.
/d/osg-toolchain/cmake-3.3.2/bin/cmake -G "Unix Makefiles" -DOSG_DIR=/d/osg-toolchain/OpenSceneGraph-3.4.0 -DOSG_THIRD_PARTY_DIR=/d/osg-toolchain/osg_thirdparty/ -DOCULUS_SDK_ROOT_DIR=/d/osg-toolchain/OculusSDK ..
-- Found osgViewer: d:/osg-toolchain/OpenSceneGraph-3.4.0/build/lib/libosgViewer.dll.a
-- Found osgDB: d:/osg-toolchain/OpenSceneGraph-3.4.0/build/lib/libosgDB.dll.a
-- Found osgGA: d:/osg-toolchain/OpenSceneGraph-3.4.0/build/lib/libosgGA.dll.a
-- Found osgUtil: d:/osg-toolchain/OpenSceneGraph-3.4.0/build/lib/libosgUtil.dll.a
-- Found OpenThreads: d:/osg-toolchain/OpenSceneGraph-3.4.0/build/lib/libOpenThreads.dll.a
-- Found OpenSceneGraph: d:/osg-toolchain/OpenSceneGraph-3.4.0/build/lib/libosgViewer.dll.a;d:/osg-toolchain/OpenSceneGraph-3.4.0/build/lib/libosgDB.dll.a;d:/osg-toolchain/OpenSceneGraph-3.4.0/build/lib/libosgGA.dll.a;d:/osg-toolchain/OpenSceneGraph-3.4.0/build/lib/libosgUtil.dll.a;d:/osg-toolchain/OpenSceneGraph-3.4.0/build/lib/libosg.dll.a;d:/osg-toolchain/OpenSceneGraph-3.4.0/build/lib/libOpenThreads.dll.a (found version "3.4.0")
CMake Error at d:/osg-toolchain/cmake-3.3.2/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find OculusSDK (missing: OCULUS_SDK_LIBRARIES)
Call Stack (most recent call first):
d:/osg-toolchain/cmake-3.3.2/share/cmake-3.3/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
cmake/FindOculusSDK.cmake:103 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:56 (FIND_PACKAGE)
So far I've been digging through the findOculus cmake file and related files and I've been unable to find out why it cannot find the Oculus SDK.
The console window outputs OpenGL errors when running in OculusViewConfigExample and OculusViewerExample (OculusCompositeViewerExample works without errors).
Warning: detected OpenGL error 'invalid operation' at after RenderBin::draw(..)
I use NodeTrackerManipulator in the scene to make the main camera tracking a flying plane, when I use the DrawThreadPerContext model, RTT cameras will jitter, especially the left RTT, this phenomenon seems to be slave cameras update before the master camera occasionally, resulting in non synchronization.
When using SingleThreaded model, there is no jitter, I also notice the SingleThreaded is forced to use in viewerexample,but the frame rate will be significantly reduced with this model. Is there anyway to fix this issue.
The Oculus SDK contains functions for handling the timing of appropriate display time of the Oculus Health and Safety Warnings.
ovrHmd_GetHSWDisplayState()
starts the time and returns the current state.
ovrHmd_DismissHSWDisplay()
tries to dismiss the warning. Returns false if the warning time is not reached.
TimeWarp shader do not work correctly when running with an emulated device.
The application crashes if we try to start without a HMD plugged in or a debug HMD configured in the Oculus Configuration Utility.
I've just been checking though my changes for MSAA support and noticed that I had to put in a kludge to swap the left and right eye camera transforms. On investigation why that was necessary, it looks to me as though the problem may have arisen in the merging of changes to support Oculus 0.7.0.0 SDK, in 8076d60
This change removed calls to a function named renderOrder
which my guess may have been responsible for swapping the eyes images? I'm not sure, but thought it might be worth raising as a issue as I didn't want to include my kludge for a possible render order issue in my MSAA pull request.
fbo_ext->glBindFramebuffer(GL_FRAMEBUFFER_EXT, fbo->getHandle(ctx));
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.