BumpMapMaterial.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  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. \n\
  6. czm_material czm_getMaterial(czm_materialInput materialInput)\n\
  7. {\n\
  8. czm_material material = czm_getDefaultMaterial(materialInput);\n\
  9. \n\
  10. vec2 st = materialInput.st;\n\
  11. \n\
  12. vec2 centerPixel = fract(repeat * st);\n\
  13. float centerBump = texture(image, centerPixel).channel;\n\
  14. \n\
  15. float imageWidth = float(imageDimensions.x);\n\
  16. vec2 rightPixel = fract(repeat * (st + vec2(1.0 / imageWidth, 0.0)));\n\
  17. float rightBump = texture(image, rightPixel).channel;\n\
  18. \n\
  19. float imageHeight = float(imageDimensions.y);\n\
  20. vec2 leftPixel = fract(repeat * (st + vec2(0.0, 1.0 / imageHeight)));\n\
  21. float topBump = texture(image, leftPixel).channel;\n\
  22. \n\
  23. vec3 normalTangentSpace = normalize(vec3(centerBump - rightBump, centerBump - topBump, clamp(1.0 - strength, 0.1, 1.0)));\n\
  24. vec3 normalEC = materialInput.tangentToEyeMatrix * normalTangentSpace;\n\
  25. \n\
  26. material.normal = normalEC;\n\
  27. material.diffuse = vec3(0.01);\n\
  28. \n\
  29. return material;\n\
  30. }\n\
  31. ";