World positions, view positions and rgb values of the 8 most recent active dynamic lights. Their ranges (entity.lightrange) are stored in the vecLightPos.w component. The light range is zero if a light is not active.


vector, read-only



// Use dynamic lights in a vertex shader

  float4 vecLightPos[8];
  float4 vecLightColor[8];

// return the dynamic light on the surface
  float4 DoPointLight(float3 P, float3 N, int i)
// calculate the light ray pointing from the light to the surface
    float3 D = (float3)vecLightPos[i]-P;
// calculate the angle between surface and light ray
    float NdotL = dot(N,normalize(D));
// modulate the light by the surface angle
    float4 Color = vecLightColor[i] * NdotL;

// calculate the light attenuation factor
    float fac = 0.f;
    if (NdotL >= 0.f && vecLightPos[i].w > 0.f)
// get the distance factor
      float LD = length(D)/vecLightPos[i].w;
      if (LD < 1.f)
        fac = 1.f - LD;
    return Color * fac;

  VS_OUT TerrainLight_VS (
    float4 inPos : POSITION,
    float3 inNormal : NORMAL)
    VS_OUT Out;

// transform the vector position to screen coordinates
    Out.Pos = mul(inPos,matWorldViewProj);

// Terrains don't need to rotate the normal, but it must be normalized
    float3 N = normalize(inNormal);
    float3 P = mul(inPos,matWorld);

// Add 6 dynamic lights (maximum for vs 1.1)
    Out.Color = float4(0.f,0.f,0.f,0.f);
    for (int i=0; i<6; i++)
      Out.Color += DoPointLight(P,N,i);
    return Out;

See also:

material, shaders, predefined shader variables