BsCommonFrag.glsl 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Common code for all fragment shaders of BS
  2. #define DEFAULT_FLOAT_PRECISION mediump
  3. #pragma anki include "shaders/Common.glsl"
  4. #pragma anki include "shaders/MsBsCommon.glsl"
  5. #pragma anki include "shaders/LinearDepth.glsl"
  6. in vec2 vTexCoord;
  7. flat in float vAlpha;
  8. #if defined(PASS_COLOR)
  9. layout(location = 0) out vec4 fColor;
  10. # define fColor_DEFINED
  11. #endif
  12. #if defined(PASS_COLOR)
  13. # define texture_DEFINED
  14. #endif
  15. #define getAlpha_DEFINED
  16. float getAlpha()
  17. {
  18. return vAlpha;
  19. }
  20. #if defined(PASS_COLOR)
  21. # define writeFais_DEFINED
  22. void writeFais(in vec4 color)
  23. {
  24. fColor = color;
  25. }
  26. #endif
  27. #if defined(PASS_COLOR)
  28. # define particleAlpha_DEFINED
  29. void particleAlpha(in sampler2D tex, in float alpha)
  30. {
  31. vec4 color = texture(tex, vTexCoord);
  32. color.w *= alpha;
  33. writeFais(color);
  34. }
  35. #endif
  36. #if defined(PASS_COLOR)
  37. # define particleSoft_DEFINED
  38. void particleSoft(in sampler2D depthMap, in sampler2D tex, in float alpha)
  39. {
  40. const vec2 screenSize =
  41. vec2(1.0 / float(RENDERING_WIDTH), 1.0 / float(RENDERING_HEIGHT));
  42. float depth = texture(depthMap, gl_FragCoord.xy * screenSize).r;
  43. float delta = depth - gl_FragCoord.z;
  44. float softalpha = clamp(delta * 100.0, 0.0, 1.0);
  45. vec4 color = texture(tex, vTexCoord);
  46. color.w *= alpha * softalpha;
  47. writeFais(color);
  48. }
  49. #endif