Advertisement
sk82

Untitled

Jan 30th, 2023
579
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. precision mediump float;
  2.  
  3.     uniform vec2 u_mouse;
  4.  
  5.     uniform sampler2D u_originalImage;
  6.     uniform sampler2D u_nextImage;
  7.     uniform sampler2D u_flowTex;
  8.  
  9.     varying vec2 v_texcoord;
  10.     uniform vec2 u_texSize;
  11.  
  12.     vec2 decodeFlow(vec3 flow) {
  13.         float angle =   flow.x  * 2.0 * 3.1415926535897932384626433832795;
  14.         float magnitude = flow.y;
  15.         return vec2(sin(angle) * magnitude, cos(angle) * magnitude);
  16.     }
  17.  
  18.     vec3 RGBtoHSV(vec3 c) {
  19.         vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);
  20.         vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));
  21.         vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));
  22.    
  23.         float d = q.x - min(q.w, q.y);
  24.         float e = 1.0e-10;
  25.         return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);
  26.     }
  27.  
  28.     void main() {
  29.  
  30.         vec3 color = texture2D(u_flowTex, v_texcoord).rgb;
  31.         vec3 flowHSV = RGBtoHSV(color);
  32.         vec2 flowVec = decodeFlow(flowHSV);
  33.         vec2 flowTexCoord = v_texcoord +  (flowVec / u_texSize)  *25.0* ( u_mouse.y);
  34.  
  35.         if (u_mouse.y > 0.50) {
  36.             float weight = (1.0 - u_mouse.y) / .5;
  37.             // Sigmoid blending.
  38.             float blend = 1.0 / (1.0 + exp(-6.0 * (weight - 0.5)));
  39.             vec4 originalSample = texture2D(u_originalImage, flowTexCoord);
  40.             vec4 transitionSample = texture2D(u_nextImage, v_texcoord);
  41.             vec4 blendedSample = mix(transitionSample, originalSample, blend);
  42.             gl_FragColor = blendedSample;
  43.         }
  44.         else {
  45.             gl_FragColor = texture2D(u_originalImage, flowTexCoord);
  46.         }
  47.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement