12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #version 120
  2. uniform sampler2D texture;
  3. uniform sampler2D desktop;
  4. uniform vec2 screenSize;
  5. uniform vec2 mouse;
  6. varying vec2 uvCoord;
  7. void main()
  8. {
  9. // adjustable parameters
  10. float circleSize = 128;
  11. float borderSize = 2;
  12. // The smaller this value is, the more intense the magnification!
  13. float magnifyNerf = 1.1;
  14. vec4 borderColor = vec4(0,0,0,1);
  15. bool crosshair = true;
  16. // actual code
  17. vec2 mUV = vec2(mouse.x, -mouse.y)/screenSize + vec2(0,1);
  18. float du = distance(mUV,uvCoord);
  19. float dr = distance(mUV*screenSize,uvCoord*screenSize);
  20. vec4 color = vec4(0);
  21. if ( dr > circleSize+borderSize ) {
  22. color = texture2D( texture, uvCoord );
  23. } else if ( dr < circleSize ) {
  24. if ( crosshair && (distance(mUV.x, uvCoord.x)<1/screenSize.x || distance(mUV.y,uvCoord.y)<1/screenSize.y) ) {
  25. color = borderColor;
  26. } else {
  27. float t = 1-du;
  28. vec2 b = uvCoord;
  29. vec2 c = (mUV-uvCoord);
  30. vec2 upsideDown = c/magnifyNerf*t*t+b;
  31. vec4 textureColor = texture2D( texture, upsideDown );
  32. color = mix( texture2D( desktop, vec2(upsideDown.x, -upsideDown.y) ), textureColor, textureColor.a );
  33. }
  34. } else if ( dr < circleSize+borderSize ) {
  35. color = borderColor;
  36. }
  37. gl_FragColor = color;
  38. }