Rufus31415 / Simple-WebXR-Unity

⭐ Bringing WebXR to Unity 3D ! B-)
https://rufus31415.github.io/webxr/MRTK-HandInteraction/
MIT License
576 stars 82 forks source link

Left and Right camera settings #26

Closed HawkenKing closed 3 years ago

HawkenKing commented 3 years ago

In some cases, it is desirable to have camera settings like layers, tags and so on exposed for customisation, to enable stereoscopic effects or hiding layers.

Having the camera rig generated at run time is a barrier to this kind of customisation.

Tested on Oculus Quest Browser

Rufus31415 commented 3 years ago

What about having the following serialized fields :

Camera LeftCameraTemplate;
Camera RightCameraTemplate;

CameraModes LeftCameraMode = CameraModes.UseMainCamera;
CameraModes RightCameraMode = CameraModes.CloneMainCamera;

CameraProperties CameraProperties;

public enum CameraModes {
   UseTemplateCamera,
   CloneTemplateCamera,
   CreateNewCamera,
   UseMainCamera,
   CloneMainCamera
}

public enum CameraProperties
   AutoSetRecommendedSettings, // transparent background in AR for instance. The previous settings would be reset at the end of the session.
   DoNotModifyCamera
}

Rather than SimpleWebXR acts on camera.transform.position of each camera, it could act on camera.transform.localPosition.

Btw, at any time, (for example on the SimpleWebXR.SessionStarts event), the user code can access the SimpleWebXR.LeftCamera and SimpleWebXR.RightCamera properties, if really what I propose here is not sufficiently complete

Let's imagine the following scenarios:

  1. The user leaves the default properties : LeftCamera is Camera.Main, RightCamera is a clone of Camera.Main created under the same parent.

  2. If the user wants to have full control of the cameras (As you mention it : layers, tags, set parent position for teleport ...), he can create them disabled in his scene and associate them to LeftCameraTemplate and RightCameraTemplate, then set modes to CameraModes.UseTemplateCamera. If the camera template is not in the scene but comes from a prefab, it can use the mode CameraModes.CloneTemplateCamera.

What do you think of this way of doing things?

Rufus31415 commented 3 years ago

Also, if no camera is using the CameraModes.UseMainCamera mode, we call Camera.Main.SetActive(false) at the start of the immersive session.

HawkenKing commented 3 years ago

Might be a bit opaque to anyone using the system. The camera generation system is unique, usually the user can edit all of these settings on multiple cameras in the scene using the inspector.

Rufus31415 commented 3 years ago

It is true. What if you also had a simulator that allows you to start a fake immersive session in unity, with the 2 cameras?

HawkenKing commented 3 years ago

I think at the very least you need 3 cameras, 1 for the initial pancake view in the browser and one for each eye at tracked hmd level

StephenHodgson commented 3 years ago

Honestly surprised about the need to have more than one Camera anyway since Unity recently changed how the stereoscopic camera works. Although I suppose you might actually need a XR Display Subsystem.

Rufus31415 commented 3 years ago

Good point, I'm going to dig into this: https://docs.unity3d.com/ScriptReference/XR.XRDisplaySubsystem.html

Rufus31415 commented 3 years ago

In fact, XR plugin is not yet compatible with WebGL : https://forum.unity.com/threads/low-level-plug-in-interface-unityregisterrenderingplugin-and-xr-interfaces.983298/#post-6397985

StephenHodgson commented 3 years ago

This is true. WebGL in Unity doesn't support threading yet, but it is def on the roadmap.

In either case, I still believe it is possible to enable the Stereoscopic rendering without the subsystems.

HawkenKing commented 3 years ago

afaik single pass isn't available yet in webxr

Rufus31415 commented 3 years ago

Camera properties like stereoEnabled, stereoSeparation are used by the XR Plugin which is still not available for WebGL.

StephenHodgson commented 3 years ago

What are the analogues in WebGL?

Rufus31415 commented 3 years ago

What do you mean by analogues ?

StephenHodgson commented 3 years ago

Is there something that functions in a similar capacity?

Rufus31415 commented 3 years ago

Using 2 cameras, I can't find anything else...

Rufus31415 commented 3 years ago

The compatibility of XR Plugin with WebGL is not a priority for the Unity dev team, but it may be something that will come one day. I spoke with De-Panther who asked the question because he has the same problem as us: https://forum.unity.com/threads/low-level-plug-in-interface-unityregisterrenderingplugin-and-xr-interfaces.983298

StephenHodgson commented 3 years ago

Yup sounds about right. That's part of why I wasn't keen on the XR Subsystems. I hate that they are playing gate keeper. Unity used to be easy enough to hack and get something working when needed.

StephenHodgson commented 3 years ago

I'm sure there's still a way, but it's likely not publicly disclosed, or available via a public API.

StephenHodgson commented 3 years ago

This was an interesting read: https://blog.mozvr.com/multiview-on-webxr/

StephenHodgson commented 3 years ago

https://developer.oculus.com/documentation/oculus-browser/browser-multiview/