Search Unity

Question how to make a light detection system in hdrp

Discussion in 'High Definition Render Pipeline' started by Aleksandre-, Nov 11, 2022.

  1. Aleksandre-

    Aleksandre-

    Joined:
    Dec 1, 2016
    Posts:
    3
    I'm trying to make a light detection system in hdrp, I was thinking of using another camera to take the amount of light taken on a pixel on a plane but the hdrp handles very poorly several cameras which makes lose a lot of performance and I find nothing that could help me to make this system without multiple camera, if you have an idea to help me it would be nice :)
     
  2. chemicalcrux

    chemicalcrux

    Joined:
    Mar 16, 2017
    Posts:
    720
    If you don't mind sticking to baked/mixed lights, then you can use light probes! I'm doing that for a stealth system, since I need to know how visible the player is.

    You can query for an interpolated light probe at any point in the world with...

    Code (CSharp):
    1. LightProbes.GetInterpolatedProbe(pos, null, out var probe);
    You can then evaluate this probe to get a light level. You need to evaluate it in a specific direction -- light probes describe not only the overall amount of light, but also which way it's going.

    Note that I'm not quite sure if the direction should be pointing into the surface that's being lit or out of of the surface that's being lit. The code below uses the direction from the viewer to the point, which is probably completely wrong...

    With that caveat, here's what I'm doing right now:

    Code (CSharp):
    1.     public static float LightAt(Vector3 pos, Vector3 dir)
    2.     {
    3.         Vector3[] dirs = new Vector3[] { dir };
    4.         Color[] results = new Color[1];
    5.         LightProbes.GetInterpolatedProbe(pos, null, out var probe);
    6.         probe.Evaluate(dirs, results);
    7.  
    8.         Color.RGBToHSV(results[0], out _, out _, out var val);
    9.         return val;
    10.     }
    I'm not sure what I'd do if I needed realtime lights. I guess I'd do a few raycasts to approximate whether the light source is hitting the target.
     
    eugeneloza and ElevenGame like this.