1
static NSString *const shader_fsh = SHADER_STRING(
precision mediump float;
varying vec2 textureCoordinate;
uniform sampler2D SamplerY;
uniform sampler2D SamplerUV;
uniform mat3 colorConversionMatrix;
uniform float correctionRadius;
uniform float zoom;
uniform float osdx;
uniform float osdy;
uniform int lensCorrect;
void main() {
mediump vec3 yuv;
lowp vec3 rgb;
vec2 newTextureCoor;
if (lensCorrect == 0) {
newTextureCoor = textureCoordinate;
} else {
if (textureCoordinate.x < osdx && textureCoordinate.y < osdy) {
newTextureCoor = textureCoordinate;
} else {
vec2 newCoor = textureCoordinate - vec2(0.5, 0.5);
float dis = length(newCoor);
float r = dis / correctionRadius;
float theta = zoom*1.0;
if(r > 0.0) {
theta = zoom*atan(r) / r;
}
newTextureCoor = vec2(0.5, 0.5) + newCoor * theta;
}
}
yuv.x = (texture2D(SamplerY, newTextureCoor).r - (16.0 / 255.0));
yuv.yz = (texture2D(SamplerUV, newTextureCoor).rg - vec2(0.5, 0.5));
rgb = colorConversionMatrix * yuv;
gl_FragColor = vec4(rgb, 1);
});
2
static NSString *const shader_fsh = SHADER_STRING(
precision mediump float;
varying vec2 textureCoordinate;
varying vec4 vPosition;
uniform sampler2D SamplerY;
uniform sampler2D SamplerUV;
uniform mat3 colorConversionMatrix;
uniform float zoom;
uniform float Fx;
uniform float Fy;
void main() {
mediump vec3 yuv;
lowp vec3 rgb;
vec4 vPos = vPosition;
vec2 vMapping = vPos.xy;
vMapping.x = vMapping.x + ((pow(vPos.y, 2.0)/zoom)*vPos.x/zoom)*-Fx;
vMapping.y = vMapping.y + ((pow(vPos.x, 2.0)/zoom)*vPos.y/zoom)*-Fy;
vMapping = vMapping/zoom * vec2(1.0, -1.0)/ 2.0 + vec2(0.5, 0.5);
yuv.x = (texture2D(SamplerY, vMapping).r - (16.0 / 255.0));
yuv.yz = (texture2D(SamplerUV, vMapping).rg - vec2(0.5, 0.5));
rgb = colorConversionMatrix * yuv;
gl_FragColor = vec4(rgb, 1);
});