Advertisement
Guest User

Pixelate GLSL

a guest
Jun 29th, 2015
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. [HEADER]
  2.     VERSION     01.00.00.00
  3.     DESCRIPTION Post-processing examples
  4.     COPYRIGHT   2013-2014, The Brenwill Workshop Ltd. All rights reserved.
  5. [/HEADER]
  6.  
  7. // Using a texture attached to a rendering surface
  8. [TEXTURES]
  9. [/TEXTURES]
  10.  
  11. ///////////////////////////////////////////////
  12. // In post-processing, draw a single texture in clip-space.
  13. // after converting the texture to grayscale.
  14. ///////////////////////////////////////////////
  15. [EFFECT]
  16.     NAME            Grayscale
  17.  
  18.     VERTEXSHADER    ClipSpace_vsh
  19.     FRAGMENTSHADER  Grayscale_fsh
  20. [/EFFECT]
  21.  
  22. ///////////////////////////////////////////////
  23. // Draws a single texture in clip-space.
  24. // In clip-space, we need no transform matrices, because all locations
  25. // are taken to be between +/-1.0 in all three dimensions.
  26. ///////////////////////////////////////////////
  27. [VERTEXSHADER]
  28.     NAME        ClipSpace_vsh
  29.     FILE        CC3ClipSpaceTexturable.vsh
  30. [/VERTEXSHADER]
  31.  
  32. ///////////////////////////////////////////////
  33. // Draws a single texture as grayscale.
  34. // Grayscale rendering is processed via the ITU-R BT.709 conversion used for
  35. // high-definition television (HDTV) signals. The alpha component is unchanged.
  36. ///////////////////////////////////////////////
  37. [FRAGMENTSHADER]
  38.     NAME        Grayscale_fsh
  39.  
  40.     [GLSL_CODE]
  41.        
  42.         uniform sampler2D s_cc3Texture; // 0
  43.         uniform float vx_offset;
  44.         uniform float rt_w; // GeeXLab built-in
  45.         uniform float rt_h; // GeeXLab built-in
  46.         uniform float pixel_w; // 15.0
  47.         uniform float pixel_h; // 10.0
  48.         void main()
  49.         {
  50.             vec2 uv = gl_TexCoord[0].xy;
  51.  
  52.             vec3 tc = vec3(1.0, 0.0, 0.0);
  53.             if (uv.x < (vx_offset-0.005))
  54.              {
  55.                     float dx = pixel_w*(1./rt_w);
  56.                     float dy = pixel_h*(1./rt_h);
  57.                     vec2 coord = vec2(dx*floor(uv.x/dx), dy*floor(uv.y/dy));
  58.                     tc = texture2D(sceneTex, coord).rgb;
  59.              }
  60.             else if (uv.x>=(vx_offset+0.005))
  61.             {
  62.                     tc = texture2D(s_cc3Texture, uv).rgb;
  63.             }
  64.             gl_FragColor = vec4(tc, 1.0);
  65.     }
  66.  
  67.     [/GLSL_CODE]
  68. [/FRAGMENTSHADER]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement