Zenn_

Untitled

Aug 10th, 2019
792
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uniform sampler2D texture;
  2. uniform int width;
  3.  
  4. //second step in the lighting algorithm.
  5. //distorts the image so the rays run in
  6. //parallel to the x axis.
  7. void main()
  8. {
  9.     //translate u and v into [-1 , 1] domain
  10.     float u = (gl_TexCoord[0].x * 2.0f) - 1.0f;
  11.     float v = (gl_TexCoord[0].y * 2.0f) - 1.0f;
  12.    
  13.     //then, as u0 approaches 0 (the center), v should also approach 0
  14.     v = v * abs(u);
  15.    
  16.     //convert back from [-1,1] domain to [0,1] domain
  17.     v = (v + 1.0f) * 0.5f;
  18.    
  19.     //we now have the coordinates for reading from the initial image
  20.     vec2 newCoords = vec2(gl_TexCoord[0].x, v);
  21.    
  22.     //read for both horizontal and vertical direction and store them in separate channels
  23.     float horizontal = texture(texture, newCoords.xy).r;
  24.     float   vertical = texture(texture, newCoords.yx).r;
  25.     gl_FragColor = vec4(horizontal,vertical ,0,1);
  26. }
RAW Paste Data