I'm trying to launch latest osgEarth with Oculus Rift CV1.
I've successfully launched latest OSG in Oculus with OsgOculusViewer.
I found a thread of Rooihere where he launched osgEarth in Oculus in 2015 with the same library.
[SOLVED] I'm trying to do the same, but no errors is shown and there is no Earth itself, I get an empty screen.
- Window on my monitor is black
- In Oculus I see ClearColor (blue)
- Manipulator is working like the Earth is there. I mean that when I zoom in I have some ordinary errors in the console like these:
Product: Oculus Rift CV1
Manufacturer: Oculus VR
Error in reading file 13.osgearth_rex_loader : file not found
Error in reading file 60.osgearth_rex_loader : file not found
Error in reading file 63.osgearth_rex_loader : file not found
Error in reading file 73.osgearth_rex_loader : file not found
If I set to use <terrain driver="mp">, then Window becomes blue (ClearColor) and divided to 2 parts, but still there is no Earth itself.
Can anybody give some suggestions how to make it work?
Okay, I've managed to launch osgEarth. The problem was in nearClip for OculusDevice, I guess it clipped the Earth.
I've set nearClip parameter as 0.00001f, but as mentioned here "It is usually better to handle the near and far plane calculation yourself". How can I correctly and should I do that?
On my Geforce GTX980 I have quite low FPS (from 0 to 45) while camera is close to the surface (because of mountains I guess). While looking "from space" everything runs smooth with 90 FPS. The most terrible part is moving head while close to surface - I have black parts of the screen being loaded, so the visual is very laggy.
My following questions are aimed at improving performance:
1. How should I correctly manage near-far clip planes?
2. How could I enable something like a "fog of war" to limit visibility from camera point and not to draw mountains located far away. I guess I should use smth like min_max_range from examples, but does it work with elevation data?
3. Any other ideas to improve performance with Oculus?
Also strange behaviour with Window, it is still black and doesn't show anything. Not a big deal, but it would be better if I can see Earth on my monitor. With simple OSG I have visuals both in Oculus and on the screen.
I will post here the working code, hope this will help to clarify some things:
int main(int argc, char** argv)
osg::ref_ptr<osg::Node> globe = osgDB::readNodeFile("D:/z13.earth");
// Open the HMD
float nearClip = 0.00001f;
float farClip = 1000.0f;
float pixelsPerDisplayPixel = 1.0f;
float worldUnitsPerMetre = 1.0f;
int samples = 0;
OculusDevice::TrackingOrigin origin = OculusDevice::TrackingOrigin::EYE_LEVEL;
int mirrorTextureWidth = 960;
osg::ref_ptr<OculusDevice> oculusDevice = new OculusDevice(nearClip, farClip, pixelsPerDisplayPixel, worldUnitsPerMetre, samples, origin, mirrorTextureWidth);
// Exit if we do not have a valid HMD present
osg::notify(osg::FATAL) << "Error: No valid HMD present!" << std::endl;
// Get the suggested context traits
osg::ref_ptr<osg::GraphicsContext::Traits> traits = oculusDevice->graphicsContextTraits();
traits->windowName = "OSGEarthOculusViewerExample";
// Create a graphic context based on our desired traits
osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
osg::notify(osg::NOTICE) << "Error, GraphicsWindow has not been created successfully" << std::endl;
gc->setClearColor(osg::Vec4(0.2f, 0.2f, 0.4f, 1.0f));
gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Force single threaded to make sure that no other thread can use the GL context
viewer.getCamera()->setViewport(0, 0, traits->width, traits->height);
// Disable automatic computation of near and far plane
// Things to do when viewer is realized
osg::ref_ptr<OculusRealizeOperation> oculusRealizeOperation = new OculusRealizeOperation(oculusDevice);
#if(OSG_VERSION_GREATER_OR_EQUAL(3, 5, 4))
// Things to do when viewer is shutting down
osg::ref_ptr<OculusCleanUpOperation> oculusCleanUpOperation = new OculusCleanUpOperation(oculusDevice);
osg::ref_ptr<OculusViewer> oculusViewer = new OculusViewer(&viewer, oculusDevice, oculusRealizeOperation);
// Manipulate with mouse. Oculus is just for viewing.
osg::ref_ptr<osgEarth::Util::EarthManipulator> earthManipulator = new osgEarth::Util::EarthManipulator();
// Add statistics handler
1. [SOLVED] I can set terrain driver to "mp" and then I get "mirrorTexture" on the screen's monitor. But it is working pretty bad, I can see image layers from the inside of the Earth:
So the problem is with REX driver and I guess maybe it is somehow connected with this issue.
2. I've downgraded my elevation data from 90m to 500m. I cropped area with elevation data, so my GeoTIFF file is now around 5 MB. The frame rate has improved significantly. But, mountains are somehow transparent, I can't attach screenshot, because I don't know how to take screenshots in Oculus and with REX monitor window is black.
3. I tried to load building and GPU trees. They are very buggy. Each building has a shimmering "chess
board"-like texture with transparent cells. The same thing happens to trees.
Buildings also have problems with disappearing. I move head to the left and building there disappear.
Oh, I thought problem with flickering and disappearing was specifically in buildings and trees/grass.
But now I'm seeing the same behaviour with 3D *.osgb models. In Oculus they become visible only when the camera is close to object and still there is a flickering.
No thoughts on the subject?
Today I've rebuilt latest OSG and osgEarth from master and 3 main problems in Oculus still exist:
1. Half-transparent mountains in Oculus. I've already wrote about this, but now I have prepared a video showing this problem:
2. Low fps with black screen parts while head is moving.
3. Flickering 3D objects, like buildings and 3D models. They look fine only when the camera is close to the object (see previous videos).
We've not done anything with the Oculus outside of having one of our customers test it with the OpenFrames framework. The flickering could be due to the manual setting of the near and far clipping planes in your code, can you somehow let osg do it's normal near/far plane computation and then update the Oculus near/far from that?