Advertisement
Guest User

Untitled

a guest
May 30th, 2011
531
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <shader language="GLSL">
  3.   <fragment><![CDATA[
  4.     uniform sampler2D rubyTexture;
  5.     uniform vec2 rubyInputSize;
  6.     uniform vec2 rubyTextureSize;
  7.     uniform vec2 rubyOutputSize;
  8.  
  9. //  #define TRIAD1
  10. // #define TRIAD2  
  11. // #define distortion 0.15
  12.  
  13. // Uncomment to use neighbours from previous and next scanlines
  14. //  #define USE_ALL_NEIGHBOURS
  15.  
  16.     // 0.5 = same width as original pixel   1.0-1.2 seems nice
  17.     #define SPOT_WIDTH  1.2
  18.     // Shape of the spots   1.0 = circle, 4.0 = ellipse with width = 2*height  ************/
  19.     #define X_SIZE_ADJUST   2.0
  20. /******************************** To increase bloom / luminosity play with this parameter ************/
  21.     #define FACTOR_ADJUST 2.0
  22.  
  23. #ifdef distortion
  24.     vec2 barrelDistortion(vec2 coord) {
  25.       vec2 cc = coord - 0.5;
  26.       float dist = dot(cc, cc);
  27.       return 0.5 + cc * (1.0 + (dist + distortion * dist * dist) * distortion) / (1.0 + (0.25 + distortion * 0.25 * 0.25) * distortion);
  28.     }
  29.    
  30.     #define TEXCOORDS   barrelDistortion(gl_TexCoord[0] * rubyTextureSize / rubyInputSize) * rubyInputSize / rubyTextureSize    
  31. #else
  32.     #define TEXCOORDS   gl_TexCoord[0].xy
  33. #endif
  34.  
  35.     #define SCALE   21.0
  36.     // Constants
  37.     vec4 luminosity_weights = vec4( 0.2126, 0.7152, 0.0722, 0.0 );      //  Y = 0.2126 R + 0.7152 G + 0.0722 B
  38.     //vec4 luminosity_weights = vec4( 0.6, 0.3, 0.1, 0.0 );    
  39.  
  40.     vec2 onex = vec2( 1.0 / rubyTextureSize.x, 0.0 );
  41.     #ifdef USE_ALL_NEIGHBOURS
  42.     vec2 oney = vec2( 0.0, 1.0 / rubyTextureSize.y);
  43.     #endif
  44.    
  45.     float factor( float lumi, vec2 dxy)
  46.     {  
  47.         float dist = sqrt( dxy.x * dxy.x + dxy.y * dxy.y * X_SIZE_ADJUST  ) / SCALE;
  48.         return (2.0 + lumi ) * (1.0 - smoothstep( 0.0, SPOT_WIDTH, dist ) ) / FACTOR_ADJUST ;
  49.     }
  50.        
  51.     void main(void) {          
  52.         vec2 coords_scaled = floor( TEXCOORDS * rubyTextureSize * SCALE );
  53.         vec2 coords_snes = floor( coords_scaled / SCALE );  //TEXCOORDS * rubyTextureSize ) ;
  54.         vec2 coords_texture = ( coords_snes + vec2(0.5) ) / rubyTextureSize;
  55.                
  56.         vec2 ecart = coords_scaled - ( SCALE * coords_snes + vec2( SCALE * 0.5 - 0.5 ) ) ;
  57.        
  58.         vec4 color = texture2D( rubyTexture, coords_texture );
  59.         float luminosity = dot( color, luminosity_weights );
  60.        
  61.         color *= factor( luminosity, ecart );
  62.                
  63.         // RIGHT NEIGHBOUR
  64.         vec4 pcol = texture2D( rubyTexture, coords_texture + onex);
  65.         luminosity = dot( pcol, luminosity_weights );
  66.         color += pcol * factor( luminosity, ecart + vec2( -SCALE , 0.0) );
  67.        
  68.         // LEFT NEIGHBOUR
  69.         pcol = texture2D( rubyTexture, coords_texture - onex);
  70.         luminosity = dot( pcol, luminosity_weights );
  71.         color += pcol * factor( luminosity, ecart + vec2( SCALE , 0.0) );
  72.        
  73. #ifdef USE_ALL_NEIGHBOURS
  74.         // TOP
  75.         pcol = texture2D( rubyTexture, coords_texture + oney);
  76.         luminosity = dot( pcol, luminosity_weights );
  77.         color += pcol * factor( luminosity, ecart + vec2( 0.0, -SCALE) );
  78.  
  79.         // TOP-LEFT
  80.         pcol = texture2D( rubyTexture, coords_texture + oney - onex);
  81.         luminosity = dot( pcol, luminosity_weights );
  82.         color += pcol * factor( luminosity, ecart + vec2( SCALE, -SCALE) );
  83.        
  84.         // TOP-RIGHT
  85.         pcol = texture2D( rubyTexture, coords_texture + oney + onex);
  86.         luminosity = dot( pcol, luminosity_weights );
  87.         color += pcol * factor( luminosity, ecart + vec2( -SCALE, -SCALE) );
  88.        
  89.         // BOTTOM
  90.         pcol = texture2D( rubyTexture, coords_texture - oney);
  91.         luminosity = dot( pcol, luminosity_weights );
  92.         color += pcol * factor( luminosity, ecart + vec2( 0.0, SCALE) );
  93.  
  94.         // BOTTOM-LEFT
  95.         pcol = texture2D( rubyTexture, coords_texture - oney - onex);
  96.         luminosity = dot( pcol, luminosity_weights );
  97.         color += pcol * factor( luminosity, ecart + vec2( SCALE, SCALE) );
  98.        
  99.         // BOTTOM-RIGHT
  100.         pcol = texture2D( rubyTexture, coords_texture - oney + onex);
  101.         luminosity = dot( pcol, luminosity_weights );
  102.         color += pcol * factor( luminosity, ecart + vec2( -SCALE, SCALE) );
  103. #endif
  104.  
  105. #ifdef TRIAD1
  106.         vec2 coords_screen = floor( gl_TexCoord[0].xy * rubyOutputSize );
  107.  
  108.         float modulo = mod( coords_screen.y + coords_screen.x , 3.0 );         
  109.         if ( modulo == 0.0 )
  110.             color.rgb *= vec3(1.0,0.5,0.5);
  111.         else if  ( modulo <= 1.0 )
  112.             color.rgb *= vec3(0.5,1.0,0.5);
  113.         else
  114.             color.rgb *= vec3(0.5,0.5,1.0);
  115. #endif
  116.  
  117. #ifdef TRIAD2
  118.         color = clamp( color, 0.0, 1.0 );
  119.  
  120.         vec2 coords_screen = floor( gl_TexCoord[0].xy * rubyOutputSize );
  121.  
  122.         float modulo = mod( coords_screen.x , 3.0 );           
  123.         if ( modulo == 0.0 )        color.gb *= 0.8;
  124.         else if (  modulo == 1.0 )  color.rb *= 0.8;
  125.         else                        color.rg *= 0.8;
  126. #endif
  127.  
  128.         gl_FragColor = clamp( color, 0.0, 1.0 );
  129.     }
  130.   ]]></fragment>
  131. </shader>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement