Search Unity

Is there a way to look up light probe data for a mesh at runtime?

Discussion in 'Global Illumination' started by Farx, Feb 22, 2016.

  1. Farx

    Farx

    Joined:
    Sep 19, 2015
    Posts:
    4
    If I have an object using light probes, is there a way to get the data associated with whatever probes are affecting that object at any given point during runtime?

    For example, if I wanted to check to see if a character were standing in a shadowy area, is there some way of checking if (lightprobe.light/color.value < someThreshold), or something similar?
     
    Marc-Saubion likes this.
  2. Marc-Saubion

    Marc-Saubion

    Joined:
    Jul 6, 2011
    Posts:
    655
    Same here.

    Anything new about this? I'm surprised this data is not exposed as this usage seems obvious.
     
  3. Inter-Illusion

    Inter-Illusion

    Joined:
    Jan 5, 2014
    Posts:
    598
    Have you tried the GetInterpolatedProbe method?
    That will give you the probe data used for that mesh at that position, then you just need to evaluate it for some direction and get a color.

    Code (csharp):
    1.  
    2.  public Color GetProbeColor( Vector3 pos )
    3.  {
    4.     Rendering.SphericalHarmonicsL2 probe;
    5.     LightmapSettings.LightProbes.GetInterpolatedProbe(pos, null, out probe);
    6.      
    7.      
    8.     Vector3[] directions = new Vector3[] { new Vector3(0.0f, 1.0f, 0.0f) };
    9.     Color[] results = new Color[1];
    10.     probe.Evaluate(directions, results)
    11.      
    12.     return results[0];
    13.  }
    14.  
     
    Marc-Saubion likes this.
  4. Marc-Saubion

    Marc-Saubion

    Joined:
    Jul 6, 2011
    Posts:
    655
    That looks promissing. :) I have a team member checking it out.

    Thanks Inter-Illusion.
     
  5. Marc-Saubion

    Marc-Saubion

    Joined:
    Jul 6, 2011
    Posts:
    655
    It's done and works really well. ;)