pbrMetallicRoughnessMaterial.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. //This file is automatically rebuilt by the Cesium build process.
  2. export default "/**\n\
  3. * Compute parameters for physically based rendering using the\n\
  4. * metallic/roughness workflow. All inputs are linear; sRGB texture values must\n\
  5. * be decoded beforehand\n\
  6. *\n\
  7. * @name czm_pbrMetallicRoughnessMaterial\n\
  8. * @glslFunction\n\
  9. *\n\
  10. * @param {vec3} baseColor For dielectrics, this is the base color. For metals, this is the f0 value (reflectance at normal incidence)\n\
  11. * @param {float} metallic 0.0 indicates dielectric. 1.0 indicates metal. Values in between are allowed (e.g. to model rust or dirt);\n\
  12. * @param {float} roughness A value between 0.0 and 1.0\n\
  13. * @return {czm_pbrParameters} parameters to pass into {@link czm_pbrLighting}\n\
  14. */\n\
  15. czm_pbrParameters czm_pbrMetallicRoughnessMaterial(\n\
  16. vec3 baseColor,\n\
  17. float metallic,\n\
  18. float roughness\n\
  19. ) \n\
  20. {\n\
  21. czm_pbrParameters results;\n\
  22. \n\
  23. // roughness is authored as perceptual roughness\n\
  24. // square it to get material roughness\n\
  25. roughness = clamp(roughness, 0.0, 1.0);\n\
  26. results.roughness = roughness * roughness;\n\
  27. \n\
  28. // dielectrics use f0 = 0.04, metals use albedo as f0\n\
  29. metallic = clamp(metallic, 0.0, 1.0);\n\
  30. const vec3 REFLECTANCE_DIELECTRIC = vec3(0.04);\n\
  31. vec3 f0 = mix(REFLECTANCE_DIELECTRIC, baseColor, metallic);\n\
  32. results.f0 = f0;\n\
  33. \n\
  34. // diffuse only applies to dielectrics.\n\
  35. results.diffuseColor = baseColor * (1.0 - f0) * (1.0 - metallic);\n\
  36. \n\
  37. return results;\n\
  38. }\n\
  39. ";