Search Unity

Detecting light level produced from indirect prebaked realtime GI in a stealth game

Discussion in 'Global Illumination' started by Gooren, Jan 21, 2020.

  1. Gooren


    Nov 20, 2015

    Is is possible to detect the amount of indirect prebaked realtime GI hitting the player?
    We are working on a stealth game where sometimes, the player character is illuminated solely by the realtime GI. And it would be lovely if we could make the NPCs able to detect the player even in these circumstances.

    The game is played from the first-person perspective and the player doesn't see (and doesn't have) a visible body. But I thought I could put a small sphere behind the player camera? And detect the amount of realtime GI illuminating said sphere? No idea how to do that effectively though. Nor if that's even the best solution.

    Last edited: Jan 21, 2020
  2. bgolus


    Dec 7, 2012
    Presumably you’re using light probes in your scene to affect dynamic objects. I believe you should be able to get the light probe data at your character’s position using GetInterpolatedProbe()
    Unless it’s overridden, dynamic objects use the center of their bounds for the position when getting probe data. You can override the renderer’s anchor to make it an easier to track position, and be less affected by animation.

    Once you have your SphericalHarmonicsL2, you can call Evaluate on it with an array of directions. Cheapest option is to just use a single up vector. Using 6 directions (up, down, left, right, forward, & back vectors) will obviously get you better data.

    Using more directions will get it more accurate, but you don’t have to go too crazy. Maybe the 6 axis and 8 box corner diagonals might be the craziest you want to go.

    Using 4 directions (down, and the HL2 basis for the other 3 upward facing vectors) will be pretty cheap and probably 90% as good.
  3. Gooren


    Nov 20, 2015
    You sire, are a beast! Thank you so much!

    For dynamic light sources (the light sources that don't affect realtime GI), I will simply:
    - Point light: Simple raycast (from light source to player, this will apply for other light source as well obviously)
    - Spot light: Raycast and cone check
    - Ambient light: Well... that should be pretty straight forward...
    - Directional light: Raycast from light source to player, but projected on the directional light source plane

    There will be no baked lighting in the game most likely, so no lightmaps to sample for "baked only" light sources. So... that should be it, a "perfect" detection system :) Thanks to you!

    Last edited: Jan 22, 2020