googlevr / cardboard

Open source Cardboard SDK and samples
Other
1.49k stars 256 forks source link

Is it possible to render different objects to each eye? #146

Open Xirion11 opened 4 years ago

Xirion11 commented 4 years ago

I want to be able to show different objects in each eye in Android/iOS.

In the now obsolete sdk it was possible to set a different target eye to each of two cameras and you could control which object were rendered with the culling mask property. With the new cardboard sdk whenever I try to get the same result I either end up:

I believe this happens when I enable the checkbox "Virtual reality supported" under Player settings -> XR Settings (since this checkbox is needed to enable the target eye field in the cameras)

dletozeun commented 4 years ago

Hi,

Check: unity_StereoEyeIndex and example there: https://docs.unity3d.com/Manual/SinglePassStereoRendering.html

This allows you at least in the shader to treat each eye differently.

jballoffet commented 4 years ago

Cardboard SDK does not support rendering different objects to each eye and there are currently no plans to support it. However, it may be considered in a future update.

yuhany1024 commented 4 years ago

I also want to render different contents to two eyes. I wonder which version SDK can achieve it? If I create two cameras targeted to different eyes. Do the cameras have the same position or should be separated by 6cm(eye distance)?

Xirion11 commented 4 years ago

I also want to render different contents to two eyes. I wonder which version SDK can achieve it? If I create two cameras targeted to different eyes. Do the cameras have the same position or should be separated by 6cm(eye distance)?

If you use the GVR SDK (now obsolete for iOS) you can do so, that's the one we are using. You just need to go to your cameras and define which eye they should render; you also need to define which layers to cull, basically the left camera should not see objects in the "right" layer and the right camera should not see objects in the "left" layer. The plugin will manage the cameras position and angle

hi4c0ck commented 3 years ago

Also interested to get this feature as soon as possible. Seems like, we can't use Cardboard XR in common case, although, we cannot use GVR with actual iPhones. Any workarounds possible?

Acimaz commented 3 years ago

I am interested as well and I'm searching for a quick solution for this. Downloaded the old gvr sdk but the documentation is not too great and I am a bit stuck atm.

Acimaz commented 3 years ago

Hi,

Check: unity_StereoEyeIndex and example there: https://docs.unity3d.com/Manual/SinglePassStereoRendering.html

This allows you at least in the shader to treat each eye differently.

It took me a while but I finally found a solution that also works with shader graph using unity 2020.2. Here is a description and some screens of the custom node I used: https://forum.unity.com/threads/render-different-color-depending-on-stereo-eye-index.1037215/

Ste-RH commented 3 years ago

Does anyone know if there is a define we can use in a shader to know if 'unity_StereoEyeIndex' is valid for use?

In Unity I have been using 'UNITY_SINGLE_PASS_STEREO' and 'UNITY_STEREO_INSTANCING_ENABLED' to cover most bases, but the Cardboard XR Plugin does not fall into line with these.

jballoffet commented 3 years ago

Currently the Cardboard XR Plugin display provider has single pass rendering support disabled. Now that OpenGL ES 3 is supported by the SDK this flag should be able to change to true (see https://github.com/googlevr/cardboard/blob/4382d959a62196405ab75a237b5c39094a137c6e/sdk/unity/xr_provider/display.cc#L108 and https://github.com/googlevr/cardboard/blob/4382d959a62196405ab75a237b5c39094a137c6e/third_party/unity_plugin_api/IUnityXRDisplay.h#L402). Then, per https://github.com/googlevr/cardboard/blob/4382d959a62196405ab75a237b5c39094a137c6e/third_party/unity_plugin_api/IUnityXRDisplay.h#L192 and https://github.com/googlevr/cardboard/blob/4382d959a62196405ab75a237b5c39094a137c6e/third_party/unity_plugin_api/IUnityXRDisplay.h#L205, with a single rendering pass, two pose/projection matrices (RenderParams) could be used.

Patches here are welcome.

rev111 commented 3 years ago

Currently the Cardboard XR Plugin display provider has single pass rendering support disabled. Now that OpenGL ES 3 is supported by the SDK this flag should be able to change to true (see

https://github.com/googlevr/cardboard/blob/4382d959a62196405ab75a237b5c39094a137c6e/sdk/unity/xr_provider/display.cc#L108

and https://github.com/googlevr/cardboard/blob/4382d959a62196405ab75a237b5c39094a137c6e/third_party/unity_plugin_api/IUnityXRDisplay.h#L402

). Then, per https://github.com/googlevr/cardboard/blob/4382d959a62196405ab75a237b5c39094a137c6e/third_party/unity_plugin_api/IUnityXRDisplay.h#L192

and https://github.com/googlevr/cardboard/blob/4382d959a62196405ab75a237b5c39094a137c6e/third_party/unity_plugin_api/IUnityXRDisplay.h#L205

, with a single rendering pass, two pose/projection matrices (RenderParams) could be used. Patches here are welcome.

This might be a stupid question, but how can I test this? I guess I would have to compile the Unity XR plugin, how? Also, would you expect this to work on the upcoming release that would work on Metal / iOS / Unity 2020?

Edit: I think I understand what you are proposing and I see the source files where the changes should be made, but I have no idea how to put this into the XR package (if that is even the way this should be done).

jballoffet commented 3 years ago

@rev111, you will need to build the SDK with Android and/or Xcode and then overwrite the prebuilt binaries in the XR plugin package. You can find instructions to do so here and here. Hope this helps.

rev111 commented 3 years ago

@rev111, you will need to build the SDK with Android and/or Xcode and then overwrite the prebuilt binaries in the XR plugin package. You can find instructions to do so here and here. Hope this helps.

Thank you very much. I was able to rebuild the SDK for iOS. But I am still confused about

Now that OpenGL ES 3 is supported by the SDK this flag should be able to change to true (see rendering_caps->noSinglePassRenderingSupport = true;

So the SDK has only multipass enabled right now, is that correct? Shouldn't that then be "false", as "false" would enable single pass rendering?

(Edit) I built the binary with rendering_caps->noSinglePassRenderingSupport = false; I put a log entry above that change and it shows up in the XCode debugger. So far I can't see any difference when experimenting with a shader graph. unity_StereoEyeIndex appears to always return 0. Does anyone know how I could check if single pass rendering is enabled on the device? To confirm.

jballoffet commented 3 years ago

Shouldn't that then be "false", as "false" would enable single pass rendering?

Correct, setting it to false should enable single pass rendering.

Does anyone know how I could check if single pass rendering is enabled on the device?

IMO, the best way to debug this is by using the Frame Capture Debugging Tools in Xcode. You should be able to notice whether the rendering is being performed on a single pass or multiple passes.

Hope this helps.

Pepn commented 1 year ago

Anyone able to replicate this in Unity 2022.2 with URP? Does not seem to work

cacard commented 1 year ago

rendering_caps->noSinglePassRenderingSupport = false; The fps not change... why?

helifax commented 7 months ago

Is changing the above from true to false, actually enable single pass (multiview) rendering in cardboard SDK or there are other changes/missing code that is needed? (OpenGL ES 3.2 or Vulkan)?

Thank you, in advance!