Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Questions about reflection probe in Unity 5

Discussion in 'Unity 5 Pre-order Beta' started by Charkes, Nov 28, 2014.

  1. Charkes

    Charkes

    Joined:
    Apr 17, 2013
    Posts:
    228
    Hi,

    I wondered how reflection probes are compute in Unity 5 ? Is it compute shader ? Is it use importance sampling ?

    I assume it is based on a blinn-phong model to match the direct specular term ( or I am wrong ), is it going to be possible to change it to use for example a GGX model or other ?

    Thanks.
     
  2. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,900
    Under the hood it simply use the same functionality as Camera.RenderToCubemap, then it applies convolution for mipmaps.
     
  3. Charkes

    Charkes

    Joined:
    Apr 17, 2013
    Posts:
    228
    Does that mean that now when using Camera.RenderToCubemap in a custom script a convolution is always applied to mipmaps ?
     
  4. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    I doubt it.

    I would however like the option to apply the convolution to regular old render textures.
     
    AcidArrow likes this.
  5. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,900
    No, RenderToCubemap only provides information for first mipmap, the convolution is applied by different code, the only wait to apply from user code, is to save the image produces by RenderToCubemap to file, and import via TexturImporter.

    Unless you're talking about applying convolution at runtime.
     
  6. Charkes

    Charkes

    Joined:
    Apr 17, 2013
    Posts:
    228
    Ok well I what I wonder is would it be possible to change this convolution by an other one and keep Unity's 5 reflection probe.

    I already have a way to convolve my probe and for that I'm using the GPU with flitered importance sampling (to use GGX or any) but for this I'm using my own scripts and I would like to take advantage of the new reflection probe system of unity.
     
  7. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,900
    Hmph, I think it should be possible, if you're trying to make a custom processing for cubemap, try accessing Cubemap class directly (http://docs.unity3d.com/ScriptReference/Cubemap.html), to get the cubemap from reflection probe, simply change ReflectionProbe.mode to Custom, and then access ReflectionProbe.customBakedTexture (cast it to Cubemap).
     
  8. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    225
    That explains very poor performance.
     
    shkar-noori likes this.
  9. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    Does it, though? I thought cubemaps were only baked once.
     
  10. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,739
    With the new realtime option, you can have a script to update them. You could even attach scripts on all of the to update all the time :)

    A more sane solution though, would be to update only the relevant cubemaps when you are doing really major lighting changes.
     
  11. Roni92

    Roni92

    Joined:
    Nov 29, 2013
    Posts:
    225
    Yup, you can use them as real-time from newest beta, but performance is so poor that.... its almost useless. :)
     
  12. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    I disagree. I've been using a real time probe attached to my character and the performance is excellent. Admittedly it's only a 128 probe, which wouldn't look good on a wall, but it looks fantastic on the player character.
     
  13. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,739
    Performance when you're updating a couple of probes at a time is just fine. Especially with the timesliced bool on.
     
  14. Charkes

    Charkes

    Joined:
    Apr 17, 2013
    Posts:
    228
    Ok I'll try that, thanks for the tip!
     
  15. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    Last edited: Dec 3, 2014
  16. Charkes

    Charkes

    Joined:
    Apr 17, 2013
    Posts:
    228
    Hey,

    Yeah I tried it a bit to see if I could bring Antonov Suit to it but get stuck with reflection, I dont want to go back to Blinn-Phong kind model.

    Thanks I'll probably make a request too :).
     
  17. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    I tried that, but it doesn't seem to be updating when the character moves. Am I missing something?
     
  18. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Yes, you need to tell it to update in a script. The script I'm using at the moment looks like this:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class ReflectionProbeUpdater : MonoBehaviour
    5. {
    6.     private ReflectionProbe probe = null;
    7.  
    8.     // Use this for initialization
    9.     void Start ()
    10.     {
    11.         probe = GetComponent<ReflectionProbe>();
    12.     }
    13.    
    14.     // Update is called once per frame
    15.     void Update ()
    16.     {
    17.         if( probe == null )
    18.             return;
    19.    
    20.         if( probe.IsFinishedRendering(0) )
    21.             probe.RenderProbe( false );
    22.     }
    23. }
    Later on I might make it so that it only updates it if it's position changes... but then I guess i want it to change if other things around the character as well. I dunno, performance seems fine anyway.

    I've also set the Anchor override of my character's mesh to be the probe object, and the "reflection probes" variable to simple. Also I've removed the character's layer from the render mask of the probe.

    For me it's working fantastically.
     
    Charkes likes this.
  19. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    Oh, awesome, thanks for the prompt reply. I'll give that a shot.
     
  20. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    Hey Zomby138, have you try to build your scene for the Reflection Probe update? Is that working for you?

    I tried earlier with my own simple script ( almost same as your script) to update the Reflection Probe, it works very well only in the editor play mode. After i build the webplayer or standalone, the Reflection Probe is black.

    I'm on my Macbook, not sure if it is the platform issue or not. (or maybe a bug?)
    (Attached a screenshot of webplayer)
     

    Attached Files:

    Last edited: Dec 3, 2014
  21. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    @Luckymouse Yeah looks like a bug. Doesn't work for me in the windows build either.
     
    Luckymouse likes this.
  22. DanSuperGP

    DanSuperGP

    Joined:
    Apr 7, 2013
    Posts:
    408
    I'm seeing the convolution step taking 45-50 ms at 128 resolution with 0 reflection passes and size 10.

    Setting time sliced to true, it's really chunky, about 1-2 fps update on the reflection.
     
  23. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    According to Tomas1856 explained from above post how unity reflection probe does as following step: (Please correct me if I'm wrong)
    1) Use Camera.RenderToCubemap for first mip level
    2) Convert RenderTexture to texture asset. (assuming using Get.Pixels to save to a file )
    3) Use TextureImporterCubemapConvolution.Specular to convolve the texture asset to Specular Cubemap
    4) Apply this Specular Cubemap to reflection probe.

    This workflow is ok for baked/precomputed cubemap in the Editor, definitely not a good idea for realtime update per-frame based.

    I assume the new ReflectionProbe.RenderProbe API will do the better job for reflection probe update, maybe implemented a GPU base convolution? (Directly convolve the RenderTexture without to save it to file first?) Or it is just doing the same steps above. If it is so this API is just not that meaningful.
     
    Last edited: Dec 3, 2014
  24. Charkes

    Charkes

    Joined:
    Apr 17, 2013
    Posts:
    228
    This is some real time test done with Unity 4 :

    https://dl.dropboxusercontent.com/u/1812933/AntonovSuit/ProbeSky/ProbeSky.html

    I render them with RenderToCubemap() in ARGBHalf format with mipmap (both diffuse and specular)
    I send them to my filtered importance sample shader to do real time convolution.

    It's slow as hell but gives good idea of what real time can do.

    But I don't think full real time can be done for an entire scene with multiple cubemap.

    I used uSky for sky : https://www.assetstore.unity3d.com/en/#!/content/24830

    EDIT : Makes me think that some engine (Fox Engine and Far Cry 3) pre bake their cubemaps for each time of the day to use them later at correct time.

    Convolution is I think done with GPU during the bake, at least for Fox Engine. But still nothing is in real time, it's just too much.
     
    Last edited: Dec 3, 2014
    Luckymouse likes this.
  25. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    Amazing, especially in the right golden material looks awesome. Now that is what i'm talking about! Great job!
     
    Charkes likes this.
  26. Charkes

    Charkes

    Joined:
    Apr 17, 2013
    Posts:
    228
    I made a quick update with two little sphere also.

    Yeah it looks good but it is slow (64 samples for both diffuse and specular less reduce qualtiy a lot for diffuse).

    I didn't tested with compute shader yet though.
     
  27. Luckymouse

    Luckymouse

    Joined:
    Jan 31, 2010
    Posts:
    484
    @Charkes
    I found out that Unity 5 is using GGX ( Googled ), It is a derivative of Disney GGX BRDF. So it will fit your Antonov Suit shader, right?
    If yes, It is will be very easy for you to integrate Antonov Suit for Unity 5.
    Unity5_GGX.jpg
     
    Last edited: Dec 4, 2014
  28. Charkes

    Charkes

    Joined:
    Apr 17, 2013
    Posts:
    228
    Specular shape looks like Blinn-Phong to me and I remember in : Physically Based Shading in Unity by Aras Pranckevičius reading that it was inspired by Disney, but still use Blinn-Phong.
     
  29. larsbertram1

    larsbertram1

    Joined:
    Oct 7, 2008
    Posts:
    6,900
    hi charkes,
    i just wanted to correct you but had a look at the latest (well: beta 16...) version of the standard brdf first: it seems as if you were right. unity has switched back to blinnphong... now that anybody moves to cook torrance.
     
    Last edited: Dec 16, 2014
    Charkes likes this.
  30. PhobicGunner

    PhobicGunner

    Joined:
    Jun 28, 2011
    Posts:
    1,813
    I honestly think Unity should switch to GGX specular - it has a very nice falloff, much better than either Blinn-Phong or Cook-Torrance.
     
    Charkes likes this.
  31. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,739
    I sort of agree, but isn't GGX more expensive?
     
  32. Charkes

    Charkes

    Joined:
    Apr 17, 2013
    Posts:
    228
    Of course a bit but not that much really.