builtin-graphics.effect 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Effect Syntax Guide: https://github.com/cocos-creator/docs-3d/blob/master/zh/material-system/effect-syntax.md
  2. CCEffect %{
  3. techniques:
  4. - passes:
  5. - vert: vs:vert
  6. frag: fs:frag
  7. blendState:
  8. targets:
  9. - blend: true
  10. blendSrc: one
  11. blendDst: one_minus_src_alpha
  12. blendSrcAlpha: one
  13. blendDstAlpha: one_minus_src_alpha
  14. rasterizerState:
  15. cullMode: none
  16. depthStencilState:
  17. depthTest: false
  18. depthWrite: false
  19. }%
  20. CCProgram vs %{
  21. precision highp float;
  22. #include <builtin/uniforms/cc-global>
  23. #include <builtin/uniforms/cc-local>
  24. in vec3 a_position;
  25. in vec4 a_color;
  26. out vec4 v_color;
  27. in float a_dist;
  28. out float v_dist;
  29. vec4 vert () {
  30. vec4 pos = vec4(a_position, 1);
  31. pos = cc_matViewProj * cc_matWorld * pos;
  32. v_color = a_color;
  33. v_dist = a_dist;
  34. return pos;
  35. }
  36. }%
  37. CCProgram fs %{
  38. #pragma extension([GL_OES_standard_derivatives, __VERSION__ < 300])
  39. precision highp float;
  40. in vec4 v_color;
  41. in float v_dist;
  42. vec4 frag () {
  43. vec4 o = v_color;
  44. #if __VERSION__ < 300
  45. #ifdef GL_OES_standard_derivatives
  46. float aa = fwidth(v_dist);
  47. #else
  48. float aa = 0.05;
  49. #endif
  50. #else
  51. float aa = fwidth(v_dist);
  52. #endif
  53. float alpha = 1. - smoothstep(-aa, 0., abs(v_dist) - 1.0);
  54. o.rgb *= o.a;
  55. o *= alpha;
  56. return o;
  57. }
  58. }%