1
0

singularity.swsl 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //Gravitational lensing effect. Loosely inspired by https://unionassets.com/blog/the-effect-of-the-gravitational-lens-195 to be Clyde based (based on what)
  2. uniform sampler2D SCREEN_TEXTURE;
  3. uniform highp vec2 renderScale;
  4. uniform highp float maxDistance;
  5. uniform lowp int count;
  6. uniform highp float[5] falloffPower;
  7. uniform highp float[5] intensity;
  8. uniform highp vec2[5] position;
  9. // the `5`s in the array lengths correspond to the upper limit on the simultaneous distortion sources that can be present on screen at a time.
  10. // If you want to change this, make sure to change all of them here, in the for loop, and, in whatever overlay assigns the uniforms
  11. // (apparently #define is an unknown preprocessor directive)
  12. void fragment() {
  13. highp vec2 finalCoords = FRAGCOORD.xy;
  14. highp vec2 delta;
  15. highp float distance;
  16. highp float deformation;
  17. for (int i = 0; i < 5 && i < count; i++) {
  18. delta = FRAGCOORD.xy - position[i];
  19. distance = length(delta / renderScale);
  20. deformation = intensity[i] / pow(distance, falloffPower[i]);
  21. // ensure deformation goes to zero at max distance
  22. // avoids long-range single-pixel shifts that are noticeable when leaving PVS.
  23. if (distance >= maxDistance) {
  24. deformation = 0.0;
  25. } else {
  26. deformation *= (1.0 - pow(distance/maxDistance, 4.0));
  27. }
  28. if(deformation > 0.8)
  29. deformation = pow(deformation, 0.3);
  30. finalCoords -= deformation * delta;
  31. }
  32. COLOR = zTextureSpec(SCREEN_TEXTURE, finalCoords*SCREEN_PIXEL_SIZE );
  33. }