Created
January 25, 2019 10:09
-
-
Save g761007/fca64d4cf056c73611d39d66faf7ce87 to your computer and use it in GitHub Desktop.
Simple eye distortion
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
precision highp float; | |
varying highp vec2 textureCoordinate; | |
uniform sampler2D inputImageTexture; | |
uniform lowp vec2 leftPupil; | |
uniform lowp vec2 rightPupil; | |
uniform lowp float intensity; | |
void main() { | |
vec2 p = vec2(textureCoordinate.x, textureCoordinate.y); | |
if (intensity != 0.0) { | |
vec2 leftEye = vec2(leftPupil.x, leftPupil.y); | |
vec2 rightEye = vec2(rightPupil.x, rightPupil.y); | |
float weight = 0.0; | |
float dis = distance(leftEye, rightEye); | |
float radius = dis * 0.27; | |
if (distance(p, leftEye) <= radius) { | |
weight = pow(distance(p, leftEye) / radius, intensity); | |
p = leftEye + (p - leftEye) * weight; | |
} else if (distance(p, rightEye) <= radius) { | |
weight = pow(distance(p, rightEye) / radius, intensity); | |
p = rightEye + (p - rightEye) * weight; | |
} | |
} | |
gl_FragColor = texture2D(inputImageTexture, p); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment