CheckerboardMaterial.glsl 1006 B

12345678910111213141516171819202122232425262728
  1. uniform vec4 lightColor;
  2. uniform vec4 darkColor;
  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. // From Stefan Gustavson's Procedural Textures in GLSL in OpenGL Insights
  9. float b = mod(floor(repeat.s * st.s) + floor(repeat.t * st.t), 2.0); // 0.0 or 1.0
  10. // Find the distance from the closest separator (region between two colors)
  11. float scaledWidth = fract(repeat.s * st.s);
  12. scaledWidth = abs(scaledWidth - floor(scaledWidth + 0.5));
  13. float scaledHeight = fract(repeat.t * st.t);
  14. scaledHeight = abs(scaledHeight - floor(scaledHeight + 0.5));
  15. float value = min(scaledWidth, scaledHeight);
  16. vec4 currentColor = mix(lightColor, darkColor, b);
  17. vec4 color = czm_antialias(lightColor, darkColor, currentColor, value, 0.03);
  18. material.diffuse = color.rgb;
  19. material.alpha = color.a;
  20. return material;
  21. }