AADProductions / VR-Mirrors

OpenVR-friendly mirror system for Unity.
MIT License
83 stars 17 forks source link

Support singel pass renderer #2

Open AndersMalmgren opened 8 years ago

AndersMalmgren commented 8 years ago

Hey guys. Have you seen this post?

http://forum.unity3d.com/threads/5-4-beta15-reflection-rendering-wrong-in-openvr-htc-vive.398756/#post-2622845

Thanks for the reply ccs. I should have replied to this thread a while ago with an update on how I've resolved the issue. Your solution sounds reasonable enough, but it does require modifying the main camera / render passes which isn't ideal. My solution modifies the MirrorReflection code and enables it to work without requiring any changes to the main camera (ie: a single main camera rendering all layers to both eyes). It also has the added benefit that it works just fine for single-pass stereo rendering. If we could get support for creating our own stereo cameras that render to split textures, then this could be improved even further.

Basically, I modified the MirrorReflection.shader so that it has two reflection textures, one for each eye, and it samples the appropriate texture based on which eye is being rendered (you can determine this by examining unity_StereoEyeIndex when using single pass stereo rendering, or by checking the sign of unity_CameraProjection[0][2] when using traditional multi-pass stereo rendering).

The MirrorReflection.cs is then responsible for generating the appropriate texture(s) for the camera that is being mirrored. Normal monocular cameras only require a single reflection render pass. Stereo cameras require two reflection render passes (this is where having engine support for creating our own stereo cameras that render to a single side-by-side split render texture would be super useful). Unfortunately, Unity does not currently expose the per-eye details that we need from a stereo camera (ie: position/rotation of each individual eye and the projection matrix used by each eye). I had to rely on some SteamVR APIs to access this information, and haven't yet looked into how (or if) one could do this for other VR platforms.

I've attached our modified MirrorReflection scripts in case anyone is interested.

Basicly you use _unityStereoEyeIndex when single pass is used

Railboy commented 8 years ago

We had not seen this, thank you for the heads up.

JDadders commented 7 years ago

Any chance of seeing this fix make it's way into the mirrors? They're unusable in single-pass stereo at the moment which is a shame as SPS adds some big performance benefits.

Railboy commented 7 years ago

I'm afraid we've been stretched too thin with other projects. It looks like that may not change for several weeks. Anyone want to give it a shot?

BeyondReal commented 7 years ago

There is new HTC package out on the unity store. I am not by by computer to log this into git. Maybe give that a look over. It is called "VR stereo rendering" I think. I can confirm the name and look later to see if this uses single pass. But as I recall it has a callback for before render and after render, so it might.

Trevor

On Sep 24, 2016, at 6:18 PM, Lars Simkins notifications@github.com wrote:

I'm afraid we've been stretched too thin with other projects. It looks like that may not change for several weeks. Anyone want to give it a shot?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.