BumpMapMaterial.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. //This file is automatically rebuilt by the Cesium build process.
  2. /*global define*/
  3. define(function() {
  4. "use strict";
  5. return "uniform sampler2D image;\n\
  6. uniform float strength;\n\
  7. uniform vec2 repeat;\n\
  8. \n\
  9. czm_material czm_getMaterial(czm_materialInput materialInput)\n\
  10. {\n\
  11. czm_material material = czm_getDefaultMaterial(materialInput);\n\
  12. \n\
  13. vec2 st = materialInput.st;\n\
  14. \n\
  15. vec2 centerPixel = fract(repeat * st);\n\
  16. float centerBump = texture2D(image, centerPixel).channel;\n\
  17. \n\
  18. float imageWidth = float(imageDimensions.x);\n\
  19. vec2 rightPixel = fract(repeat * (st + vec2(1.0 / imageWidth, 0.0)));\n\
  20. float rightBump = texture2D(image, rightPixel).channel;\n\
  21. \n\
  22. float imageHeight = float(imageDimensions.y);\n\
  23. vec2 leftPixel = fract(repeat * (st + vec2(0.0, 1.0 / imageHeight)));\n\
  24. float topBump = texture2D(image, leftPixel).channel;\n\
  25. \n\
  26. vec3 normalTangentSpace = normalize(vec3(centerBump - rightBump, centerBump - topBump, clamp(1.0 - strength, 0.1, 1.0)));\n\
  27. vec3 normalEC = materialInput.tangentToEyeMatrix * normalTangentSpace;\n\
  28. \n\
  29. material.normal = normalEC;\n\
  30. material.diffuse = vec3(0.01);\n\
  31. \n\
  32. return material;\n\
  33. }";
  34. });