Advertisement
Guest User

work

a guest
Jun 2nd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. uniform sampler2D texture;
  2. uniform float width;
  3. uniform float border;
  4.  
  5. //third step in the lighting algorithm.
  6. //reduces the occlusion map to 2 pixels horizontally
  7. //(each pass halves the texture size horizontally)
  8.  
  9. /*the original reduction shader from Zima only used min(pixel, pixelRight), adding the left pixel
  10. somehow made it work better, i dont know why, should technically be the same thing right? maybe my
  11. downscaling method is sloppy or theres some mipmapping going on im not aware of, even though i only
  12. scale down in the x axis, but i spent weeks on this already and just dont care anymore*/
  13.  
  14. void main()
  15. {
  16.     float pixeltopixeldistance = 1.0f / width;
  17.  
  18.     //odd pixel?
  19.     bool thisrow = fract(gl_TexCoord[0].x * width / 2.0f) < 0.5f;
  20.    
  21.     vec2 otherpixel = texture2D(texture, gl_TexCoord[0].xy - vec2(pixeltopixeldistance,0)).rg; //color to the right
  22.    
  23.     vec2 color     = texture2D(texture, gl_TexCoord[0].xy);
  24.     vec2 result = vec2(min(color, otherpixel));  //, min(min(color.g, colorL.g) , colorR.g));
  25.     if (!thisrow && !(gl_TexCoord[0].x < 0.5f && gl_TexCoord[0].x + pixeltopixeldistance > 0.5f))
  26.         gl_FragColor = vec4(min(color, otherpixel),0,1);
  27. }
  28.  
  29. /*
  30. void main()
  31. {
  32.     float pixeltopixeldistance = 1.0f / width;
  33.  
  34.     //odd pixel?
  35.     bool thisrow = fract(gl_TexCoord[0].x * width / 2.0f) < 0.5f;
  36.    
  37.     vec2 pixeloffset = vec2(pixeltopixeldistance,0).rg;
  38.     if(thisrow) pixeloffset *= -1.f;
  39.    
  40.     vec2 otherpixel = texture2D(texture, clamp(gl_TexCoord[0].xy + pixeloffset, vec2(0.0f, 0.0f), vec2(1.0f,0.0f)));
  41.    
  42.     vec2 color  = texture2D(texture, gl_TexCoord[0].xy);
  43.     vec2 result = min(color, otherpixel);  //, min(min(color.g, colorL.g) , colorR.g));
  44.     if (
  45.         !thisrow &&
  46.         !((gl_TexCoord[0].x < border) && (gl_TexCoord[0].x + pixeloffset.x >= border)) &&
  47.         !((gl_TexCoord[0].x > border) && (gl_TexCoord[0].x + pixeloffset.x <= border))
  48.     )
  49.         gl_FragColor = vec4(min(color, otherpixel), 0, 1);
  50. }
  51. */
  52.  
  53. /*
  54. void main()
  55. {
  56.     float pixeltopixeldistance = 1.0f / width;
  57.  
  58.     //odd pixel?
  59.     bool thisrow = fract(gl_TexCoord[0].x * width / 2.0f) < 0.5f;
  60.    
  61.     vec2 otherpixel;
  62.     if(!thisrow)    otherpixel = texture2D(texture, gl_TexCoord[0].xy - vec2(pixeltopixeldistance,0)).rg; //color to the left
  63.             else    otherpixel = texture2D(texture, gl_TexCoord[0].xy + vec2(pixeltopixeldistance,0)).rg; //color to the right
  64.    
  65.     vec2 color  = texture2D(texture, gl_TexCoord[0].xy);
  66.     vec2 result = vec2(min(color, otherpixel));  //, min(min(color.g, colorL.g) , colorR.g));
  67.     gl_FragColor = vec4(min(color, otherpixel),0,1);
  68. }
  69. */
  70.  
  71.  
  72. /*
  73. void main()
  74. {
  75.     float pixeltopixeldistance = 1.0f / width;
  76.  
  77.     //odd pixel?
  78.     bool thisrow = fract(gl_TexCoord[0].x * width / 2.0f) < 0.5f;
  79.    
  80.     vec2 otherpixel = texture2D(texture, gl_TexCoord[0].xy - vec2(pixeltopixeldistance,0)).rg; //color to the right
  81.    
  82.     vec2 color     = texture2D(texture, gl_TexCoord[0].xy);
  83.     vec2 result = vec2(min(color, otherpixel));  //, min(min(color.g, colorL.g) , colorR.g));
  84.     if (!thisrow && !(gl_TexCoord[0].x < 0.5f && gl_TexCoord[0].x + pixeltopixeldistance > 0.5f))
  85.         gl_FragColor = vec4(min(color, otherpixel),0,1);
  86. }
  87. */
  88. /*
  89. void main(){
  90.     vec2 color = texture2D(texture, gl_TexCoord[0].xy);
  91.     vec2 colorR = texture2D(texture, clamp(gl_TexCoord[0].xy + vec2(1.0f / width, 0.0f), vec2(0.0f, 0.0f), vec2(1.0f,1.0f)));
  92.     if(gl_TexCoord[0].x < border && gl_TexCoord[0].x + 1.0f / width > border)
  93.         discard;
  94.     else gl_FragColor = vec4(min(color, colorR), 0, 1);
  95.    
  96. }
  97. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement