You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.7 KiB

  1. #version 100
  2. precision mediump float;
  3. // Input vertex attributes (from vertex shader)
  4. varying vec2 fragTexCoord;
  5. varying vec4 fragColor;
  6. // Input uniform values
  7. uniform sampler2D texture0;
  8. uniform vec4 colDiffuse;
  9. // NOTE: Add here your custom variables
  10. uniform vec2 leftLensCenter;
  11. uniform vec2 rightLensCenter;
  12. uniform vec2 leftScreenCenter;
  13. uniform vec2 rightScreenCenter;
  14. uniform vec2 scale;
  15. uniform vec2 scaleIn;
  16. uniform vec4 hmdWarpParam;
  17. uniform vec4 chromaAbParam;
  18. void main()
  19. {
  20. // Compute lens distortion
  21. vec2 lensCenter = fragTexCoord.x < 0.5? leftLensCenter : rightLensCenter;
  22. vec2 screenCenter = fragTexCoord.x < 0.5? leftScreenCenter : rightScreenCenter;
  23. vec2 theta = (fragTexCoord - lensCenter)*scaleIn;
  24. float rSq = theta.x*theta.x + theta.y*theta.y;
  25. vec2 theta1 = theta*(hmdWarpParam.x + hmdWarpParam.y*rSq + hmdWarpParam.z*rSq*rSq + hmdWarpParam.w*rSq*rSq*rSq);
  26. vec2 thetaBlue = theta1*(chromaAbParam.z + chromaAbParam.w*rSq);
  27. vec2 tcBlue = lensCenter + scale*thetaBlue;
  28. if (any(bvec2(clamp(tcBlue, screenCenter - vec2(0.25, 0.5), screenCenter + vec2(0.25, 0.5)) - tcBlue)))
  29. {
  30. // Set black fragment for everything outside the lens border
  31. gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
  32. }
  33. else
  34. {
  35. // Compute color chroma aberration
  36. float blue = texture2D(texture0, tcBlue).b;
  37. vec2 tcGreen = lensCenter + scale*theta1;
  38. float green = texture2D(texture0, tcGreen).g;
  39. vec2 thetaRed = theta1*(chromaAbParam.x + chromaAbParam.y*rSq);
  40. vec2 tcRed = lensCenter + scale*thetaRed;
  41. float red = texture2D(texture0, tcRed).r;
  42. gl_FragColor = vec4(red, green, blue, 1.0);
  43. }
  44. }