Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Using light probe to reflect objects placed on a plane?

Discussion in 'General Graphics' started by kznatt, Mar 6, 2015.

  1. kznatt

    kznatt

    Joined:
    Sep 19, 2014
    Posts:
    5
    I've tried to play with light probe do to what the topic stated and found no success. The reflections seemed off and are very far from the actual placement.

    Edit : I've tried tinkering with the box size and the transform location and failed.

    Here are the screenshots
    Screen Shot 2015-03-06 at 4.14.40 PM.png Screen Shot 2015-03-06 at 4.14.51 PM.png

    Thank You!
     

    Attached Files:

  2. bolaum

    bolaum

    Joined:
    Jul 24, 2014
    Posts:
    5
    Same here.
     
  3. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Struggling with the same.

    On a Realtime "Every frame" reflection probe this is written:
    Seems really counter-intuitive to say the least. Why do I have to initiate it from script when I just told it I want it to update always? Anyways I tried that in all the ways I could and it made no difference. I feel like the reflected GI is real time because I have a day/night cycle that works well, but the reflections themselves don't update.

    Recently I've been browsing Youtube for what people are able to make with Unity and look at this guy:


    He has managed it. And in the description it says he's only using standard Unity.
     
  4. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Ok, it is real time. I guess the scripting thing is just an advice or best practice to get more control, but I have no clue how to line up the reflection and not make it look like a camera that is rendering the scene from a specific spot. I've tried every setting and position. It just looks crummy no matter what. :p
     
    ArachnidAnimal likes this.
  5. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Eureuka. :p

    I wrote the above and then I went to make breakfast. As I thought about what I said about the probe acting like a camera I realized you have to update the probe position every frame. So you have to set your probe to the position of your camera.

    Edit: Something like this:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class RealtimeReflection : MonoBehaviour {
    5.  
    6.     ReflectionProbe probe;
    7.  
    8.     void Awake() {
    9.         probe = GetComponent<ReflectionProbe>();
    10.     }
    11.  
    12.     void Update () {
    13.         probe.transform.position = Camera.main.transform.position;
    14.         probe.RenderProbe();
    15.     }
    16. }
    It still looks crummy, but now it at least matches up the reflections sort of.

    But I want to update the probe origin, not the position, but I have no clue how.

    Edit2: No, it obviously has to be at the same height as the plane you want the reflections on. For me that is 0. So it should be like this:
    Code (csharp):
    1. probe.transform.position = new Vector3(Camera.main.transform.position.x, 0, Camera.main.transform.position.z);
    Now it actually looks rather nice.
     
    Last edited: Mar 8, 2015
    Sherlore likes this.
  6. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Here's a gif showing the effect:
    http://i.imgur.com/75pvWFJ.gif

    It can't get much better than that I venture. The downside is obviously that you can only make it work for 1 plane at a time I guess.
     
    Last edited: Mar 8, 2015
  7. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Hopefully last correction. Your probe has to be the same amount below the surface you want reflections on as the camera is above it. So if your camera is 1.8 meters above the floor because your character is 1.8 meters tall then the probe has to be 1.8 meters below the floor.

    To avoid rendering the floor from the probe (because it's under it) you will have to add the floor to a layer and then uncheck that layer in the reflection probe "Culling Mask" property. But now it really looks nice. :p
    http://i.imgur.com/bXqt2QU.gif

    Look at how perfectly the sunlight matches up in the reflection. And with a 1024 cubemap size it's a perfect mirror reflection which like you can see even reflects dynamic objects. In my test scene it doesn't really affect the framerate at all.

    Also, just wanted to say that the new default skybox and the rest of the Unity 5 lighting workflow is absolutely amazing. Being able to create an awesome day/night cycle by just rotating your directional light is mind blowing. :p

    Edit: Changed the gifs to links. It was annoying. :p
     
    Last edited: Mar 8, 2015
    NeatWolf and ArachnidAnimal like this.
  8. bolaum

    bolaum

    Joined:
    Jul 24, 2014
    Posts:
    5
    You, sir, are a life saver! I was able to make my floor reflective, but I still have an issue: when things move on the scene, its reflection seems to update after the movement, as if there was a delay of 1 frame before the reflection is updated. I also tried LateUpdate(), but it didn't work.

    Any tips?
     
    Last edited: Mar 8, 2015
  9. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Slow computer? I'm not sure.

    I only tested it as a proof of concept because of the video I found (the one I linked to). It looks like the reflections lag a bit in that video as well.

    There's no lag whatsoever for me, even with a 2048 probe.

    Here's my settings:


    There's a lot about the probes here:
    http://docs.unity3d.com/Manual/class-ReflectionProbe.html

    It has to render your scenes from 6 direction every frame. So it's a massive performance hog. If your computer can't keep up it may lag?
     
  10. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Here are my scene settings. No idea if they matter. Haven't really had time to get familiar with everything yet. :p
     
  11. bolaum

    bolaum

    Joined:
    Jul 24, 2014
    Posts:
    5
    Once again, you are my hero. Turns out I had 'Time Slicing' to 'All faces at once', setting it to 'No time slicing' fixed it!!

    Thank you so much. I tried to do this for hours last night, now I can get some good sleep.
     
  12. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    No problem.

    I'm making an arch viz scene to learn about physical shading and the new graphical features so I'm fiddling with a lot of these things myself at the moment.

    It would be cool trying to make it work for multiple surfaces. Like have multiple probes and then assign each probe to a single surface and have a script which aligns that probe in relation to that surface according to your movement in the scene. Vertical surfaces like mirrors would require some more work at least.

    I haven't really got a need for reflections in my scene yet, but it would be cool to have mirrors.

    This is a very smoke and mirrors approach though. :p A more plug & play solution like screen space reflections would be preferable I guess. Although I have no experience with that.
     
  13. bolaum

    bolaum

    Joined:
    Jul 24, 2014
    Posts:
    5
  14. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    ArachnidAnimal and bolaum like this.
  15. kznatt

    kznatt

    Joined:
    Sep 19, 2014
    Posts:
    5
    TwiiK, You are a life saver! I figured out until the part that I have to move the reflection box to the bottom of the plane. However I couldn't figure out the part about the position of the probe. Thank you so much!


    Also I played a bit more in trying to make a reflective metal objects that reflects everything around it. When combined with your technique, this is what I've achieved. It's made by using two separate probes, one for floor reflection using your technique, and another probe is attached as a child to the object you want it to be reflective (with mapping done properly, of course). Maybe you can achieve wall reflection using the same method?

    The important part is that you don't want to leave blend probes on, I use simple and attach specific probe anchor to the object I want to be reflective.

    P.S. may I refer to you in my blog if I make a tutorial?
     

    Attached Files:

  16. kznatt

    kznatt

    Joined:
    Sep 19, 2014
    Posts:
    5
    By using the same technique, I've received wall reflection by inverting the z-position of the probe instead of y.
    Unfortunately, my 6970HD took a huge performance hit after 3 real-time awake reflection probes.
     
  17. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    Of course, I would never think to ask your permission before doing the same. :p
     
  18. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
  19. DennG

    DennG

    Joined:
    Dec 5, 2013
    Posts:
    158
    The link doesn't work.
     
  20. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    I agree that the link doesn't work.

    Also, it's worth noting that using a cubemap to render a planar reflection is extremely inefficient. It's rendering 6 cameras for the cube when it only needs to render one. A single camera has always been enough for planar reflections.

    Ideally I would like them to add the new specular convolution to the old plane reflection stuff and have it integrate properly with the new PBR system. Unfortunately I'm not seeing many people requesting that so it might not happen.
     
  21. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,729
    I agree with the first thing you said, but I have no clue what you mean by the second. :p

    As you can probably tell from this thread the technical knowhow here is very low. If I were to take a single camera I would have no idea how I would get the image it produces onto a surface which I can control with a material with variable roughness etc. This was just a quick and easy way to make it work with what we have. :)
     
    kznatt likes this.
  22. shkar-noori

    shkar-noori

    Joined:
    Jun 10, 2013
    Posts:
    833
    DennG likes this.
  23. Teyhouse

    Teyhouse

    Joined:
    May 25, 2013
    Posts:
    12
    TwiiK you really made my day! One question: Is there any way to have like more than one reflection-plane at my scene?
     
  24. DennG

    DennG

    Joined:
    Dec 5, 2013
    Posts:
    158
    Sweet!

    Btw.. will this demo project be released soon?
     
  25. ArachnidAnimal

    ArachnidAnimal

    Joined:
    Mar 3, 2015
    Posts:
    1,727
    I was having difficultly with this very issue and I tried this Twiik approach and it seems to work very well.
    In fact, I compared this to the MirrorReflection.cs approach that is going around the forums, and I don't really see any more overhead used by this process as compared to the MirrorReflection4. (I stretched the reflection probe box out such that 5 sides were facing "nothing", i.e. nothing for the camera to render, so that may drastically improve the performance

    In fact, this approach is better for many reasons because you can control the intensity of the reflection probes and continue using the standard shader along with this, whereas I have had difficulties with the other approaches using multiple shaders.
    Apparently Unity is working on these issues to be released in v 5.1.
    Thanks.
    refProbe+RGB+NormalMap.png

    Using reflection probe, RGB file, and Normal map combined.
    Major improvement
     
    Last edited: Apr 29, 2015
    NeatWolf likes this.