getSpecular.js 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "/**\n\
  3. * Calculates the specular intensity of reflected light.\n\
  4. *\n\
  5. * @name czm_getSpecular\n\
  6. * @glslFunction\n\
  7. *\n\
  8. * @param {vec3} lightDirectionEC Unit vector pointing to the light source in eye coordinates.\n\
  9. * @param {vec3} toEyeEC Unit vector pointing to the eye position in eye coordinates.\n\
  10. * @param {vec3} normalEC The surface normal in eye coordinates.\n\
  11. * @param {float} shininess The sharpness of the specular reflection. Higher values create a smaller, more focused specular highlight.\n\
  12. *\n\
  13. * @returns {float} The intensity of the specular highlight.\n\
  14. *\n\
  15. * @see czm_phong\n\
  16. *\n\
  17. * @example\n\
  18. * float diffuseIntensity = czm_getLambertDiffuse(lightDirectionEC, normalEC);\n\
  19. * float specularIntensity = czm_getSpecular(lightDirectionEC, toEyeEC, normalEC, 200);\n\
  20. * vec3 color = (diffuseColor * diffuseIntensity) + (specularColor * specularIntensity);\n\
  21. */\n\
  22. float czm_getSpecular(vec3 lightDirectionEC, vec3 toEyeEC, vec3 normalEC, float shininess)\n\
  23. {\n\
  24. vec3 toReflectedLight = reflect(-lightDirectionEC, normalEC);\n\
  25. float specular = max(dot(toReflectedLight, toEyeEC), 0.0);\n\
  26. \n\
  27. // pow has undefined behavior if both parameters <= 0.\n\
  28. // Prevent this by making sure shininess is at least czm_epsilon2.\n\
  29. return pow(specular, max(shininess, czm_epsilon2));\n\
  30. }\n\
  31. ";