stealth.swsl 1023 B

12345678910111213141516171819202122232425262728293031323334353637
  1. light_mode unshaded;
  2. uniform sampler2D SCREEN_TEXTURE;
  3. uniform highp float visibility; // number between -1 and 1
  4. uniform mediump vec2 reference;
  5. const mediump float time_scale = 0.25;
  6. const mediump float distance_scale = 0.125;
  7. void fragment() {
  8. highp vec4 sprite = zTexture(UV);
  9. if (sprite.a == 0.0) {
  10. discard;
  11. }
  12. // get distortion magnitude. hand crafted from a random jumble of trig functions
  13. highp vec2 coords = (FRAGCOORD.xy + reference) * distance_scale;
  14. highp float w = sin(TIME + (coords.x + coords.y + 2.0*sin(TIME*time_scale) * sin(TIME*time_scale + coords.x - coords.y)) );
  15. // visualize distortion via:
  16. // COLOR = vec4(w,w,w,1.0);
  17. w *= (3.0 + visibility * 2.0);
  18. highp vec4 background = zTextureSpec(SCREEN_TEXTURE, ( FRAGCOORD.xy + vec2(w) ) * SCREEN_PIXEL_SIZE );
  19. lowp float alpha;
  20. if (visibility>0.0)
  21. alpha = sprite.a * visibility;
  22. else
  23. alpha = 0.0;
  24. COLOR.xyz = mix(background.xyz, sprite.xyz, alpha);
  25. COLOR.a = 1.0;
  26. }