BumpMapMaterial.js 1.1 KB

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