Search Unity

How much light falls on mesh

Discussion in 'General Discussion' started by Nirvan, Dec 24, 2013.

  1. Nirvan

    Nirvan

    Joined:
    Nov 16, 2013
    Posts:
    134
    Hi, I want determinate how much mesh is illuminated by light sources.
    Is there simple way to check this?
    If no I will determinate it by distance from light sources ;)

    Thanks.
     
  2. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,125
    I'd perhaps have it be a function of distance and the intensity of the light
     
  3. Nirvan

    Nirvan

    Joined:
    Nov 16, 2013
    Posts:
    134
    But there are walls/corridors etc. and intensity will be caught even light not falls on mesh and when we determinate distance and obstacles it still will not be too much corrects because light can fall on mesh from cracks for example when mesh in in closet.
     
  4. dogzerx2

    dogzerx2

    Joined:
    Dec 27, 2009
    Posts:
    3,971
    You could use raycast.

    http://docs.unity3d.com/Documentation/ScriptReference/Physics.Raycast.html

    Raycast only returns the first collider in the ray. Hence if it's not the mesh, light received is zero; if it is, then light received is inverse of distance.
     
    Last edited: Dec 24, 2013
  5. XGundam05

    XGundam05

    Joined:
    Mar 29, 2012
    Posts:
    473
    If you have Pro, you can use Light Probes.

    If not, you might look into generating some sort of lighting model and implementing the lighting yourself in a shader. I'm not entirely certain yet how you'd do it (working that out myself currently), but if you could create a lighting model using voxels you might be off to a good start.

    The idea is that each voxel would have it's own lighting data, you could then figure out which vertices of a model were in which voxel and modify the lighting or vertex colors accordingly. I'm not yet certain how you'd pass the voxel-lighting data to a shader though (position and value and what-not), but there's gotta be a good way to do it.