1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
| vec3 result=vec3(0,0,0);
float distances= length(light.pos - FragPos); float attenuation=1.0f/(light.constant+light.linear*distances+light.quadratic*distances*distances); float spotRatio=0; float cosTheta=dot(normalize(FragPos-light.pos),-1.0f*light.dirToLight);
if(cosTheta > light.cosPhyInner) { spotRatio=1.0f; }else if(cosTheta > light.cosPhyOutter){ spotRatio=(light.cosPhyOutter-cosTheta)/(light.cosPhyOutter - light.cosPhyInner); } else{ spotRatio=0.0f; } attenuation*=spotRatio;
float diffuseIntensity=max(dot(normalize(light.pos-FragPos),uNormal),0); vec3 diffuse=texture(material.diffuse,TexCoord).rgb*light.color*diffuseIntensity; result+=diffuse;
float specularIntersity=pow(max(dot(normalize(reflect(-normalize(light.pos-FragPos),uNormal)),dirToCamera),0),material.shininess); vec3 specular = specularIntersity*texture(material.specular,TexCoord).rgb*light.color; result+=specular;
result*=spotRatio; return result;
|