grid.shader 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. uniform lowp vec4 u_plateColor;
  14. uniform lowp vec4 u_gridColor0;
  15. uniform lowp vec4 u_gridColor1;
  16. varying lowp vec2 v_uvs;
  17. void main()
  18. {
  19. vec2 coord = v_uvs.xy;
  20. // Compute anti-aliased world-space minor grid lines
  21. vec2 minorGrid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord);
  22. float minorLine = min(minorGrid.x, minorGrid.y);
  23. vec4 minorGridColor = mix(u_plateColor, u_gridColor1, 1.0 - min(minorLine, 1.0));
  24. // Compute anti-aliased world-space major grid lines
  25. vec2 majorGrid = abs(fract(coord / 10.0 - 0.5) - 0.5) / fwidth(coord / 10.0);
  26. float majorLine = min(majorGrid.x, majorGrid.y);
  27. gl_FragColor = mix(minorGridColor, u_gridColor0, 1.0 - min(majorLine, 1.0));
  28. }
  29. vertex41core =
  30. #version 410
  31. uniform highp mat4 u_modelViewProjectionMatrix;
  32. in highp vec4 a_vertex;
  33. in lowp vec2 a_uvs;
  34. out lowp vec2 v_uvs;
  35. void main()
  36. {
  37. gl_Position = u_modelViewProjectionMatrix * a_vertex;
  38. v_uvs = a_uvs;
  39. }
  40. fragment41core =
  41. #version 410
  42. uniform lowp vec4 u_plateColor;
  43. uniform lowp vec4 u_gridColor0;
  44. uniform lowp vec4 u_gridColor1;
  45. in lowp vec2 v_uvs;
  46. out vec4 frag_color;
  47. void main()
  48. {
  49. vec2 coord = v_uvs.xy;
  50. // Compute anti-aliased world-space minor grid lines
  51. vec2 minorGrid = abs(fract(coord - 0.5) - 0.5) / fwidth(coord);
  52. float minorLine = min(minorGrid.x, minorGrid.y);
  53. vec4 minorGridColor = mix(u_plateColor, u_gridColor1, 1.0 - min(minorLine, 1.0));
  54. // Compute anti-aliased world-space major grid lines
  55. vec2 majorGrid = abs(fract(coord / 10.0 - 0.5) - 0.5) / fwidth(coord / 10.0);
  56. float majorLine = min(majorGrid.x, majorGrid.y);
  57. frag_color = mix(minorGridColor, u_gridColor0, 1.0 - min(majorLine, 1.0));
  58. }
  59. [defaults]
  60. u_plateColor = [1.0, 1.0, 1.0, 1.0]
  61. u_gridColor0 = [0.96, 0.96, 0.96, 1.0]
  62. u_gridColor1 = [0.8, 0.8, 0.8, 1.0]
  63. [bindings]
  64. u_modelViewProjectionMatrix = model_view_projection_matrix
  65. [attributes]
  66. a_vertex = vertex
  67. a_uvs = uv0