Search Unity

Detect shadows on terrain

Discussion in 'General Graphics' started by blackaciddevil, Jun 18, 2019.

  1. blackaciddevil

    blackaciddevil

    Joined:
    Mar 6, 2016
    Posts:
    48
    Is there any way to access shadows from a realtime directional light? I would like to get the world positions of areas in shadow on a terrain. I got AIs that will avoid direct light and try to move to areas in shadow. So they need to know where to move.

    The only thing i could think of is some sort of grid with light values. But I don't really know how to implement it. Any ideas?
     
  2. brownboot67

    brownboot67

    Joined:
    Jan 5, 2013
    Posts:
    375
    What is a texture but a grid of values?

    (Use a baked lightmap)
     
    blackaciddevil likes this.
  3. blackaciddevil

    blackaciddevil

    Joined:
    Mar 6, 2016
    Posts:
    48
    That is true and exaclty what I need (I think)! :) I am trying to get the Realtime GI lightmap but I can't find it. This might be totaly wrong but this is as close as I get, and resulting in no lightmap.


    Code (CSharp):
    1.  
    2. Texture2D lightmapColorTexture;
    3. Texture2D lightmapDirTexture;
    4. LightmapData lightmapData;
    5.  
    6. lightmapData = LightmapSettings.lightmaps[0];
    7. lightmapDirTexture = lightmapData.lightmapDir;
    8. lightmapColorTexture = lightmapData.lightmapColor;