BumpMapMaterial.glsl 1021 B

1234567891011121314151617181920212223242526272829
  1. uniform sampler2D image;
  2. uniform float strength;
  3. uniform vec2 repeat;
  4. czm_material czm_getMaterial(czm_materialInput materialInput)
  5. {
  6. czm_material material = czm_getDefaultMaterial(materialInput);
  7. vec2 st = materialInput.st;
  8. vec2 centerPixel = fract(repeat * st);
  9. float centerBump = texture2D(image, centerPixel).channel;
  10. float imageWidth = float(imageDimensions.x);
  11. vec2 rightPixel = fract(repeat * (st + vec2(1.0 / imageWidth, 0.0)));
  12. float rightBump = texture2D(image, rightPixel).channel;
  13. float imageHeight = float(imageDimensions.y);
  14. vec2 leftPixel = fract(repeat * (st + vec2(0.0, 1.0 / imageHeight)));
  15. float topBump = texture2D(image, leftPixel).channel;
  16. vec3 normalTangentSpace = normalize(vec3(centerBump - rightBump, centerBump - topBump, clamp(1.0 - strength, 0.1, 1.0)));
  17. vec3 normalEC = materialInput.tangentToEyeMatrix * normalTangentSpace;
  18. material.normal = normalEC;
  19. material.diffuse = vec3(0.01);
  20. return material;
  21. }