Search Unity

How to get the Intensity of Light on Shader?

Discussion in 'Scripting' started by egohim, Jul 4, 2012.

  1. egohim

    egohim

    Joined:
    Nov 11, 2010
    Posts:
    1
    I'll try to find start value of attenuation each point light or spot light.
    Is there any methods to get light intensity on vertex shader or fragment shader?
    thanks.
     
  2. Khalanar_Dev

    Khalanar_Dev

    Joined:
    Mar 25, 2013
    Posts:
    34
    Hello, did you manage to solve this? I'm facing the same issue here =)

    Thanks
     
  3. jochenWinkler

    jochenWinkler

    Joined:
    Apr 29, 2014
    Posts:
    2
    Had the same problem. It seems to be included in _LightColor0.

    So _LightColor0 does not only give you the color of the light, but the color of the light premultiplied with it's intensity.
    To use it, include it with:

    uniform float4 _LightColor0; // automaticly from "Lighting.cginc

    at the start of your CGPROGRAM (together with your other uniforms like the _MainTex). Then use it like:

    float4 color;
    float3 colorCalculatedForThisFragment = float3(1,1,1); //just for testing, in reallity you would want to calculate distance and angle.
    color.rgb = colorCalculatedForThisFragment * _LightColor0;
    color.a = 1;
    return color;

    Note, unlike many other values, _LightColor0 seem not to be limited between (0,0,0) and (1,1,1) - for a bright yellow light it might end up being something like (5.1, 5.7, 0.0).
     
    pedua, IgorAherne and Kin0min like this.