Search Unity

Updating Reflection Probe at runtime... Oh my!

Discussion in 'General Graphics' started by LightStriker, Feb 16, 2018.

  1. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    For a number of reason - in part because our sky is dynamic - I have to update a set of reflection probes once in a while.

    However, even with "ReflectionProbeTimeSlicingMode.IndividualFaces", a reflection probe update cost is highly prohibitive (about 2.5 to 3 times longer than a normal render from our player camera!).

    We found out that normal "RenderProbe()" always renders in Forward mode, which is really not good for us for a number of reason, but mainly because it cost a lot more and the lighting is all wrong.

    So we tried using a "Camera.RenderToCubemap()", but it also only renders in Forward mode, regardless of the camera setting.

    We tried to find a way to "Graphics.Blit()" a RenderTexture into a Cubemap, but it also appears to be an impossibility as it only blits into the X+ side even after doing "Graphics.SetRenderTarget()" with a cubemap face. Is it even possible to Blit into a specific face of a cubemap?

    What is supposed to be the proper way of updating ReflectionProbe without killing your performance and getting a good lighting?
     
    Last edited: Feb 16, 2018
  2. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    After another full day on the topic, I finally managed to do it on my own.

    In a specific scene, we passed from 30-40ms per frame while updating a probe, to less then 10ms... While the probe is running on deferred and is able to pick particles and command-buffered lights.

    EDIT: More optimization and work; 4ms while a reflection probe is being updated. Take that!
     
    Last edited: Feb 16, 2018
  3. eobet

    eobet

    Joined:
    May 2, 2014
    Posts:
    176
    That sounds like a great thing to share with the community in a tutorial or blog post!
     
  4. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    At runtime it works flawlessly.

    I'm currently building a tool to bake deferred reflection probe, since our level artists are using quite a lot of Command Buffered decals and lights, and half our probes don't need to be update at runtime. Means I can even apply post-process on those cubemap.

    I might release an asset on the Store. Maybe 1-2$, maybe free. I'll see.
     
    exitshadow, tehusterr and Mauri like this.
  5. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Doing tests... And getting full post-process on a reflection probe is actually very cool. Example, you're underwater and have a nice color correction to make everything bit blueish. But your probe doesn't have that, so they aren't tinted properly. Or you have some bright light sources that don't "glow" properly in the reflection.


    Probe with Amplify Color and Amplify Glow on it.
     
  6. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Comparaison:


    I was surprised how much Unity normal reflection baking is having a hard time picking small emissive objects. The room is clearly blueish from all the blue emissive, but Unity's probe turns out whiteish. Unity's probes also render out decal and some transparent object totally wrong.

    Our sky is totally dynamic, which means it change colors overtime. So updating smoothing (and accurately) the reflection probe is very important!
     
    protopop and tehusterr like this.
  7. INedelcu

    INedelcu

    Unity Technologies

    Joined:
    Jul 14, 2015
    Posts:
    173
    The Reflection Probe is rendered using the rendering path set in the graphics tier settings (Project Settings -> Graphics).
    You can specify which tier is active using Graphics.activeTier
    By default the rendering path there is Forward.
    For a specific camera you can customize the rendering path - Forward or Deferred or use the one set in the current tier settings(Use Graphics Settings).

    https://docs.unity3d.com/ScriptReference/Rendering.GraphicsTier.html
     
    Salvador-Romero likes this.
  8. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    You're right, it get updated properly now. (Downloaded 2017 to test)

    However, we still have no control over the render process. I admit our camera setup is a bit unusual, since we have a "live" sky that is rendered by a different camera, which the normal reflection probe can't pick.
     
    Last edited: Feb 22, 2018
  9. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    We'd be very very interested in this (both baking and optimized runtime updating) -- are you still thinking about releasing it on the Asset Store? Would surely be a bargain at a lot more than $1-2....
     
  10. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    I might just end up dumping it on GitHub. I fount the Asset Store is usually not worth the work of packaging, documenting, supporting and updating an asset. I just haven't found the few bucks here and there be worth the dozen of hours invested.
     
  11. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Definitely understand that! And that would be very generous...think you might do that soon? :)
     
  12. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    Here you go: https://github.com/LightStriker/ReflectorProbe
    There's a small demo scene where the reflector uses a camera with a different clear so the sky in the reflection is blue.
     
    Stardog, mgsvevo, tehusterr and 4 others like this.
  13. gecko

    gecko

    Joined:
    Aug 10, 2006
    Posts:
    2,241
    Awesome! Thank you so much!!
     
  14. IkigaiMonkey

    IkigaiMonkey

    Joined:
    Sep 22, 2012
    Posts:
    18
    This is great, thanks!
     
  15. no00ob

    no00ob

    Joined:
    Dec 13, 2017
    Posts:
    65
    This is exactly what I needed!

    Edit: I don't know why but this seems to cause errors with the new post processing layer, also flare layer on the camera causes a crash...
     
    Last edited: Dec 29, 2018
  16. namanam

    namanam

    Joined:
    Jul 27, 2013
    Posts:
    8
    need hdr! Thanks
     
  17. graphicDNA

    graphicDNA

    Joined:
    Jun 26, 2017
    Posts:
    47
    Thanks for all that great stuff. It's indeed very useful. With regards to manually updating the Reflection Probes:

    If you are using HDRP (and maybe other Scriptable Rendering Pipelines), Reflection Probes are overridden by newer classes (search for UnityEngine.Experimental.Rendering.HDPipeline.HDProbe.cs).

    They behave differently, and RenderProbe method won't work with those. Instead, you have to use the following helper method:

    HDAdditionalReflectionDataExtensions.RequestRenderNextUpdate(reflectionProbe);

    **Please note**: The HDAdditionalReflectionDataExtensions class is in the UnityEngine.Experimental.Rendering.HDPipeline namespace. You will also need to configure your probe as RealTime, and realtime mode should be set to OnDemand.

    Cheers
     
  18. flogelz

    flogelz

    Joined:
    Aug 10, 2018
    Posts:
    142
    @LightStriker I just downloaded your package and everything seems fine, i just can't seem to find where i can switch the mode of the reflection probe? There's a refreshmode.cs in the folder, but no button in the inspector?
     
  19. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    I don't think I've exposed the refresh mode in the inspector, since for our use we had it driven by a manager.
     
    flogelz likes this.
  20. flogelz

    flogelz

    Joined:
    Aug 10, 2018
    Posts:
    142
    Ok, so could you help me on how to call the refresh function? I'm not that familiar with namespaces, but i can't find the void RefreshReflection function when using Reflector.ReflectorProbe- Am I missing something to call the function?
     
  21. amynox

    amynox

    Joined:
    Oct 23, 2016
    Posts:
    178
    Hi All,

    Thanks for sharing @LightStriker . Sadly i didnt managed to make Updating Reflection prob on demande ( ReflectorProb.RefreshReflection(Reflector.RefreshMode.Overtime) ) work with URP...
    Any help will be much appreciated.
    Thanks a lot
     
  22. LightStriker

    LightStriker

    Joined:
    Aug 3, 2013
    Posts:
    2,717
    That's kinda vague... What have you tried?
     
  23. amynox

    amynox

    Joined:
    Oct 23, 2016
    Posts:
    178
    1/Created Go with reflector on it (that create reflection prob..)
    2/ coded simple script that call ReflectorProb.RefreshReflection(Reflector.RefreshMode.Overtime) every X second.
    3/ the code get executed, a cube map get generated on Reflection prob but its BLACK !!
    4/ Clicking the "BAKE" btn in Editor mode get generate the cube map correctly. so i geuss it has to do with some reflection prob API that dont work anymore on runtime in URP ....
    Thanks for your help
     
  24. TubertMorti

    TubertMorti

    Joined:
    Apr 3, 2020
    Posts:
    4
    The problem I have with reflection is that I have several different skyboxes. And naturally I would want the reflection probe to reflect the active skybox. So I set the lighting to auto generate. This fixes it, however in the build it continuously reflects the skybox that was active during the build. In my menu I use the sky as a background, and it chooses and sets one at random out of 12 material skyboxes. There's a leafy particle system that plays behind the menu's transparent bits like a house window. It emits shiny reflective leaves that will not reflect my sky. Unity's particle system and the material has no functionality to edit reflection. And the particles seem to work on their own in the editor, regardless of my reflection probe. I came here looking to force the reflection's update with code with every skybox selection.