grid.shader 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. [shaders]
  2. vertex =
  3. uniform highp mat4 u_modelViewProjectionMatrix;
  4. attribute highp vec4 a_vertex;
  5. attribute lowp vec2 a_uvs;
  6. varying lowp vec2 v_uvs;
  7. void main()
  8. {
  9. gl_Position = u_modelViewProjectionMatrix * a_vertex;
  10. v_uvs = a_uvs;
  11. }
  12. fragment =
  13. #ifdef GL_ES
  14. #extension GL_OES_standard_derivatives : enable
  15. #ifdef GL_FRAGMENT_PRECISION_HIGH
  16. precision highp float;
  17. #else
  18. precision mediump float;
  19. #endif // GL_FRAGMENT_PRECISION_HIGH
  20. #endif // GL_ES
  21. uniform lowp vec4 u_plateColor;
  22. uniform lowp vec4 u_gridColor0;
  23. uniform lowp vec4 u_gridColor1;
  24. varying lowp vec2 v_uvs;
  25. void main()
  26. {
  27. vec2 coord = v_uvs.xy;
  28. // Compute anti-aliased world-space minor grid lines
  29. vec2 minorGrid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord);
  30. float minorLine = min(minorGrid.x, minorGrid.y);
  31. vec4 minorGridColor = mix(u_plateColor, u_gridColor1, 1.0 - min(minorLine, 1.0));
  32. // Compute anti-aliased world-space major grid lines
  33. vec2 majorGrid = abs(fract(coord / 10.0 - 0.5) - 0.5) / fwidth(coord / 10.0);
  34. float majorLine = min(majorGrid.x, majorGrid.y);
  35. gl_FragColor = mix(minorGridColor, u_gridColor0, 1.0 - min(majorLine, 1.0));
  36. }
  37. vertex41core =
  38. #version 410
  39. uniform highp mat4 u_modelViewProjectionMatrix;
  40. in highp vec4 a_vertex;
  41. in lowp vec2 a_uvs;
  42. out lowp vec2 v_uvs;
  43. void main()
  44. {
  45. gl_Position = u_modelViewProjectionMatrix * a_vertex;
  46. v_uvs = a_uvs;
  47. }
  48. fragment41core =
  49. #version 410
  50. uniform lowp vec4 u_plateColor;
  51. uniform lowp vec4 u_gridColor0;
  52. uniform lowp vec4 u_gridColor1;
  53. in lowp vec2 v_uvs;
  54. out vec4 frag_color;
  55. void main()
  56. {
  57. vec2 coord = v_uvs.xy;
  58. // Compute anti-aliased world-space minor grid lines
  59. vec2 minorGrid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord);
  60. float minorLine = min(minorGrid.x, minorGrid.y);
  61. vec4 minorGridColor = mix(u_plateColor, u_gridColor1, 1.0 - min(minorLine, 1.0));
  62. // Compute anti-aliased world-space major grid lines
  63. vec2 majorGrid = abs(fract(coord / 10.0 - 0.5) - 0.5) / fwidth(coord / 10.0);
  64. float majorLine = min(majorGrid.x, majorGrid.y);
  65. frag_color = mix(minorGridColor, u_gridColor0, 1.0 - min(majorLine, 1.0));
  66. }
  67. [defaults]
  68. u_plateColor = [1.0, 1.0, 1.0, 1.0]
  69. u_gridColor0 = [0.96, 0.96, 0.96, 1.0]
  70. u_gridColor1 = [0.8, 0.8, 0.8, 1.0]
  71. [bindings]
  72. u_modelViewProjectionMatrix = model_view_projection_matrix
  73. [attributes]
  74. a_vertex = vertex
  75. a_uvs = uv0