      // in WorldView space, the camera is at <0> so just invert the position
        float3 HalfVector = normalize(normalize(-TransformedPosition.xyz) + VecToLight);

        // the max is to ensure that the attenuation only diminishes the light
        float atten = 1.0 / max(Data.AttenAndRange.x
                                + Data.AttenAndRange.y * DistToLight
                                + Data.AttenAndRange.z * DistToLight * DistToLight,
                                1.0);

        // AttenAndRange.w is the light's range
        Output.Diffuse.rgb += Data.Color.rgb
                              * pow(max(dot(TransformedNormal, HalfVector), 0), SpecularPower)
                              * atten
                              * step(DistToLight, Data.AttenAndRange.w);
    }
}
