Search Unity

Realtime mobile reflections

Discussion in 'General Graphics' started by YuriiChumak, Mar 19, 2020.

  1. YuriiChumak

    YuriiChumak

    Joined:
    May 28, 2017
    Posts:
    5
    Hello, developers. How to create real-time mobile reflections, on the example of the game "Need for Speed - no limits"
    IMG_20200319_143746.jpg In this game at the minimum settings, we can see 4 cars on the track, where three of them that are nearby have realtime reflections
    How is this implemented in this example?
    because unity real-time reflection probe not optimized
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    I'm willing to bet those are not realtime. Not 100% what they're doing exactly, but it's probably a bunch of prebaked probes that look vaguely like the environment you're in, with some box projection so that the reflection moves as you move along the track.
     
  3. YuriiChumak

    YuriiChumak

    Joined:
    May 28, 2017
    Posts:
    5
    But what about the cars passing by, which I see on the body of my car?
     
  4. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    Do you? From that pic you posted, I don't see other cars in the reflections.

    Same thing in this video :
     
  5. YuriiChumak

    YuriiChumak

    Joined:
    May 28, 2017
    Posts:
    5
    Real racing 3 ea products
     

    Attached Files:

  6. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    That is a different game though?

    They could be using a realtime probe, but only for your car, and then bullshit probes for the rest of the cars.

    Although looking at real videos of Real Racing 3, I don't see other cars in the reflections:

     
  7. YuriiChumak

    YuriiChumak

    Joined:
    May 28, 2017
    Posts:
    5
    the reflections are not correct enough, but there are, they do not look like a sphere, but a reflected sphere on the floor, what do you say?
     

    Attached Files:

  8. YuriiChumak

    YuriiChumak

    Joined:
    May 28, 2017
    Posts:
    5
    One man create special shader on unity

    How it works ?
    I want to understand the principle of how it works, this is definitely not a reflection probe, maybe some kind of hemisphere? How does it reflect?
     
  9. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    Why?
     
  10. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    1 place box projected cubemap around the tracks

    2 render only close dynamics in a local to the car cubemaps, skybox write to alpha, fog attenuate to alpha, low rendering distance (possibly render only low poly proxy, or imposter, rather than full dynamic objects)

    3 sample the current box projected

    4. sample the dynamic cubemap and merge with the sampled box projected cubemap using the alpha as mask
     
    DMorock likes this.
  11. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Real Racing 3 does real time reflection probes for the vehicles. But they also did a ton of optimization work to make that happen.

    What's in the reflection is a super simplified version of the world missing a lot of the details, often completely lacking anything beyond a few hundred feet, and only a few of the closest cars using simplified models & shaders. Also only the hero car reflects other cars, and only the other cars directly next to you reflect the track at all. The rest of the cars have a kind of generic, slightly blurry reflection, if any reflection at all.

    If you drive from the driver seat camera, pay attention to what's visible in the mirrors and how bad other cars actually look. They're kind of chunky, there's no reflections on them just kind of glowy soft diffuse colors. You can also see that the track disappears in chunks. That's what the reflection probe is also rendering.

    Your example images above are a great example of all of this. Note the white BMW M3 is reflecting the green Ford Focus, but the Focus isn't reflecting the M3. Also notice in the reflection on the M3 the Focus is missing tail lights, exaust pipes, the windows are opaque, and it looks kind of soft. Also notice the blue Focus in the distance (which isn't in the reflection) looks almost exactly the same (though the windows are still transparent). You'll find a ton of that.

    Lastly, one of the most expensive parts of rendering a real time reflection probe in Unity is the real time convolution ... that is the blurring of the cube map so it works with PBR roughness. Racing games don't have to worry about that because only the car body usually uses the real reflections, and they're always perfectly sharp.
     
  12. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,348
    Also in the description of that video he explicitly says he's using a "realtime cubemap" ... that's what a reflection probe is, a cubemap. He even has a small description of how he's setting it up. Short version, what he's doing works on a completely flat road and nothing else, but looks fine for the car as long as you don't get too close to things.
     
  13. neoshaman

    neoshaman

    Joined:
    Feb 11, 2011
    Posts:
    6,493
    Last edited: Mar 20, 2020
  14. Mehrdad995

    Mehrdad995

    Joined:
    Jul 17, 2013
    Posts:
    46
    I also always wanted to have a realtime reflection on mobile and was amazed by how some of games have them without a lot of frame drops,
    so I started investigating about it in games and analyzed CarX drift for this purpose.


    If you zoom onto reflective parts of your vehicle you can clearly see that there are only two sides for the reflection and they fade into each other at the center.
    so I did the same thing in unity, instead of using a 6faced cubemap (reflection probe is the same) I render two RenderTextures with a camera that has a wide fov (to cover most of the scene, however the more the angle the more you'll lose detail on the center of image),
    then wrap those on the object as reflections inside the sahder.
    I also noticed that using replaced shaders for reflection camera to simplify shaders of objects being rendered by it, actually strangely decrease the performance.
    directly comparing the default cubemap rendering and this approach, it gives you a ~200% boost in performance (apparently, rendering 5 apples in a single camera is faster than rendering 1 apple in 5 cameras).
    you can also use low-poly proxy meshes with super simple shaders and only render them to reflection maps. That's what rockstar does in GTA V.
     
    Last edited: Jun 13, 2020
  15. Mehrdad995

    Mehrdad995

    Joined:
    Jul 17, 2013
    Posts:
    46
    As far as I know, generating mipmaps can be costly if happens at real-time specially a couple of times per frame (for reflection texture).
     
  16. Neto_Kokku

    Neto_Kokku

    Joined:
    Feb 15, 2018
    Posts:
    1,751
    They probably do it like it was done back in the PS2 era: render a very simplified version of the scene with a dual paraboloid projection. Much cheaper than a cubemap, since you get a 180 degrees FOV in a single pass. During some close ups on the car body you can see the telltale distortions caused by the non-linear projection used on the low polygon reflected scene.

    The track reflection looks like a planar reflection too, but using a "special" low-polygon version of the scene with things like headlights and streetlights replaced by vertically elongated sprites, to fake elongated reflections.

    Notice how there aren't really any blurry reflections. They don't bother generating mipmaps.

    In short: you'll not achieve this with out-of-the-box Unity features. It requires custom shaders and clever use of render targets.
     
    blueivy and mgsvevo like this.