Search Unity

  1. Looking for a job or to hire someone for a project? Check out the re-opened job forums.
    Dismiss Notice
  2. Unity 2020 LTS & Unity 2021.1 have been released.
    Dismiss Notice
  3. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice

Reflections - SSR?

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

  1. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    992
    What are the current SSR options in Unity, are there any that are't on the asset store? I understand Candela has fallen from grace. Why was it so much more expensive than the other SSR offering. Suggestions? Thanks.
     
    fra3point likes this.
  2. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,899
    SSR is coming in a future update, apparently.
     
  3. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    992
    Yea I've heard and i'm looking forward to it. The problem is I have a current project and deadline. Box projection and cubemaps have worked ok, but I always end up with a column in the middle of the room or an 'L' shaped space or somthing. This project is no exception.
     
  4. erana79

    erana79

    Joined:
    Jun 26, 2013
    Posts:
    61
    Why did Candela fall from grace?
     
  5. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    992
    I dont have any personal experience. It's been mentioned in a number of threads i've read that they are no longer responding to support requests. I dont know why I phrased it like that.
     
  6. erana79

    erana79

    Joined:
    Jun 26, 2013
    Posts:
    61
    Ah, i see.
    Thanks for the info. I don't own the plugin myself but heard about it. Probably gonna pass on it until Unity comes up with their version.
     
  7. Boris1998

    Boris1998

    Joined:
    Jul 5, 2013
    Posts:
    82
    What about Mirror Reflection or Surface Reflection scripts from the wiki?
    I've heard they work fine, but it looks like they are broken in Unity 5. Any suggestions for making mirror reflection on floors (in more complex enviroment than box shaped room)?
     
  8. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    26,899
    Duplicate upside down geometry and transparent floor hack? :)
     
    DennG likes this.
  9. Boris1998

    Boris1998

    Joined:
    Jul 5, 2013
    Posts:
    82
    Bad idea for many reasons...Is there any not so complex trick for having flipped geometry image as some sort of camera-dependent tiled texture?
    Sorry for so much questions, but I am new to this stuff. I've recently started learning graphic aspect of game develping, altrough I am not very experienced programmer, especially when it comes down to shaders.
     
  10. MattMurphy

    MattMurphy

    Joined:
    Dec 24, 2013
    Posts:
    111
    If you have Candela and are good with coding shaders and understand the rendering changes since 4.6 I think it's fixable. It's not that far away from working properly. It'd be easier than creating your own SSRR anyway.

    Other than that the only solution, if your reflective object moves, is to use legacy shaders with real time cubemaps from render texture which is now available to us free version plebs. It's not ideal and won't look as good but it's a possibility.

    I'm sure most people would rather use a built in solution, myself included, but we don't know when it'll be available. I'd be surprised if we don't see new 5.0 compatible SSRR in the asset store very soon. I think there's a great opportunity there for someone to make some cash.
     
  11. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    657
    There's no reason to use legacy shaders with realtime cubemaps. You can set up a realtime reflection probe with all the new PBR shizzle and attach it to your character.
     
  12. MattMurphy

    MattMurphy

    Joined:
    Dec 24, 2013
    Posts:
    111
    Of course, I forgot to mention those. But on for example vehicles, results can be good but not on the level of SSRR. You have to adjust clipping planes to stop the paint work reflecting the interior of the car, but at the same time this can result in very close objects not being reflected.

    But yes, much better than using legacy.
     
  13. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    657
    Personally I would put the car itself on a layer that is left out of the rendering mask of the probe.
     
  14. Boris1998

    Boris1998

    Joined:
    Jul 5, 2013
    Posts:
    82
    Reflection probes are pretty useful for almost everything, but cannot compare to SSRR.
    For example, floor is just a horizontal surface that reflects everything along Y axis and Mirror Reflection or Surface Reflection shaders from Unity wikishould be fine for floor reflection, like lacquered wood. I've also seen some pretty good realtime floor reflections that work even on mobile devices in Angry Bots demo. What I don't understand is why those shaders stopped working after Unity 5 update.

    As I alredy mentioned, I don't have knowledge about shaders nor how to make those shaders work in Unity 5 and I don't plan on learning shader coding soon.

    I am just curious, has anyone menaged to convert such shaders to work with Unity 5 or something that will work stuff?
    Aaaaand...reflection probes that generate cubemaps cannot reflect objects in the middle of the room or L shaped rooms...
     
  15. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    6,571
  16. adventurefan

    adventurefan

    Joined:
    Jan 17, 2014
    Posts:
    201
  17. Botanika

    Botanika

    Joined:
    Nov 2, 2013
    Posts:
    59
    Doesn't seem to work for me, but I've only tried it on a DX9 Integrated GPU laptop.
     
  18. adventurefan

    adventurefan

    Joined:
    Jan 17, 2014
    Posts:
    201
    Me neither. DX11/Windows 7. Purple screen of shader issue.

    But looking at his twitter seems like he's just ported it to Windows today so something must be missing there still.
     
    Botanika likes this.
  19. jRocket

    jRocket

    Joined:
    Jul 12, 2012
    Posts:
    566
    That brings back memories. I remember doing that in Worldcraft for Half-Life 1 maps back in the day. Worked like a charm.
     
  20. element_wsc

    element_wsc

    Joined:
    Jul 27, 2012
    Posts:
    522
    @Botanika @adventurefan
    open SSR.shader and change line 290 from
    specRoughPixel = half4( 1.0 );
    to
    specRoughPixel = half4( 1.0, 1.0, 1.0, 1.0 );

    this fixed the purple screen for me
     
    Botanika and adventurefan like this.
  21. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    992
    It works for me on Windows after updating line 290 per @element_wsc Pretty short distance, but I haven't played with any of the settings.
     
  22. kode80

    kode80

    Joined:
    Aug 1, 2013
    Posts:
    151
    I've pushed all fixes to the kode80SSR repo. Please let let me know of any issues either via the github tracker (https://github.com/kode80/kode80SSR/issues) or email (ben AT kode80).

    Reflection distance is completely variable; "Iterations" and "Pixel Stride" are the main two properties for altering that. Check the README for details on each of the SSR component's properties. I'm going to put together a video later in the day showing various test scenes and how the properties affect performance/quality.
     
    Lex4art, Botanika and adventurefan like this.
  23. frankfrankovic

    frankfrankovic

    Joined:
    Jan 26, 2015
    Posts:
    9
    is there anyone who get this script working for a simple plane/cube scene?
     
  24. kode80

    kode80

    Joined:
    Aug 1, 2013
    Posts:
    151
    Here's a simple scene with SSR property values. The ground's material has a high metal value.
    ssr_simplescene_example.jpg
     
    DennG and shkar-noori like this.
  25. Pix10

    Pix10

    Joined:
    Jul 21, 2012
    Posts:
    845
    I've been doing it this week -- Some things will never go out of fashion. Keep yer fancy pants shaders :)
     
  26. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    Looks perfect here. Nothing I could do with it seemed to affect my framerate in the slightest. I set everything to max and it still chugged along smoothly.

    But I can't see myself using such an effect if it's not properly affected by materials, especially roughness. Also the fact that it disappears along the edges of the screen completely ruin the effect for me. These may simply be limitations with SSR, but I'm hoping Aras and Unity, or you or anyone else for that matter, are able to come up with some solutions for them. :)
     
    Last edited: Mar 12, 2015
  27. kode80

    kode80

    Joined:
    Aug 1, 2013
    Posts:
    151
    That's great to hear the performance is holding up. My dev machine's a MBP, so fairly moderate in the gfx department.

    I'm going to be adding physically correct handling of reflections once I get the chance, for now you can at least enable specular tinting by commenting out the line near the end of the shader (it's got an explanation above it). Aside from how roughness affects color, the amount of reflection-blur is currently limited by the blur pass. I was quite conservative with the number of samples taken, you could certainly bump that up (and even run a 2nd pass) to widen the potential radius, which would put it more in line with the maximum blur you see in very rough surfaces from the standard shader. Another possibility is sampling higher mip levels.

    Unfortunately the fading is the price you pay for screen space effects. One potential fix (at least for the screen edges) would be to render the scene to a slightly higher resolution so reflections have that data available and then crop that to the screen's resolution. Obviously you'd pay for the extra rendering but maybe that'd be worth it on a case by case basis.
     
    TwiiK and Lex4art like this.
  28. ArchVizPRO

    ArchVizPRO

    Joined:
    Apr 27, 2014
    Posts:
    395
    Going to try it now :D
     
  29. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,545
    Congrats @kode80 the SSR looks and works great (and performs amazingly I might add). The only major-ish drawback is the low quality blur.
     
    shkar-noori likes this.
  30. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    This is the kind of thing I would expect to see if Unity was open source. Most people would put this on the asset store.

    Wasn't Unity looking for a graphics programmer recently? Perhaps you should do some freelance work and help Aras finish the built in SSR? :p

    Aras was talking about having a fallback to reflection probes where SSR did not produce valid results. I'm not sure if along the edges of the screen is included in that. Will be interesting to see.

    This is from his GDC notes:
    I've never really thought about how SSR looks or works because I rarely play games that has it. I mostly play simple indie games. :p Guess I could take a look in Unreal Engine 4.
     
    shkar-noori likes this.
  31. Boris1998

    Boris1998

    Joined:
    Jul 5, 2013
    Posts:
    82
    Win 7 Nvidia GeForce 8800 GT, works fine with default settings :D
     
  32. kode80

    kode80

    Joined:
    Aug 1, 2013
    Posts:
    151
    Thanks! Yup the blur is definitely the weakest pass. As mentioned earlier, there's definitely room there to bump up the quality by increasing samples/passes - but overall I'm still looking at how to improve it.

    As much as I love the asset store and am certainly considering creating other components/effects for it, I do feel it encourages people to try and make a buck vs. sharing. I've learnt so much over the years from people being open with their code and ideas and want to reciprocate whenever possible. If it was financially viable, I'd make all my work open source.

    That snippet from Aras's GDC notes is interesting, the article he mentions at the end (by Morgan & Mike) is the same one that was super helpful in getting the DDA part of my ray caster working and I mention in the article. My implementation adds a couple of optimizations and deviates quite a bit in the intersection tests and compositing stage.

    SSR pretty much requires reflection probes, they really help fill in the gaps where it fails. As it is right now it automatically falls back to them since I'm sampling the final frame buffer anyway (so if there is no ray intersection it just returns the current fragment).
     
    AcidArrow and Kinetic-Kai like this.
  33. TwiiK

    TwiiK

    Joined:
    Oct 23, 2007
    Posts:
    1,699
    Just downloaded Unreal Engine 4 and tested out the Paris demo everyone was so crazy about and the included reflections demo. From what I can tell their reflections behave the exact same way as yours. So if you're able to fix the blur it looks like the exact same effect from what I can tell.

    But I thought it was distracting in Unreal Engine 4 as well. To the point where I would consider turning it off if I had the choice. It's very obvious how the reflections disappear along the edges of the screen for me. Guess I need a bigger monitor so I can't see the edges. :p
     
  34. kode80

    kode80

    Joined:
    Aug 1, 2013
    Posts:
    151
    Yeah it's hard to miss it when you have a completely reflective surface that extends beyond the screen. It can definitely be masked somewhat with reflection probes and not having completely flat, fully reflective surfaces. I agree it tends to stand out in those areas (the kite open world demo they showed off is another example, when the boy gets to the lake you see the reflections fading clearly at the screen edges) - that said some people just like the pretties lol! It's just like SSAO really - a stop gap until we can get a better solution - and when over used it tends stand out, subtlety always wins with these things.
     
  35. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    7,545
    I think the main purpose of SSR is to "ground" the objects properly. A hint of a reflection of an object in the middle of the room is enough to make the scene that much more believable. Otherwise, everything feels kinda floaty.

    I played around with Unreal's built-in SSR, and the blur they do seemed very noisy to me. Although I'm guessing they were going the more "proper" route, of doing multiple samples. I do feel like a "fake" blur is the way to go.
     
  36. kode80

    kode80

    Joined:
    Aug 1, 2013
    Posts:
    151
    I've started an optimization branch on the repo today, have refactored the raycast code and misc. other bits. In some cases I'm seeing a performance increase of around 40%. If anyone's feeling adventurous check it out and let me know how it runs on your machine.

    I agree and this is definitely where the subtlety comes into it, you can use very conservative settings and still get that 'grounded' feeling.

    I actually tried something similar for rough samples initially, although I simply added a random vector to the ray direction based on roughness. I got similar results, i.e. very noisy. Now I'm getting good results in the optimization stage, I may give it another try, this time using multiple rays per pixel - at least as an option.
     
    xLeng and Lex4art like this.
  37. xLeng

    xLeng

    Joined:
    Feb 12, 2014
    Posts:
    19
    Kode, how about make it compatible on mobile (ios). is that a lot of work to make it happen?
     
    zyzyx likes this.
  38. elbows

    elbows

    Joined:
    Nov 28, 2009
    Posts:
    2,480
    Thanks so much for sharing your SSR work. I only tried it briefly but I was impressed, and look forward to using it more today.
     
  39. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    992
    Is that available through the same download or indicated differently. I'm ashamed to say I have limited experience with github. I'm never sure i'm looking at the most current information.
     
  40. kode80

    kode80

    Joined:
    Aug 1, 2013
    Posts:
    151
    I looked into it briefly over the weekend before I started the optimization work, it should definitely be possible using lower precision depth and quality settings. I may take a crack at a mobile-specific version this weekend.

    It's currently on a different branch (you can switch branches directly in github with the gray drop down that says "branch: master"). I'm going to be merging the optimization stuff into the main branch today anyway as all reports show that it fixes issues some people were having while also drastically increasing performance. So come this evening, the main download link should be up to date.
     
    zyzyx and xLeng like this.
  41. MS80

    MS80

    Joined:
    Mar 7, 2014
    Posts:
    341
    @kode80: Thank you very much for sharing your work with us! Your ssr works great and is damn fast! G
     
  42. chingwa

    chingwa

    Joined:
    Dec 4, 2009
    Posts:
    3,639
    I've tested this out as well and after fixing a few lines of code (I was using your original version) everything seems to be working great. Digging through the code is illuminating as well... I didn't realize how easy it was to access the new Deferred buffers :) It would be great to be able to access "roughness" information though, in order to convolve/blur the reflection properly for PBR. Do you think this is possible? I haven't found any info on this elsewhere...

    The fade at the edges is pretty standard for SSR, It's pretty obvious in some Unreal Engine scenes, and I also noticed it in the latest FinalFantasy XV videos. Doesn't bother me personally, though I can see how it may be distracting for some.

    @kode80 This is a great gift you've given to the community here... THANK YOU!
     
  43. kode80

    kode80

    Joined:
    Aug 1, 2013
    Posts:
    151
    You're welcome, glad you like it. :D

    Yeah, I had the hardest time tracking down the correct texture names for GBuffer access - it *is* actually discussed in the Unity docs but like a lot of things with the Unity documentation you have to do several Google incantations to find the correct term to get to the correct version of the correct page... I actually found the docs after I'd already uncovered the texture names by digging through the Unity shader source code - something I'd highly recommend to anyone working on shaders in Unity.

    You can get the per-pixel roughness via the alpha channel of _CameraGBufferTexture1. If you look in the BilateralBlur.shader I am using this to alter the blur radius - it may just be subtle due to the blur being a bit crap ;) I have a new version of the blur shader on my local copy which is much nicer and I'll eventually push that to the repo. I'm currently working on making reflections more physically correct, taking fresnel/specular into account etc. and that will be the next push.

    If you haven't already updated to the latest revision, I'd definitely suggest you do that - there's a huge performance boost.
     
    ArthurT and cakeslice like this.
  44. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    6,571
  45. cakeslice

    cakeslice

    Joined:
    Oct 18, 2014
    Posts:
    192
    Hi, kode80, amazing work! Thank you so much for giving this to the community

    You should make a thread for your SSR solution so we can praise you :D
     
    hopeful likes this.
  46. topofsteel

    topofsteel

    Joined:
    Dec 2, 2011
    Posts:
    992
    I thought someone asked this, but I didn't see it in the thread. Is there a way to apply a culling mask per layer? I have a large square room with columns. I want to be able to use a probe for the room and SSR for the columns. I guess I could stack cameras, but my goal is to optimize the scene. I'm getting about a 100 fps drop with SSR on the camera. I have not spent a lot of time tweaking it, but based on my initial results culling sounds like a good option. Thanks.
     
  47. MBaldowski

    MBaldowski

    Joined:
    Oct 1, 2014
    Posts:
    5
    Wow kode80 - amazing work! Really loving the reflections and SSR.

    I've tried the orthoraphic camera tough, and it didn't work as expected - gave me some false positioned reflections. Is there something I need to set to use SSR with an orthographic camera?
     
  48. kode80

    kode80

    Joined:
    Aug 1, 2013
    Posts:
    151
    Thanks! Great idea, new thread is here: http://forum.unity3d.com/threads/kode80ssr-free-screen-space-reflections-component.313404/

    There is no way currently to cull specific objects from SSR. Doing so would require a separate pass rendering your scene with only the specific objects and doing that would start to move away from the benefits of SSR (i.e. you're now having to render the scene twice). You can however use reflection probes with SSR just fine. By the sounds of what you're asking, you have it backwards. Rather than culling the room from the SSR, you should cull the columns from your probes. This way the reflections from your probes will have the base room and the then the reflections from the SSR will be layered on top of it.

    Thanks! Unfortunately kode80SSR won't work with orthographic cameras since AFAIK Unity orthographic cameras don't work with deferred rendering. You can check this out by enabling one of the debug defines at the bottom of SSRBlurCombiner.shader to view the specular/smoothness pass directly - they aren't updated as soon as you switch to orthographic. I couldn't find anything mentioning this specifically in the Unity documentation but have found several posts from people who've run into the same problem.
     
  49. MBaldowski

    MBaldowski

    Joined:
    Oct 1, 2014
    Posts:
    5
    Thank you for your response. So there is currently no working SSR for orthographic cameras? Will the Unity Team implement something in the future?
     
  50. Pix10

    Pix10

    Joined:
    Jul 21, 2012
    Posts:
    845
    Orthographic cameras have a different z-buffer, which is needed for deferred, so it's not technically compatible.

    You used to be able to get around that with custom projections (not sure if you still can in 5.0, you can always give it a try), but you'd still be open to issues with lighting. It would work, but never 'properly'.
     
unityunity