SlightlyMad / VolumetricLights

Volumetric Lights for Unity
BSD 3-Clause "New" or "Revised" License
2.05k stars 303 forks source link

VR Compatibility #9

Open Knive opened 7 years ago

Knive commented 7 years ago

The lights are great but in VR (with an HTC Vive), they are somewhat shifted from the original position in both the right and the left eye but on different positions depending on the eye.

SlightlyMad commented 7 years ago

VR isn't supported. I don't have VR kit to test it and I don't plan to buy one. I'll accept pull request if somebody finds a way how to fix it and I'll update readme for now.

Edgyy commented 7 years ago

Hi, just to provide some further insight, I attempted to use the Oculus SDK OVRCameraRig which allows you to choose either two separate cameras (one per eye) or a single one. Unfortunately, this didn't work properly with either.

When adding the Volumetric Light Renderer to each eye's camera separately, by default the volumetric lights appear only in the second camera (right eye) but not the first one (left eye). If you change the "depth" of the camera, the camera with the lowest depth shows the effect whilst the other one does not. Switching between deferred and forward rendering for both cameras also does not change the behaviour. One interesting point is that if you choose Single Pass Stereoscopic Rendering as opposed to the default Multi-Pass Stereoscopic Rendering, there are problems because the shader breaks the image (get a weird overlay and resolution is all wrong - it seems that a lot of effects, even standard Unity ones such as "Bloom" or "Sun Shafts" etc. also break) but it seems like the effect works for both cameras. So possibly there is a compatibility issue with the multi-pass rendering?

@SlightlyMad I would be willing to help with testing of new changes and contribute in any way. Thanks.

chrisnobrega commented 7 years ago

@SlightlyMad I'm also willing to help test any changes on the HTC Vive. That way we can cover both platforms.

javl commented 7 years ago

Pinging @Knive, @Edgyy and @chrisnobrega to check if any of you looked into this further. Maybe we can figure out what is going on together.

Trying the examples with the SteamVR plugin I can get the effect to work on one eye at a time only:

cam one target cam two target result left result right
left right no effect effect
right left effect no effect
left left no effect black
left off effect black
off left effect off
right right black no effect
off right black effect
right off black effect

I'm new to Unity and not quite sure about the way the two images for your different eyes get rendered. When I put a debug script line into the VolumetricLightRenderer script to check what camera it is drawing to, I get both. I was hoping it was somehow just drawing to one eye.

Debug.Log ("render to: ___" + _camera.stereoTargetEye +"___", _camera);
// Outputs: render to ___Both___
kwnetzwelt commented 7 years ago

This is exactly the issue. Set the camera to only draw to one eye, and create a separate camera for the other eye, that will work fine!

OEN007 commented 6 years ago

Unity hangs when i have two Steam VR_Camera cameras in the SteamVR rig and press play

kwnetzwelt commented 6 years ago

The issue here is the steam vr camera component. You should only have one of that.

millenniummike commented 6 years ago

I got this working on Unity 2017.3.0f3 Opening example scene Enabling PlayerSettings - XR Settings - Virtual Reality Supported Duplicating Main Camera Setting Camera 1 to left eye Setting Camera 2 to right eye

Tried on HTC Vive and it looks pretty good.

The Directional light examples all worked but spotlight ones render to one eye hence the workaround above.

ruonanzh commented 6 years ago

For now, it works in Unity with Multpass on. I am using Unity 2017.4.8f1 and OpenVR. It is correct rendered on both eye if the light don't cast any shadow.

Wired thing about light casting shadow, it only show on the left eye. I am looking into this now.