Mirrors and reflections for VR

Hi,

I’ve spent the better part of my holidays and free time creating and optimising a set of shaders and scripts to get Mirrors and other reflective surfaces working in VR. Optimised in a way that it runs smoothly on Oculus Quest 2.

There’s no limit to the amount of surfaces that can reflect each other and no limit to the amount of recursions either. However with the limited rendering budget on mobile hardware 2 recursions on 2 simultaneously visible reflective surfaces is about as far as you can get. But on PC you can really go nuts.

The shader is created using Shadergraph and supports Refraction.

It’s URP Multiview (singlepass) compatible and I’ll be releasing it to the Asset Store soon.

Here’s a quick teaser.

5 Likes

Some more rough content, testing everything

2 Likes

This look absolutely amazing! I would love to use this in my upcoming project.

When do you plan to put it on the store? I read somewhere that there is currently an approval queue for submitting new packages which is ~60-90 days.

It’s only singlepass compatible, not actually rendering the reflected view in singlepass, correct?

Sadly you’re correct, in URP, the moment you set a camera to use a targetTexture it does not render to a double wide texture anymore. Therefor i’m stuck rendering the view again for the right eye. I’m keeping an eye out for any changes in this behaviour, the moment we can render double wide in renderTextures I’m updating the asset.

1 Like

The asset was just published to the asset store.

looking forward to seeing how people use it!
Here’s the documentation:

And some nice screens

3 Likes

Looks cool! Does that consistently hit 72fps on Quest 2?

For sure, will try to find the time to release an APK to sideQuest. Not that it means much… but all video in the teaser was recorded straight of device.
(That’s why the screen is cut in half most of the shots)

2 Likes

The video looks more like 30ish fps though

Video recording straight from Quest is actually always only 24 fps that’s why i said it does not mean anything besides the fact that is was running on quest during recording. :slight_smile:
7888936--1004005--upload_2022-2-11_16-30-23.png

The demo, light baked and occlusion culled gets a smooth 72 fps on Quest 2.

But be assured this is a heavy effect! The demo is made like most level designs to limit the amount of mirrors you can see at anytime.

3 Likes

Making a few new materials as an update to the asset.

I’ve been trying to get Unity to render to a renderTexture as a doublewide texture containing both eyes.
(as the main camera does in multiview/singlepass rendering) but so far no luck.

Also have an idea to cut texture memory usage in half or more especially for deep recuring mirrors. Currently making a prototype to test this idea.


1 Like

Small tutorial like movie with bad sound showing a quick elevator model with 3 mirrors.

2 Likes

Hey, this looks great. Did you ever since the double wide rendering issue? If not, does that mean the performance is basically cut in half because you have to render it twice?

I am using a different package right and it looks great in the editor, but when I run it on the device I get the reflections doubled, like it’s rendering both eyes and the reflections seem to move all over the place. That said, I’ve been looking for a replacement package that would suit my needs.

all I need it for is a planar reflection on a arcade basketball machine. Would this work for that or is it more just for mirrors?

Hi Jingato,

I did not (yet) convert it to double wide rendering, it’s on my list to re-investigate.
(Have not read anything in the changelogs about a fix for renderTextures to support it so don’t get your hopes up)
However it won’t be made twice as fast if it works. Double wide rendering is not free either, but i imagine it would help a lot.

But still, you can do some crazy stuff on Quest2 with good practises. Check out the APK I made if you have Quest2, the link is on the bottom of the description page.
https://assetstore.unity.com/packages/vfx/shaders/fullscreen-camera-effects/mirrors-and-reflections-for-vr-212493

Reflections on an almost completely transparent glass plane (like your basketball machine) would work perfectly with the asset. You can add small refractions and smudges from dirty fingers or some spilled beer on top :slight_smile: [EDIT: added a quick test video to showcase a transparant dirty glass surface and a quick WIP for the upcoming portals asset]

I’m currently working on VR Portals. Not just rendering them correctly but support for popular rigs and everything, it’s shaping up to become something cool!

https://www.youtube.com/watch?v=ciSkpbcrzjM

8372676--1103592--upload_2022-8-18_17-27-4.png

2 Likes

Well then, SOLD! That looks very impressive. I guess that makes sense though because you are still rendering the same amount of pixels in the end That upcoming portals package looks freaking sweet too. Reminds me of Rick and Morty :slight_smile:

I’m leaving for vacation in the morning, but I’ll be looking to pick up the reflection package when I return.

Thanks for the quick response.

1 Like

Hey, so I went ahead and picked up the package and figured I’d give it a shot before taking off tomorrow and I am having quite a difficult time getting it to work. I can’t seem to get the effect I am looking for. I’ve played around with the shaders / materials and it seems as I increase specular value, the mirror effect increases, but the more I increase it the less I am able to see the texture. I can’t get it to a similar state like I had it in the previous package I was using which shows both the texture and the reflections pretty well. I’ve attached 2 screenshots to show you what I mean. If I increase the specular to the point where I have the same amount of reflections, I basically can no longer see the texture.

Is it possible to get an effect similar to this?

Also, I am trying to set the skybox material on the skybox script of the camera gameobject, but it keeps getting reverted back to nothing seemingly randomly. Is there a way to make that stick?

It seems this package may be more geared towards actual mirrors that general reflections? Or am I missing something? Perhaps I misunderstood.

Thanks for all the assistance :slight_smile:


Hi Jingato!

Thanks for supporting the asset! Your screens look good! Can’t wait to try and play that game.
It’s certainly possible to make it look like that.

Make sure you’ve baked your lighting before playing around with the spec values. Also, have a look at the documentation about textures. (EDIT: It seems I missed the part about inverting the specular map in the alpha channel in the docs, will update!)
[EDIT2: Added a dedicated page in the documentation about converting a pbr texture found here Unity URP - Mirrors and Reflections for VR - Google Docs page 16]

Basically, the alpha channel of your floor texture controls how much reflection is coming through. (that way you don’t need an extra texture lookup for your specular) The easiest way i know of is opening your texture in photoshop and adding the specular map in the alpha channel, just use the psd as the texture for fast iteration.
(!! You have to invert the specular texture of a PBR specular map for it to look correct)

8374803--1104006--upload_2022-8-19_12-36-14.png

1 Like

Excellent. I’ll give that a read and try it out in the next few days. Do you have any idea about the skybox material getting reset constantly?

No idea, I just add a skybox material to the lighting settings and I’m seeing that one in the headset, never actually added it to the camera directly. Are there any advantages to doing that? I don’t think I’m replacing it but will have a look this weekend to be sure.

Enjoy your vacation!

Thanks for having a look. I will check again as well as I will have some down time this weekend. Basically, I have my main skybox, but I need the camera that is rendering the reflections to clear to a different material setup using a cube map, like a sky map. This material is a cube map of the interior building whereas the main skybox is the outside world. I am doing this so I don’t need to render any of the static environment when rendering the reflections, just the game table. When I setup the mirror system it created a camera object and on that object is a skybox script, which I assumed you made. Maybe not though. Either way, when I set my material to it, the reflections clear to my inside room cube map material, but it keeps getting reset to nothing. Also, does the camera that was added need that flare script that is also attached to it?

thanks! I will start enjoying that vacation soon!

1 Like