varying vec4 lastPosition; //Fragment position in the last frame varying vec4 currentPosition;//Fragment position in the current frame uniform sampler2D SaliencyMap; //Saliency map: Edge detector (only magnitude) + center surround differences uniform float time; //Frame time. uniform float habituation; //Habituation time for pixel's object //Constants for normalizing the optical fow map uniform float m; //0.4 uniform float Am; //700 pixels/s //Constants for normalizing the habituation uniform float h; //5 uniform float Ah; //12.5s //Viewport size uniform vec2 size; void main() { vec2 coordCurrent = (currentPosition.xy/currentPosition.w +1) /2.; vec2 coordLast = (lastPosition.xy /lastPosition.w + 1 ) /2.; vec2 distance = abs(coordCurrent * size - coordLast * size); ////////////////////////////////////////////////////////////////////////////////////////// //MOTION SALIENCY float speed = sqrt(dot(distance,distance))/time; //Mod float left = 1. / ( m * sqrt(2.*3.141566)); float right = - ((speed/Am)*(speed/Am)) / (m*m); float motionSaliency = 1.-left*exp(right); ////////////////////////////////////////////////////////////////////////////////////////// //SCENE SALIENCY float sceneSaliency = texture2D(SaliencyMap,coordCurrent).r; ////////////////////////////////////////////////////////////////////////////////////////// //HABITUATION SALIENCY left = 1. / ( h * sqrt(2.*3.141566)); right = -(habituation*habituation)/(h*h); float habituationSaliency = left*exp(right)*Ah; ////////////////////////////////////////////////////////////////////////////////////////// float saliency = motionSaliency * (sceneSaliency * 0.8 + habituationSaliency * 0.2); gl_FragColor = saliency; }