You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

34 lines
1.1 KiB

  1. define([
  2. ], function (
  3. ) {
  4. return `
  5. varying vec2 vTextureCoord;
  6. uniform sampler2D uSampler;
  7. uniform float thickness;
  8. uniform vec4 outlineColor;
  9. uniform float pixelWidth;
  10. uniform float alpha;
  11. vec2 px = vec2(pixelWidth, pixelWidth);
  12. void main(void) {
  13. const float PI = 3.14159265358979323846264;
  14. vec4 ownColor = texture2D(uSampler, vTextureCoord);
  15. vec4 curColor;
  16. float maxAlpha = 0.;
  17. for (float angle = 0.; angle < PI * 2.; angle += %THICKNESS% ) {
  18. curColor = texture2D(uSampler, vec2(vTextureCoord.x + thickness * px.x * cos(angle), vTextureCoord.y + thickness * px.y * sin(angle)));
  19. maxAlpha = max(maxAlpha, curColor.a);
  20. }
  21. if (maxAlpha > 0.1)
  22. maxAlpha = alpha;
  23. else
  24. maxAlpha = 0.0;
  25. float resultAlpha = max(maxAlpha, ownColor.a);
  26. gl_FragColor = vec4((ownColor.rgb + outlineColor.rgb * (1. - ownColor.a)) * resultAlpha, resultAlpha);
  27. }
  28. `;
  29. });