grid.shader 2.9 KB

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