Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How to handle light as in the real world?

Discussion in 'Shaders' started by colmwhitehead1212, Oct 13, 2019.

  1. colmwhitehead1212

    colmwhitehead1212

    Joined:
    Oct 13, 2019
    Posts:
    2
    Hi!

    I'm trying to simulate some physics phenomena and I need light to behave as it would in the real world. From my basic understanding i'd want to implement ray-tracing since my gpu is supposedly equipped to handle this, but to be honest I don't really know where to start with this, as my expertise is primarily in physics.

    Can you please suggest what I should look at implementing to have light behave as closely as possible to the real world?
     
  2. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    This is what every game engine ever created is trying to do. The problem is it's really, really hard (I.E.: Impossible) to do fast enough to be even close to real time. So game engines use a ton of different approximations that get close to the look of what happens in the real world. But it's still just an approximation. Even with real time raytracing it's still only a very basic approximation.

    Honestly, I would say the thing you're trying to do isn't really feasible with something like Unity. Yes the latest GPUs support raytracing, but Unity doesn't expose much support for that yet, and GPU raytracing is still fairly limited and mainly used for gross approximations of real world lighting.

    If you want to get into real world physics of light, even with GPU accelleration you're looking at several minutes to several hours, or even days, to render a single 1920x1080 image, depending on how accurate you want to be. Even top end spectral renderers like Indigo or Octane eventually have to cheat a bit so rendering times aren't insane.
     
  3. colmwhitehead1212

    colmwhitehead1212

    Joined:
    Oct 13, 2019
    Posts:
    2
    Okay noted, I think I could live with an approximation of the light's behaviour. I'm trying to look at the total observed light intensity when I view a satellite orbiting the earth. So i'd need reasonably accurate reflections for different materials in the satellite, a pretty large distance between the source and the object, and to avoid ambient light so avoiding emission surfaces and stuff.


    Where would I begin to look?
     
  4. bgolus

    bgolus

    Joined:
    Dec 7, 2012
    Posts:
    12,329
    A physics book?

    Seriously, this is way outside the realm of anything a game engine would even attempt to do in an even mildly accurate way. Usually we'd just cheat it with a single dot that's been hand animated in brightness to look sort of right. You're dealing with extreme super sampling, since a satellite viewed from earth is going to be super tiny on screen without a significant zoom, at which point floating point math will start breaking down and the camera rotation will get all jerky and even the mesh details will start to quantize. Games that handle planetary scales like this, like Kerbal, fake a ton of this kind of thing when it comes to rendering even if they internally track things at a higher precision.

    You'd have to render your satellite on it's own to a render texture of high enough resolution that can capture most of the details, lit with photometric HDR values of the sun, stars, and earth reflections. Then downsample the image to a single pixel and take the intensity value from that. Then do some math to take into account any dispersion from the atmosphere and the distance from the earth.

    Really you could probably get just as accurate results from some very approximate manual calculations based on the area of the solar panels, the reflectivity of those panels, the angle of the sun and the panels compared to the viewer, and some generic average reflectance from the body.

    Also, satellites orbiting the earth still get a ton of ambient light from the earth itself, especially when over an inhabited region. That's part of why satellites are visible from earth at night even when they aren't reflecting sunlight. The earth is bright!