123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. vec2 boxOffset = vec2(-64,-64);
  11. vec2 boxSize = vec2(128,128);
  12. float magstrength = 5;
  13. vec2 borderSize = vec2(1,1);
  14. vec4 borderColor = vec4(0,0,0,1);
  15. bool crosshair = true;
  16. //------------------------------
  17. // actual code (don't touch unless you're brave)
  18. // convert to UV space
  19. boxOffset = boxOffset/screenSize;
  20. boxSize = boxSize/screenSize;
  21. borderSize = borderSize/screenSize;
  22. // get mouse position in UV space
  23. vec2 mpos = vec2(mouse.x, -mouse.y)/screenSize + vec2(0,1);
  24. vec4 color;
  25. // Check if our current UV is inside our box.
  26. if ( uvCoord.x < mpos.x+boxOffset.x+boxSize.x &&
  27. uvCoord.x > mpos.x+boxOffset.x &&
  28. uvCoord.y > mpos.y+boxOffset.y &&
  29. uvCoord.y < mpos.y+boxOffset.y+boxSize.y ) {
  30. // Check if we're actually inside the crosshair area.
  31. if ( (distance(uvCoord.x, mpos.x+boxOffset.x+boxSize.x/2) <= borderSize.x ||
  32. distance(uvCoord.y, mpos.y+boxOffset.y+boxSize.y/2) <= borderSize.y) && crosshair ) {
  33. color = borderColor;
  34. } else {
  35. // Calculate where the UV should be.
  36. vec2 zoomedUV = ((uvCoord-mpos)-(boxOffset+boxSize/2))/magstrength+mpos;
  37. // The desktop texture is upside-down due to X11
  38. vec2 zoomedUVFlipped = vec2( zoomedUV.x, -zoomedUV.y );
  39. // Then change the color to the desktop color to draw, then add on our rectangle on top.
  40. vec4 rectColor = texture2D( texture, zoomedUV );
  41. color = mix( texture2D( desktop, zoomedUVFlipped ), rectColor, rectColor.a );
  42. }
  43. // Then check if we're in our border size.
  44. } else if( uvCoord.x <= mpos.x+boxOffset.x+boxSize.x+borderSize.x &&
  45. uvCoord.x >= mpos.x+boxOffset.x-borderSize.x &&
  46. uvCoord.y >= mpos.y+boxOffset.y-borderSize.y &&
  47. uvCoord.y <= mpos.y+boxOffset.y+boxSize.y+borderSize.y ) {
  48. color = borderColor;
  49. } else {
  50. color = texture2D( texture, uvCoord );
  51. }
  52. gl_FragColor = color;
  53. }