SHARE
TWEET

Untitled

a guest Sep 13th, 2017 78 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.    
  11. // To see how the render is made, uncomment this
  12. // only 1/3 of the input pixel will be displayed for 1/3 of the lines
  13. //  #define SHOW_HOW_ITS_DONE   3.0
  14.    
  15. // To change the size of the spots  2.0 to 5.0 seems good
  16.     #define SPOT_SIZE   3.0
  17. // To change the shape of the spots 1 = circle, 0.25 = ellipse with width = 2*height
  18.     #define X_SIZE_ADJUST   0.4
  19. // To increase bloom / luminosity play with this parameter
  20.     #define FACTOR_ADJUST 1.5
  21.    
  22.     float factor( float lumi, vec2 dxy)
  23.     {  
  24.         float dist = sqrt( X_SIZE_ADJUST * dxy.x * dxy.x + dxy.y * dxy.y  );
  25.         return (2.0 + lumi ) * (1.0 - smoothstep( 0.0, SPOT_SIZE, dist ) ) / FACTOR_ADJUST ;
  26.     }
  27.    
  28.     vec2 ar_correction = vec2(  rubyOutputSize.x/rubyOutputSize.y * rubyInputSize.y/rubyInputSize.x,1.0 );
  29.     vec2 arInputSize = rubyInputSize * ar_correction;
  30.     vec2 arTextureSize = rubyTextureSize * ar_correction;
  31.    
  32.     vec4 luminosity_weights = vec4( 0.6, 0.3, 0.1, 0.0 );
  33.    
  34.     vec4 get_color( vec2 pos )
  35.     {
  36.         vec2 texture_coords = ( pos + vec2(0.5) ) / arTextureSize;
  37.         vec4 color = texture2D(rubyTexture, texture_coords );
  38.  
  39. #ifdef SHOW_HOW_ITS_DONE
  40.         if ( mod(pos.x, SHOW_HOW_ITS_DONE ) != 0.0 )
  41.             color.rgb = vec3(0.0);
  42.         if ( mod(pos.y, SHOW_HOW_ITS_DONE ) != 0.0 )
  43.             color.rgb = vec3(0.0);
  44. #endif
  45.         return color;
  46.     }
  47.  
  48.     void main(void) {
  49.         vec2 coords_5x = floor( gl_TexCoord[0].xy * arTextureSize * 5.0 );
  50.         vec2 coords_snes = floor( gl_TexCoord[0].xy * arTextureSize );
  51.                
  52.         vec2 ecart = coords_5x - ( vec2(5.0) * coords_snes + vec2(2.0) );
  53.        
  54.         vec4 color = vec4(0.0,0.0,0.0,1.0);
  55.        
  56.         float i,j;
  57.         float n = 1.0;
  58.        
  59.         // If SPOT_SIZE is small enough, j=0 might be enough...
  60.         // If SPOT_SIZE is too big, n = 2.0 or even 3.0 may be necessary... But not very realistic
  61.         for( i = -n; i <= n; i+=1.0 )
  62.         {
  63.             for( j = -n; j <= n; j+=1.0 )
  64.             {
  65.                 vec4 pcol = get_color( coords_snes + vec2(i,j) );
  66.                 float luminosity = dot( pcol, luminosity_weights );
  67.            
  68.                 vec2 dxy = ecart - vec2( 5.0*i, 5.0*j );
  69.            
  70.                 float distance = sqrt( dot(dxy, dxy) );
  71. #ifdef SHOW_HOW_ITS_DONE           
  72.                 color += pcol * factor( luminosity, dxy ) ;
  73. #else
  74.                 color += pcol * factor( luminosity, dxy ) ;
  75. #endif
  76.             }
  77.         }
  78.        
  79.  
  80. #ifdef TRIAD1
  81.         vec2 coords_screen = floor( gl_TexCoord[0].xy * rubyOutputSize );
  82.  
  83.         float modulo = mod( coords_screen.y + coords_screen.x , 3.0 );         
  84.         if ( modulo == 0.0 )
  85.             color.rgb *= vec3(1.0,0.5,0.5);
  86.         else if  ( modulo <= 1.0 )
  87.             color.rgb *= vec3(0.5,1.0,0.5);
  88.         else
  89.             color.rgb *= vec3(0.5,0.5,1.0);
  90. #endif
  91.  
  92.         gl_FragColor = clamp( color, 0.0, 1.0 );
  93.     }
  94.   ]]></fragment>
  95. </shader>
RAW Paste Data
Top