Advertisement
Zenn_

Reduction shader

May 31st, 2019
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uniform sampler2D texture;
  2. uniform float width; //x resolution of the image
  3.  
  4. void main()
  5. {
  6.     float pixeltopixeldistance = 1.0f / width;
  7.  
  8.     //odd pixel?
  9.     bool thisrow = fract(gl_TexCoord[0].x * width / 2.0f) < 0.5f;
  10.    
  11.     vec2 otherpixel;
  12.     if(!thisrow)    otherpixel = texture2D(texture, gl_TexCoord[0].xy - vec2(pixeltopixeldistance,0)).rg; //color to the left
  13.             else    otherpixel = texture2D(texture, gl_TexCoord[0].xy + vec2(pixeltopixeldistance,0)).rg; //color to the right
  14.    
  15.     vec2 color  = texture2D(texture, gl_TexCoord[0].xy);
  16.     vec2 result = vec2(min(color, otherpixel));  //, min(min(color.g, colorL.g) , colorR.g));
  17.     gl_FragColor = vec4(min(color, otherpixel),0,1);
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement