SHARE
TWEET

phosphorLUT-GTU.shader

a guest Mar 29th, 2013 230 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.      PhosphorLUT-GTU v1.1
  4.     This shader uses an external lookup texture (LUT) to create a shadow mask with individual RGB phosphor lenses.
  5.     You can swap out the LUTs by changing the 'file' referenced in Line 11.
  6.     This version uses aliaspider's GTU shader code to create the phosphor bloom, rather than 2 passes of gaussian blur.
  7.     Author: hunterk and aliaspider
  8.      License: GPL (contains code from other GPL shaders).
  9. -->
  10. <shader language="GLSL">
  11.    <texture id="phosphorLUT" file="480pvert.png" filter="linear"/>
  12.    <vertex><![CDATA[
  13.       void main()
  14.       {
  15.          gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  16.          gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
  17.          gl_TexCoord[1].xy = gl_MultiTexCoord1.xy;
  18.       }
  19.    ]]></vertex>
  20.    <fragment filter="linear" outscale="2.0"><![CDATA[
  21.       uniform sampler2D rubyTexture;
  22.       uniform sampler2D phosphorLUT;
  23.  
  24.       void main()
  25.       {
  26.          vec4 frame = texture2D(rubyTexture, gl_TexCoord[0].xy);
  27.        vec4 inverse = 1 - texture2D(rubyTexture, gl_TexCoord[0].xy);
  28.          vec4 screen = texture2D(phosphorLUT, gl_TexCoord[1].xy);
  29.        
  30.          gl_FragColor = screen - inverse;
  31.       }
  32.    ]]></fragment>
  33.   <vertex><![CDATA[
  34.  
  35.  
  36. //--------------------------------------------------------------------------//
  37. // CONFIG :
  38. // uncomment next line to zoom the picture removing
  39. // horizontal and vertical overscan
  40.  
  41. // #define CROP_OVERSCAN
  42.  
  43. // CONFIG END.
  44. //--------------------------------------------------------------------------//
  45.  
  46.  
  47.  
  48.     uniform vec2        rubyTextureSize;
  49.     uniform vec2         rubyInputSize ;
  50.     uniform vec2         rubyOutputSize;
  51.    
  52.     void main() {
  53.     vec4 pos = ftransform();
  54. #ifdef CROP_OVERSCAN
  55.       pos.w=0.94;
  56. #endif    
  57.     gl_Position=pos;
  58.     gl_TexCoord[0] = gl_MultiTexCoord0;      
  59.     }
  60.    
  61.  
  62.   ]]></vertex>
  63.  
  64.   <fragment filter="nearest"><![CDATA[
  65.  
  66.  
  67.  
  68. //--------------------------------------------------------------------------//
  69. // CONFIG :
  70.  
  71. // a dirty fix for higan-accuracy because it handles
  72. // changes in game resolution differently
  73. //
  74. // #define HIGAN_ACCURACY
  75.  
  76.  
  77.  
  78.  
  79. // select scaling Kernel
  80. // 0 - Gaussian ( default )
  81. // 1 - Spline ( almost like Gaussian with a KERNEL_WIDTH = 1.88561808316
  82. //                but without the ( barely visible) checkerboard effect.  slower)
  83. // 2 - Bilinear
  84. //
  85. #define KERNEL 0
  86.  
  87.  
  88. // for gaussian kernel only :
  89. //    define Kernel width and height ( how big an original pixel becomes)
  90. //    higher values cause more blur, might be beneficial for some games.
  91. //    lower values cause the gap between the original pixels to become visible
  92. //    reducing this value for the height only produces a scanline effect
  93. //    valid range : [ 0.5 : 4.0 ]
  94. //    default is 1.88561808316  = (4.0f*sqrt(2.0f)/3.0f)
  95. //
  96. #define KERNEL_WIDTH 1.88561808316
  97.  
  98. //    you can set a different value for the kernel height if needed
  99. //    otherwise KERNEL_WIDTH will be used for both
  100. //
  101.  //#define KERNEL_HEIGHT 1.0
  102.  
  103.  
  104. // desired gamma value for the emulated CRT-TV
  105. // default 2.2
  106. //
  107. #define GAMMA_IN 2.2
  108.  
  109. // the gamma value of the current display device
  110. // default 2.2
  111. //
  112. #define GAMMA_OUT 2.2
  113.  
  114. // CONFIG END.
  115. //--------------------------------------------------------------------------//
  116.  
  117.  
  118.     uniform sampler2D     rubyTexture;
  119.     uniform vec2          rubyTextureSize;
  120.     uniform vec2         rubyInputSize ;
  121.     uniform vec2         rubyOutputSize;
  122.    
  123.    
  124. #define pi            3.14159265358
  125. //uncommenting this line might give some speed-up on Nvidia GPUs
  126. // #pragma optionNV(unroll all)
  127. #ifndef KERNEL_HEIGHT
  128. #define KERNEL_HEIGHT KERNEL_WIDTH
  129. #endif
  130.  
  131.  
  132.  
  133. #if (KERNEL==1)
  134. #define KERNEL_X(x) ((abs(x)<0.5)?(0.75-(abs(x)*abs(x))):((abs(x)<1.5)?(0.5*(1.5-abs(x))*(1.5-abs(x))):0.0))
  135. #define KERNEL_Y(x) KERNEL_X(x)
  136. #define MIN_X -1.0
  137. #define MAX_X 3.0
  138. #define MIN_Y -1.0
  139. #define MAX_Y 3.0
  140. #elif (KERNEL==2)
  141. #define KERNEL_X(x) (min(max((1.0-abs(x)),0.0),1.0))
  142. #define KERNEL_Y(x) KERNEL_X(x)
  143. #define MIN_X -1.0
  144. #define MAX_X 2.0
  145. #define MIN_Y -1.0
  146. #define MAX_Y 2.0
  147. #else
  148. #define KERNEL_X(x) ((sqrt(2.0)/KERNEL_WIDTH)*(exp(-2.0*pi*(x)*(x)/(KERNEL_WIDTH*KERNEL_WIDTH))))
  149. #define KERNEL_Y(y) ((sqrt(2.0)/KERNEL_HEIGHT)*(exp(-2.0*pi*(y)*(y)/(KERNEL_HEIGHT*KERNEL_HEIGHT))))
  150. #define MIN_X max((floor(-KERNEL_WIDTH)+1.0),-3.0)
  151. #define MAX_X min((ceil(KERNEL_WIDTH)+1.0),5.0)
  152. #define MIN_Y max((floor(-KERNEL_HEIGHT)+1.0),-3.0)
  153. #define MAX_Y min((ceil(KERNEL_HEIGHT)+1.0),5.0)
  154. #endif
  155. #define STUDIOSWING(c) min(max((c - ( 16.0 / 255.0 ) )* ( 255.0 / 219.0 ), 0.0),1.0)
  156. #define DECODE_GAMMA(c0) pow(c0,GAMMA_IN)
  157. #define ENCODE_GAMMA(c0) pow(c0,(1.0/GAMMA_OUT))
  158.  
  159.  
  160. void main() {
  161.     vec2 oneT = 1.0 / rubyTextureSize ;
  162.     vec2 offset =(gl_TexCoord[0].xy *rubyTextureSize );
  163. #ifdef HIGAN_ACCURACY
  164.     offset.x /= 2.0;
  165.      oneT.x*=2.0;
  166. #endif
  167.     offset -= vec2(0.5,0.5);
  168.     offset-=floor(offset);
  169.     vec3 tempColor = vec3(0.0, 0.0, 0.0);
  170.     float X,Y,fX,Xcoord;
  171.     for (float i = MIN_X; i < MAX_X; i++) {
  172.         X = (offset.x - i);        
  173.         fX = KERNEL_X(X);
  174.         Xcoord = X * oneT.x;                    
  175.         for (float j = MIN_Y; j < MAX_Y; j++) {
  176.             Y = (offset.y - j);                    
  177.             vec2 sourceCoord = gl_TexCoord[0].xy - vec2(Xcoord,Y * oneT.y);                    
  178.             vec3 c=texture2D(rubyTexture, sourceCoord).xyz;
  179.             c.x=DECODE_GAMMA(STUDIOSWING(c.x));
  180.             c.y=DECODE_GAMMA(STUDIOSWING(c.y));
  181.             c.z=DECODE_GAMMA(STUDIOSWING(c.z));
  182.             tempColor += c* fX * KERNEL_Y(Y);    
  183.         }
  184.     }    
  185.        
  186.     tempColor.x=ENCODE_GAMMA(tempColor.x);
  187.     tempColor.y=ENCODE_GAMMA(tempColor.y);
  188.     tempColor.z=ENCODE_GAMMA(tempColor.z);
  189.    
  190.     gl_FragColor=vec4(tempColor,1.0);}
  191.  
  192.  
  193.     ]]></fragment>
  194.    <vertex><![CDATA[
  195. attribute vec2 rubyOrigTexCoord;
  196. varying vec2 orig_tex;
  197.  
  198.       void main()
  199.       {
  200.          gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  201.          orig_tex = rubyOrigTexCoord;
  202.          gl_TexCoord[1].xy = gl_MultiTexCoord1.xy;
  203.       }
  204.    ]]></vertex>
  205.    <fragment filter="linear" outscale="2.0"><![CDATA[
  206.       uniform sampler2D rubyOrigTexture;
  207.       uniform sampler2D phosphorLUT;
  208.      varying vec2 orig_tex;
  209.      uniform float brightness;
  210.  
  211.       void main()
  212.       {
  213.       float brightness = 1.2;
  214.          vec4 frame = texture2D(rubyOrigTexture, orig_tex);
  215.        vec4 inverse = 1 - (brightness * texture2D(rubyOrigTexture, orig_tex));
  216.          vec4 screen = texture2D(phosphorLUT, gl_TexCoord[1].xy);
  217.        
  218.          gl_FragColor = screen - inverse;
  219.       }
  220.    ]]></fragment>
  221.    
  222.    <vertex><![CDATA[
  223.     attribute vec2 rubyPass1TexCoord;
  224.     attribute vec2 rubyPass2TexCoord;
  225.     varying vec2 pass1_tex;
  226.     varying vec2 pass2_tex;
  227.  
  228.     void main() {
  229.        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  230.        gl_TexCoord[0] = gl_MultiTexCoord0;
  231.        pass1_tex = rubyPass1TexCoord;
  232.        pass2_tex = rubyPass2TexCoord;
  233.     }
  234.   ]]></vertex>
  235.     <fragment filter="linear"><![CDATA[
  236.     uniform sampler2D rubyPass1Texture; // Result from Pass 1.
  237.      uniform sampler2D rubyPass2Texture; // Result from Pass 2.
  238.      uniform sampler2D rubyTexture; // Result from Pass 3 (previous pass).
  239.      varying vec2 pass1_tex;
  240.      varying vec2 pass2_tex;
  241.    
  242.     //#define LOWRES
  243.  
  244.      void main() {
  245.         vec4 pass1 = texture2D(rubyPass1Texture, pass1_tex);
  246.         vec4 pass2 = texture2D(rubyPass2Texture, pass2_tex);
  247.       vec4 pass3 = texture2D(rubyTexture, gl_TexCoord[0].xy);
  248.    #ifdef LOWRES
  249.       gl_FragColor = 1.0 - (1.0 - pass1) * (1.0 - pass2) * (1.0 - pass3) * (1.0- pass2);
  250.    #else
  251.       gl_FragColor = 1.0 - (1.0 - pass1) * (1.0 - pass2) * (1.0 - pass3);
  252.    #endif
  253.      }
  254.   ]]></fragment>
  255.    </shader>
RAW Paste Data
Top