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.

53 lines
1.8 KiB

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