What does lightposition.w mean?

Hello,
In UnityCG.cginc, there exist many LightPosition.w. But I don’t know the reason why to multiply LightPosition.w.

For example, there is
float3 toLight = unity_LightPosition.xyz - viewpos.xyz * unity_LightPosition*.w;
in the following code.
_
```csharp*_
*float3 ShadeVertexLightsFull (float4 vertex, float3 normal, int lightCount, bool spotLight)
{
float3 viewpos = UnityObjectToViewPos (vertex);
float3 viewN = normalize (mul ((float3x3)UNITY_MATRIX_IT_MV, normal));

float3 lightColor = UNITY_LIGHTMODEL_AMBIENT.xyz;
for (int i = 0; i < lightCount; i++) {
    float3 toLight = unity_LightPosition[i].xyz - viewpos.xyz * unity_LightPosition[i].w;
    float lengthSq = dot(toLight, toLight);

    // don't produce NaNs if some vertex position overlaps with the light
    lengthSq = max(lengthSq, 0.000001);

    toLight *= rsqrt(lengthSq);

    float atten = 1.0 / (1.0 + lengthSq * unity_LightAtten[i].z);
    if (spotLight)
    {
        float rho = max (0, dot(toLight, unity_SpotDirection[i].xyz));
        float spotAtt = (rho - unity_LightAtten[i].x) * unity_LightAtten[i].y;
        atten *= saturate(spotAtt);
    }

    float diff = max (0, dot (viewN, toLight));
    lightColor += unity_LightColor[i].rgb * (diff * atten);
}
return lightColor;

}
_
```*_

here it says,
View-space light position:
(-direction,0) for directional lights
(position,1) for point/spot lights.

1 Like

Oh, thanks. It is so kind of you!