Search Unity

Nekativ's Standard PBR Realtime Stereo Planar Reflections

Discussion in 'General Graphics' started by Nekativ, Jul 22, 2017.

  1. Nekativ

    Nekativ

    Joined:
    Jun 30, 2017
    Posts:
    9
    Here is my chance to give a little bit back to a helpful community.

    This is an extension to the standard shader to support realtime planar reflections for objects on a specific layer. The realtime reflections are combined with the reflections from the reflection probe. The reflections are properly distorted by the normal map and will have the proper roughness from the smooth map and smoothness slider.

    Basically, apply the script to the floor or tabletop, select this shader over standard, and everything should act as if you are using the standard shader only now you have realtime reflections from the objects on your desired layer.

    Smooth>LessSmooth>LeastSmooth
    Example1.jpg

    The brief backstory is you shouldn't use deferred rendering with VR since VR looks terrible without MSAA and the performance cost is too high. This leaves out using SSR since it is not compatible with forward rendering mode.

    As a result of the above limitation, all dynamic objects appear to be floating especially in situations where the dynamic object is not casting dynamic shadows because it's in an occluded area. Ambient Occlusion *could* *help* alleviate this effect however the cost for AO is too high in combination with super sampling.

    This solution helps improves immersion a lot. As for performance in VR, I am at 120fps with SS at 2 in my Vive with a full scene. I have a Gforce GTX 1070.

    I am calling this version 0.9 until I can address the following shortcomings:

    -I would like to add single-pass support, right now it is multi-pass only for VR

    -The convolution on the planar reflection is simple Gaussian blur, I would like to explore making this more like the specular convolution in the cube maps, however I have more to learn on this subject and I am not sure if it really matters.

    -I would like to add an extendable list in the inspector for "PlanarReflections.cs" that will contain the specific materials you want "PlanarReflections.cs" to send the reflection texture it is generating too. This will help with managing several instances of "PlanarReflections.cs" on multiple surfaces.

    If you have any additional ideas, please let me know and I will implement it if I am able.

    I am happy to have this picked apart by those that know more. So please if you have any insight on how to make this better please let me know.
     

    Attached Files:

    Last edited: Jul 23, 2017
  2. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    I already looked into this and came to the conclusion that Gaussian is actually a very good approximation. The thing you are missing is that the actual amount of blur of the reflection also greatly depends on the distance between the reflecting and reflected surfaces. (The same actually goes for the effect the normal map has.)

    When you are using multiple blur levels, the advantage of Gaussian is that it can be stacked. Apart from rounding and sampling differences a blur with deviation 3 on top of a blur with deviation 4 is the same as a single blur with deviation 5.

    Where the floor reflects the book case is a good example of the variation in blur here:
    FINES_Cam11A.jpg
     
  3. Nekativ

    Nekativ

    Joined:
    Jun 30, 2017
    Posts:
    9
    Very nice.

    Do you use the depth map of a texture to determine how blurry something should be based on the distance from the reflective surface?

    Also I have briefly read about utilizing fourier transforms to achieve a faster more effective blur however I haven't looked into it past reading that statement.
     
    tigerleapgorge likes this.
  4. jvo3dc

    jvo3dc

    Joined:
    Oct 11, 2013
    Posts:
    1,520
    Yes, two depth buffers actually. The one of the main render and the one of the reflected render.
     
    tigerleapgorge likes this.
  5. ArchVizPRO

    ArchVizPRO

    Joined:
    Apr 27, 2014
    Posts:
    457
    Hello
    Thank you for this! Really it's a life saver!
    Support for single pass would be awesome.
    Thank you again for sharing
    Regards
     
  6. Tom-Goethals

    Tom-Goethals

    Joined:
    Mar 6, 2015
    Posts:
    102
    Hi Nekativ,

    Had to change line 105 to float4 in shader for it to work in Unity 2018.
    Works great, understandably it takes a decent performance hit when i'm using it on 3 mirrors (car with rearview mirrors)

    What would it take for it to work in single pass?

    I've tried 3 different solutions for mirrors in VR and yours is the only one i could get to work.

    Thanks!
     
  7. Nekativ

    Nekativ

    Joined:
    Jun 30, 2017
    Posts:
    9
    Thanks for the information, I will go ahead and update the shader. Perhaps I should put this up on github...

    I will look back into adding single pass support, hopefully the API has evolved more.
     
  8. TWalden

    TWalden

    Joined:
    Jun 6, 2019
    Posts:
    2
    I'm on a project that's well into development (so I couldn't just swap to hdrp and use the new planar probes) and I wanted dynamic reflections on the shiny floors in vr, this works perfectly. Thank you so much.