grid.shader 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. }
  39. vertex41core =
  40. #version 410
  41. uniform highp mat4 u_modelMatrix;
  42. uniform highp mat4 u_viewMatrix;
  43. uniform highp mat4 u_projectionMatrix;
  44. in highp vec4 a_vertex;
  45. in lowp vec2 a_uvs;
  46. out lowp vec2 v_uvs;
  47. void main()
  48. {
  49. gl_Position = u_projectionMatrix * u_viewMatrix * u_modelMatrix * a_vertex;
  50. v_uvs = a_uvs;
  51. }
  52. fragment41core =
  53. #version 410
  54. uniform lowp vec4 u_plateColor;
  55. uniform lowp vec4 u_gridColor0;
  56. uniform lowp vec4 u_gridColor1;
  57. in lowp vec2 v_uvs;
  58. out vec4 frag_color;
  59. void main()
  60. {
  61. vec2 coord = v_uvs.xy;
  62. // Compute anti-aliased world-space minor grid lines
  63. vec2 minorGrid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord);
  64. float minorLine = min(minorGrid.x, minorGrid.y);
  65. vec4 minorGridColor = mix(u_plateColor, u_gridColor1, 1.0 - min(minorLine, 1.0));
  66. // Compute anti-aliased world-space major grid lines
  67. vec2 majorGrid = abs(fract(coord / 10.0 - 0.5) - 0.5) / fwidth(coord / 10.0);
  68. float majorLine = min(majorGrid.x, majorGrid.y);
  69. frag_color = mix(minorGridColor, u_gridColor0, 1.0 - min(majorLine, 1.0));
  70. }
  71. [defaults]
  72. u_plateColor = [1.0, 1.0, 1.0, 1.0]
  73. u_gridColor0 = [0.96, 0.96, 0.96, 1.0]
  74. u_gridColor1 = [0.8, 0.8, 0.8, 1.0]
  75. [bindings]
  76. u_modelMatrix = model_matrix
  77. u_viewMatrix = view_matrix
  78. u_projectionMatrix = projection_matrix
  79. [attributes]
  80. a_vertex = vertex
  81. a_uvs = uv0