glow.glslf 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #version GLSL_VERSION
  2. #include <precision_statement.glslf>
  3. #include <std.glsl>
  4. uniform sampler2D u_src_color;
  5. uniform sampler2D u_glow_mask_small;
  6. uniform sampler2D u_glow_mask_large;
  7. uniform float u_glow_mask_small_coeff;
  8. uniform float u_glow_mask_large_coeff;
  9. /*==============================================================================
  10. SHADER INTERFACE
  11. ==============================================================================*/
  12. GLSL_IN vec2 v_texcoord;
  13. //------------------------------------------------------------------------------
  14. GLSL_OUT vec4 GLSL_OUT_FRAG_COLOR;
  15. /*==============================================================================
  16. MAIN
  17. ==============================================================================*/
  18. void main(void) {
  19. vec4 src_color = GLSL_TEXTURE(u_src_color, v_texcoord);
  20. vec4 mask_small = GLSL_TEXTURE(u_glow_mask_small, v_texcoord);
  21. vec4 mask_large = GLSL_TEXTURE(u_glow_mask_large, v_texcoord);
  22. GLSL_OUT_FRAG_COLOR = src_color;
  23. if (mask_large.a != 0.0) {
  24. // outside object inside mask_large
  25. float alpha_large_out = u_glow_mask_large_coeff * mask_large.a;
  26. alpha_large_out = clamp(alpha_large_out, 0.0, 1.0);
  27. GLSL_OUT_FRAG_COLOR.rgb = mix(GLSL_OUT_FRAG_COLOR.rgb, mask_large.rgb / mask_large.a, alpha_large_out);
  28. GLSL_OUT_FRAG_COLOR.a = mix(GLSL_OUT_FRAG_COLOR.a, 1.0, alpha_large_out);
  29. }
  30. if (mask_small.a != 0.0) {
  31. // outside object inside mask_small
  32. float alpha_small_out = u_glow_mask_small_coeff * mask_small.a;
  33. alpha_small_out = clamp(alpha_small_out, 0.0, 1.0);
  34. GLSL_OUT_FRAG_COLOR.rgb = mix(GLSL_OUT_FRAG_COLOR.rgb, mask_small.rgb / mask_small.a, alpha_small_out);
  35. GLSL_OUT_FRAG_COLOR.a = mix(GLSL_OUT_FRAG_COLOR.a, 1.0, alpha_small_out);
  36. }
  37. }