聚光灯软化边缘的关键:
float diffuseIntensity=0.0;
//计算聚光灯的入射光线和中心线的夹角的余弦
float currentCosThta=max(0.0,dot(L,spotLightDirection));
if(currentCosThta>cosThta)
{
//-----聚光灯软化边缘的关键步骤 计算 currentCosThta的幂
diffuseIntensity=pow(currentCosThta,U_LightDirection.w);
}
//--漫反射光的最终值
vec4 diffuseColor=U_DiffuseLightColor*U_DiffuseMaterial*diffuseIntensity*attenuation*4.0;
边缘软化后的效果图
未软化边缘的效果图
顶点shader实现