phong.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "float czm_private_getLambertDiffuseOfMaterial(vec3 lightDirectionEC, czm_material material)\n\
  3. {\n\
  4. return czm_getLambertDiffuse(lightDirectionEC, material.normal);\n\
  5. }\n\
  6. \n\
  7. float czm_private_getSpecularOfMaterial(vec3 lightDirectionEC, vec3 toEyeEC, czm_material material)\n\
  8. {\n\
  9. return czm_getSpecular(lightDirectionEC, toEyeEC, material.normal, material.shininess);\n\
  10. }\n\
  11. \n\
  12. /**\n\
  13. * Computes a color using the Phong lighting model.\n\
  14. *\n\
  15. * @name czm_phong\n\
  16. * @glslFunction\n\
  17. *\n\
  18. * @param {vec3} toEye A normalized vector from the fragment to the eye in eye coordinates.\n\
  19. * @param {czm_material} material The fragment's material.\n\
  20. *\n\
  21. * @returns {vec4} The computed color.\n\
  22. *\n\
  23. * @example\n\
  24. * vec3 positionToEyeEC = // ...\n\
  25. * czm_material material = // ...\n\
  26. * vec3 lightDirectionEC = // ...\n\
  27. * out_FragColor = czm_phong(normalize(positionToEyeEC), material, lightDirectionEC);\n\
  28. *\n\
  29. * @see czm_getMaterial\n\
  30. */\n\
  31. vec4 czm_phong(vec3 toEye, czm_material material, vec3 lightDirectionEC)\n\
  32. {\n\
  33. // Diffuse from directional light sources at eye (for top-down)\n\
  34. float diffuse = czm_private_getLambertDiffuseOfMaterial(vec3(0.0, 0.0, 1.0), material);\n\
  35. if (czm_sceneMode == czm_sceneMode3D) {\n\
  36. // (and horizon views in 3D)\n\
  37. diffuse += czm_private_getLambertDiffuseOfMaterial(vec3(0.0, 1.0, 0.0), material);\n\
  38. }\n\
  39. \n\
  40. float specular = czm_private_getSpecularOfMaterial(lightDirectionEC, toEye, material);\n\
  41. \n\
  42. // Temporary workaround for adding ambient.\n\
  43. vec3 materialDiffuse = material.diffuse * 0.5;\n\
  44. \n\
  45. vec3 ambient = materialDiffuse;\n\
  46. vec3 color = ambient + material.emission;\n\
  47. color += materialDiffuse * diffuse * czm_lightColor;\n\
  48. color += material.specular * specular * czm_lightColor;\n\
  49. \n\
  50. return vec4(color, material.alpha);\n\
  51. }\n\
  52. \n\
  53. vec4 czm_private_phong(vec3 toEye, czm_material material, vec3 lightDirectionEC)\n\
  54. {\n\
  55. float diffuse = czm_private_getLambertDiffuseOfMaterial(lightDirectionEC, material);\n\
  56. float specular = czm_private_getSpecularOfMaterial(lightDirectionEC, toEye, material);\n\
  57. \n\
  58. vec3 ambient = vec3(0.0);\n\
  59. vec3 color = ambient + material.emission;\n\
  60. color += material.diffuse * diffuse * czm_lightColor;\n\
  61. color += material.specular * specular * czm_lightColor;\n\
  62. \n\
  63. return vec4(color, material.alpha);\n\
  64. }\n\
  65. ";