stroke_shader.fsh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifdef GL_ES
  2. precision lowp float;
  3. #endif
  4. varying vec4 v_fragmentColor;
  5. varying vec2 v_texCoord;
  6. uniform float outlineSize;
  7. uniform vec3 outlineColor;
  8. uniform vec2 textureSize;
  9. uniform vec3 foregroundColor;
  10. int getIsStrokeWithAngelIndex(float angel)
  11. {
  12. float rad = angel * 0.01745329252;
  13. int stroke = 0;
  14. float a = texture2D(CC_Texture0, vec2(v_texCoord.x + outlineSize * cos(rad) / textureSize.x, v_texCoord.y + outlineSize * sin(rad) / textureSize.y)).a;
  15. if (a >= 0.5)
  16. {
  17. stroke = 1;
  18. }
  19. return stroke;
  20. }
  21. void main()
  22. {
  23. vec4 myC = texture2D(CC_Texture0, vec2(v_texCoord.x, v_texCoord.y));
  24. myC.rgb *= foregroundColor;
  25. if (myC.a >= 0.5)
  26. {
  27. gl_FragColor = v_fragmentColor * myC;
  28. return;
  29. }
  30. int strokeCount = 0;
  31. strokeCount += getIsStrokeWithAngelIndex(0.0);
  32. strokeCount += getIsStrokeWithAngelIndex(30.0);
  33. strokeCount += getIsStrokeWithAngelIndex(60.0);
  34. strokeCount += getIsStrokeWithAngelIndex(90.0);
  35. strokeCount += getIsStrokeWithAngelIndex(120.0);
  36. strokeCount += getIsStrokeWithAngelIndex(150.0);
  37. strokeCount += getIsStrokeWithAngelIndex(180.0);
  38. strokeCount += getIsStrokeWithAngelIndex(210.0);
  39. strokeCount += getIsStrokeWithAngelIndex(240.0);
  40. strokeCount += getIsStrokeWithAngelIndex(270.0);
  41. strokeCount += getIsStrokeWithAngelIndex(300.0);
  42. strokeCount += getIsStrokeWithAngelIndex(330.0);
  43. if (strokeCount > 0)
  44. {
  45. myC.rgb = outlineColor;
  46. myC.a = 1.0;
  47. }
  48. gl_FragColor = v_fragmentColor * myC;
  49. }