Oculus Rift with osgEarth 2.10.0 DEV

classic Classic list List threaded Threaded
11 messages Options
Nikkitta Nikkitta
Reply | Threaded
Open this post in threaded view
|

Oculus Rift with osgEarth 2.10.0 DEV

This post was updated on .
Hi,
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 Rooi here 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
VendorId:        NNNNN
ProductId:       NN
SerialNumber:    WMHDNNNNNNNNNN
FirmwareVersion: 7.8
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?
Best regards,
Nikita Petrov
Nikkitta Nikkitta
Reply | Threaded
Open this post in threaded view
|

Re: Oculus Rift with osgEarth 2.10.0 DEV

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
	if (!oculusDevice->hmdPresent())
	{
		osg::notify(osg::FATAL) << "Error: No valid HMD present!" << std::endl;
		return 1;
	}

	// 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());

	if (!gc)
	{
		osg::notify(osg::NOTICE) << "Error, GraphicsWindow has not been created successfully" << std::endl;
		return 1;
	}

	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.get());
	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);

	// Things to do when viewer is realized
	osg::ref_ptr<OculusRealizeOperation> oculusRealizeOperation = new OculusRealizeOperation(oculusDevice);
	viewer.setRealizeOperation(oculusRealizeOperation.get());

#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);
	viewer.setCleanUpOperation(oculusCleanUpOperation.get());
#endif

	osg::ref_ptr<OculusViewer> oculusViewer = new OculusViewer(&viewer, oculusDevice, oculusRealizeOperation);
	oculusViewer->addChild(globe.get());
	viewer.setSceneData(oculusViewer.get());

	// Manipulate with mouse. Oculus is just for viewing.
	osg::ref_ptr<osgEarth::Util::EarthManipulator> earthManipulator = new osgEarth::Util::EarthManipulator();
	viewer.setCameraManipulator(earthManipulator.get());

	viewer.getCamera()->setSmallFeatureCullingPixelSize(-1.0f);
	viewer.getCamera()->setNearFarRatio(0.00002);

	// Add statistics handler
	viewer.addEventHandler(new osgViewer::StatsHandler);

	viewer.addEventHandler(new OculusEventHandler(oculusDevice));

	viewer.run();

	return 0;
}
Best regards,
Nikita Petrov
Nikkitta Nikkitta
Reply | Threaded
Open this post in threaded view
|

Re: Oculus Rift with osgEarth 2.10.0 DEV

This post was updated on .
Did some experiments and here are the results:

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:
Oculus with MP driver
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.

Any suggestions are welcomed here.
Best regards,
Nikita Petrov
Nikkitta Nikkitta
Reply | Threaded
Open this post in threaded view
|

Re: Oculus Rift with osgEarth 2.10.0 DEV

Update.
I did the changes to OSG according to previously mentioned thread from this commit (thanks to Philippe Renon). And now I have image on the screen with REX driver!

So I decided to take a video, showing current problems with buildings, trees, grass and low frame rate.


I noticed that problem of flickering occurs with distance from camera. So if I move camera close to the grass - it looks great. But the farther from the camera the object is, the more it flickers.

Buildings also behave strange - they keep appearing and disappearing even on small head movement.
Best regards,
Nikita Petrov
jasonbeverage jasonbeverage
Reply | Threaded
Open this post in threaded view
|

Re: Oculus Rift with osgEarth 2.10.0 DEV

The flickering might be due to the near far ratio.

You can try changing this in code like:
viewer.getCamera()->setNearFarRatio(0.0001);

Or do it with an environment variable:
set OSG_NEAR_FAR_RATIO=0.0001

Jason

On Fri, Mar 16, 2018 at 9:58 AM Nikkitta [via osgEarth] <[hidden email]> wrote:
Update.
I did the changes to OSG according to previously mentioned thread from this commit (thanks to Philippe Renon). And now I have image on the screen with REX driver!

So I decided to take a video, showing current problems with buildings, trees, grass and low frame rate.


I noticed that problem of flickering occurs with distance from camera. So if I move camera close to the grass - it looks great. But the farther from the camera the object is, the more it flickers.

Buildings also behave strange - they keep appearing and disappearing even on small head movement.
Best regards,
Nikita Petrov



If you reply to this email, your message will be added to the discussion below:
To start a new topic under osgEarth, email [hidden email]
To unsubscribe from osgEarth, click here.
NAML
Nikkitta Nikkitta
Reply | Threaded
Open this post in threaded view
|

Re: Oculus Rift with osgEarth 2.10.0 DEV

Thanks for the reply!
I will be able to test it on Monday and I'll write back about results.
Best regards,
Nikita Petrov
Nikkitta Nikkitta
Reply | Threaded
Open this post in threaded view
|

Re: Oculus Rift with osgEarth 2.10.0 DEV

In reply to this post by jasonbeverage
Unfortunately setting NearFarRatio to 0.0001 didn't help. Buildings look the same:


Parts that are very close to camera looks almost fine.
Best regards,
Nikita Petrov
Nikkitta Nikkitta
Reply | Threaded
Open this post in threaded view
|

Re: Oculus Rift with osgEarth 2.10.0 DEV

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.
Best regards,
Nikita Petrov
Nikkitta Nikkitta
Reply | Threaded
Open this post in threaded view
|

Re: Oculus Rift with osgEarth 2.10.0 DEV

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).
Best regards,
Nikita Petrov
jay jay
Reply | Threaded
Open this post in threaded view
|

Re: Oculus Rift with osgEarth 2.10.0 DEV

Hi,

Did you try integration with HTC vive too with openvrviewer etc?


thanks
Nikkitta Nikkitta
Reply | Threaded
Open this post in threaded view
|

Re: Oculus Rift with osgEarth 2.10.0 DEV

No, unfortunately I don't have HTC Vive device available. Currently I'm working only with Oculus Rift.
Best regards,
Nikita Petrov