Cocos2dx VR API

i have a question, it seems that distortion logic is optimized by headset manufacturer in the device sdk , so maybe the generic logic can’t support all the hardware. am i right?

to support the same visual feeling for user producer (game studio) and customer , it is much better use the same logic in the engine (or sdk) and the device. am i right?

last, @ricardo would you like to the check this video.
https://www.youtube.com/watch?v=1dcoKWOlGAA it is ported from cardboard java logic to obj-c , to suport ios.

correct. The generic code is useful only for quick-n-dirty testing… let’s say that you want to test VR on a windows phone and no SDKs are available, then you can use our generic implementation.

Users should use the official SDKs: cardboard SDK, oculus sdk, etc…

1 Like

Cool. thanks for your confirmation.

@ricardo I have sent a PR to you.

I didn’t upload the 3rdParty(SDKS). If you want to compile code, please download from here and move them to the cocos2d-x/external folder:

@ricardo For now, I have found the following BUGS that we need resolve:

  • The ProjectionMatrix error, different VR SKD define specific ProjectionMatrix Information for VR rendering, we need replace the camera’s ProjectionMatrix by the SKD’s ProjectionMatrix, otherwise, we will see the rendering error when we using headtracking.

the texts distortion occurred

I have found two ways to solved this problem:

a) passing SKD’s ProjectionMatrix to scene
replace
Scene::render(Renderer* renderer, const Mat4& eyeTransform)
by
Scene::render(Renderer* renderer, const Mat4& eyeTransform, const Mat4& eyeProjection)
and replace
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix());
by
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, eyeProjection * Camera::_visitingCamera->getViewMatrix());

b) VRIRenderer provide a interface like virtual VRIPerspective getSuggestedPerspective() const = 0;
and for default camera, we can doing some changes in Camera::initDefault()

        float zeye = Director::getInstance()->getZEye();
        Vec3 eye, center, up;
        if (Director::getInstance()->getOpenGLView() && Director::getInstance()->getOpenGLView()->isVREnabled()){
            auto perspective = Director::getInstance()->getOpenGLView()->getVRRenderer()->getSuggestedPerspective();
            initPerspective(perspective.fov, perspective.width / perspective.height, perspective.zNear, zeye + perspective.height / 2.0f);
        }else{
            //initialization like before
        }

for user camera, developers need calling Director::getInstance()->getOpenGLView()->getVRRenderer()->getSuggestedPerspective() to get the perspective information and using it to create camera by Camera::createPerspective.
would you like a) or b), or other ideas?

  • Culling error, part of the texts was culled. I haven’t found the cause of the problem, do you have any ideas?

  • Coordinate mapping error of touch event, normally, when enter the VR mode, we should not receive the touch event(because phone in VR devices, we cannot touch the screen), how can we solve this problem or have other alternatives?

a) seems to be cleaner.

I think it is a bug in the “UI Scroll list” component. we should review that code… I think it is using the camera for the culling and perhaps it is not getting the values correctly, or perhaps we introduced a bug in the camera.

For example Cardboard SDK uses touches (actually just one touch)… the touch can be in any place.
So, I think the user should disable / enable the touches when VR is enabled/disabled. We shouldn’t automate that because it varies from SDK to SDK

OK, thanks! I will review the UI code.

@songchengjiang

hey, after merging your patch in my “vr” branch, Android does not compile. It gives me this error:

Android NDK: /Users/riq/progs/cocos2d-x/tests/cpp-tests/proj.android/../../../external/recast/Android.mk: Cannot find module with tag 'gearvr/prebuild' in import path
Android NDK: Are you sure your NDK_MODULE_PATH variable is properly defined ?
Android NDK: The following directories were searched:
Android NDK:
make: Entering directory `/Users/riq/progs/cocos2d-x/tests/cpp-tests/proj.android'
/Users/riq/progs/cocos2d-x/tests/cpp-tests/proj.android/../../../cocos/Android.mk:332: *** Android NDK: Aborting.    .  Stop.
make: Leaving directory `/Users/riq/progs/cocos2d-x/tests/cpp-tests/proj.android'
Error running command, return code: 2.

The gearvr, cardboardsdk, and the other sdk are optional features, and cocos2d-x should compile and run without them. Once we have the package manager working, users should install the different SDKs using the package manager.

In the meantime, could you remove the gearvr dependency? Thanks!

@songchengjiang
Another thing that we need to discuss is the workflow.

For example, I tried to compile your VR patch, but it fails because it requires the “deepoon/include/deepoon_sdk_native.h” file.

Of course, the solution is to avoid compiling the “CCVRDeepon*” files. Or to tell users to install Deepon and put it in the path. But those two solutions are not good from a UX point of view.

So either:

  • the “CCVRDeepon*” (and the other SDK*) should not be part of cocos2d-x
  • or users should not be forced to install the different VR SDKs in order to compile cocos2d-x.

Another way to look at it is:

  • it should work with cocos2d-x precompiled libraries.

One possible solution is to put the different CCVRDeepon* / GRVear / Oculus* files outside cocos2d-x, and tell users to include those files in their games…
Any other solution?

Cocos2d-x only includes the built-in VR module for testing or debugging.

Developers should use Cocos package to install different SDKs if they would like to test games on real devices or polish their games to VR Store.

We could have another repo for VR SDKs which is the plugins repo of cocos package.

perfect. where should we place the GearVR, Deepoon, Cardboard SDKs ?
Right now they are in cocos/vr, but they should be moved somewhere else. what is the best place? the package manager ?

I’m almost finished the integration of GVR SDK(Google’s new VR SDK for daydream and cardboard), cardboard has been test OK on Android platform. I will test daydream on nexus 6P(the only phone supports daydream at this time) next step and send a PR to @ricardo after testing is completed.

1 Like

squashed everything in one commit and sent PR here: https://github.com/cocos2d/cocos2d-x/pull/15853
tested on:

  • mac
  • ios
  • android
  • win32, win8.1 and win10
    Not tested on Linux, but I assume it should work.

The Deepoon, Cardboard, GearVR, Oculus files were removed from the repo since they should be part of the package manager (as discussed with @ShunLin).
They were preserved in this branch: https://github.com/ricardoquesada/cocos2d-x/tree/vr_full/cocos/vr

How to use it:

// In the AppDelegate, just add these two lines:
auto vrImpl = new VRGenericRenderer;
glview->setVR(vrImpl);
1 Like

PR merged. Will be part of v3.12

2 Likes

@songchengjiang Does supporting VR mean we will finally have gamepad support for platforms that support VR?

What I mean is we currently have gamepad support on iOS and Android only.

But not Windows, Linux, Mac OS X, etc.

@songchengjiang

Can you tell me how to enable each VR SDK we support? Gear, Deepoon, Oculus, Cardboard, etc.

@slackmoehrle

@songchengjiang Does supporting VR mean we will finally have gamepad support for platforms that support VR?

Yes, In finally, I think we should support gamepad on all platforms. But now the first thing we should support the VR rendering and headtracking.

@songchengjiang
Can you tell me how to enable each VR SDK we support? Gear, Deepoon, Oculus, Cardboard, etc.

We are going to use cocos package manager to manage the VR SDKs. If we want to enable GearVR, we just doing like this in command line:
-> CMP install GearVR
-> installed GearVR SDK…
-> replaced AndroidManifest.xml
->…

Then, we just add two lines in the AppDelegate as Riq said:

// In the AppDelegate, just add these two lines:
auto vrImpl = new VRGearRenderer;
glview->setVR(vrImpl);

@songchengjiang Thanks, but how do I document to the user to install a VR SDK now when we don’t have them available in the package manager already?

For example, we support Cardboard but how does the user install it when v3.12 is released in 1 day from now?

@ricardo?

yes, we should document the whole process, including how to use the package manager. Although I’m not sure if that is ready… and I haven’t used it, so I don’t know the answer