2019-05-16 16:30:03 +03:00
|
|
|
#version 100
|
2019-04-11 14:53:01 +03:00
|
|
|
|
2019-05-16 16:30:03 +03:00
|
|
|
precision mediump float;
|
2019-04-11 14:53:01 +03:00
|
|
|
|
2019-05-16 16:30:03 +03:00
|
|
|
// Input vertex attributes (from vertex shader)
|
|
|
|
varying vec2 fragTexCoord;
|
|
|
|
varying vec4 fragColor;
|
|
|
|
|
|
|
|
// Input uniform values
|
2019-04-11 14:53:01 +03:00
|
|
|
uniform sampler2D texture0;
|
2019-05-16 16:30:03 +03:00
|
|
|
uniform vec4 colDiffuse;
|
|
|
|
|
|
|
|
// NOTE: Add here your custom variables
|
2019-04-11 14:53:01 +03:00
|
|
|
uniform vec2 leftLensCenter = vec2(0.288, 0.5);
|
|
|
|
uniform vec2 rightLensCenter = vec2(0.712, 0.5);
|
|
|
|
uniform vec2 leftScreenCenter = vec2(0.25, 0.5);
|
|
|
|
uniform vec2 rightScreenCenter = vec2(0.75, 0.5);
|
|
|
|
uniform vec2 scale = vec2(0.25, 0.45);
|
|
|
|
uniform vec2 scaleIn = vec2(4, 2.2222);
|
|
|
|
uniform vec4 hmdWarpParam = vec4(1, 0.22, 0.24, 0);
|
|
|
|
uniform vec4 chromaAbParam = vec4(0.996, -0.004, 1.014, 0.0);
|
|
|
|
|
|
|
|
void main()
|
|
|
|
{
|
2019-05-16 16:30:03 +03:00
|
|
|
// Compute lens distortion
|
2019-04-11 14:53:01 +03:00
|
|
|
vec2 lensCenter = fragTexCoord.x < 0.5? leftLensCenter : rightLensCenter;
|
|
|
|
vec2 screenCenter = fragTexCoord.x < 0.5? leftScreenCenter : rightScreenCenter;
|
|
|
|
vec2 theta = (fragTexCoord - lensCenter)*scaleIn;
|
|
|
|
float rSq = theta.x*theta.x + theta.y*theta.y;
|
|
|
|
vec2 theta1 = theta*(hmdWarpParam.x + hmdWarpParam.y*rSq + hmdWarpParam.z*rSq*rSq + hmdWarpParam.w*rSq*rSq*rSq);
|
|
|
|
vec2 thetaBlue = theta1*(chromaAbParam.z + chromaAbParam.w*rSq);
|
|
|
|
vec2 tcBlue = lensCenter + scale*thetaBlue;
|
|
|
|
|
|
|
|
if (any(bvec2(clamp(tcBlue, screenCenter - vec2(0.25, 0.5), screenCenter + vec2(0.25, 0.5)) - tcBlue)))
|
|
|
|
{
|
2019-05-16 16:30:03 +03:00
|
|
|
// Set black fragment for everything outside the lens border
|
|
|
|
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
2019-04-11 14:53:01 +03:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-05-16 16:30:03 +03:00
|
|
|
// Compute color chroma aberration
|
|
|
|
float blue = texture2D(texture0, tcBlue).b;
|
2019-04-11 14:53:01 +03:00
|
|
|
vec2 tcGreen = lensCenter + scale*theta1;
|
2019-05-16 16:30:03 +03:00
|
|
|
float green = texture2D(texture0, tcGreen).g;
|
2019-04-11 14:53:01 +03:00
|
|
|
|
|
|
|
vec2 thetaRed = theta1*(chromaAbParam.x + chromaAbParam.y*rSq);
|
|
|
|
vec2 tcRed = lensCenter + scale*thetaRed;
|
|
|
|
|
2019-05-16 16:30:03 +03:00
|
|
|
float red = texture2D(texture0, tcRed).r;
|
|
|
|
gl_FragColor = vec4(red, green, blue, 1.0);
|
2019-04-11 14:53:01 +03:00
|
|
|
}
|
2019-05-16 16:30:03 +03:00
|
|
|
}
|