SHARE
TWEET

PhosphorLUT-Scanlines-Brightness

a guest Mar 22nd, 2013 194 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-scanlines v1.0
  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.     You can also uncomment line 157 if you're using this shader on a low-resolution display (i.e., 1080p or below) to fix the colors a bit.
  7.     Author: hunterk
  8.      License: GPL (contains code from other GPL shaders).
  9. -->
  10. <shader language="GLSL">
  11.    <texture id="phosphorLUT" file="aperture2.png" filter="linear"/>
  12.  
  13.    <vertex><![CDATA[
  14.         uniform vec2 rubyTextureSize;
  15.      uniform vec2 rubyInputSize;
  16.      uniform vec2 rubyOutputSize;
  17.  
  18.      varying vec2 omega;
  19.       void main()
  20.       {
  21.          gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  22.          gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
  23.          gl_TexCoord[1].xy = gl_MultiTexCoord1.xy;
  24.              omega = vec2(3.1415 * rubyOutputSize.x * rubyTextureSize.x / rubyInputSize.x, 2.0 * 3.1415 * rubyTextureSize.y);
  25.       }
  26.    ]]></vertex>
  27.    <fragment filter="linear" outscale="2.0"><![CDATA[
  28.       uniform sampler2D rubyTexture;
  29.       uniform sampler2D phosphorLUT;
  30.      uniform vec2 rubyTextureSize;
  31.      uniform vec2 rubyInputSize;
  32.      uniform vec2 rubyOutputSize;
  33.  
  34.      varying vec2 omega;
  35.  
  36.      const float base_brightness = 0.95;
  37.      const vec2 sine_comp = vec2(0.05, 0.85);
  38.  
  39.       void main()
  40.       {
  41.          vec4 frame = texture2D(rubyTexture, gl_TexCoord[0].xy);
  42.        vec4 inverse = 1 - texture2D(rubyTexture, gl_TexCoord[0].xy);
  43.          vec4 screen = texture2D(phosphorLUT, gl_TexCoord[1].xy);
  44.          vec4 final = screen - inverse;
  45.          
  46.              vec4 scanline = final * (base_brightness + dot(sine_comp * sin(gl_TexCoord[0].xy * omega), vec2(1.0)));
  47.     gl_FragColor = clamp(scanline, 0.0, 1.0);
  48.        
  49.          //gl_FragColor = screen - inverse;
  50.       }
  51.    ]]></fragment>
  52.    <fragment filter="linear" outscale="1.0"><![CDATA[
  53. uniform sampler2D     rubyTexture;
  54. uniform vec2 rubyTextureSize;
  55. uniform vec2 rubyInputSize;
  56. uniform vec2 rubyOutputSize;
  57.  
  58. #define CRTgamma 2.5
  59. #define display_gamma 2.0
  60. #define TEX2D(c) pow(texture2D(rubyTexture,(c)),vec4(CRTgamma))
  61.  
  62. void main()
  63. {
  64.   vec2 xy = gl_TexCoord[0].st;
  65.   float oney = 1.0/rubyTextureSize.y;
  66.  
  67.   float wid = 2.0;
  68.  
  69.   float c1 = exp(-1.0/wid/wid);
  70.   float c2 = exp(-4.0/wid/wid);
  71.   float c3 = exp(-9.0/wid/wid);
  72.   float c4 = exp(-16.0/wid/wid);
  73.   float norm = 1.0 / (1.0 + 2.0*(c1+c2+c3+c4));
  74.  
  75.   vec4 sum = vec4(0.0);
  76.  
  77.   sum += TEX2D(xy + vec2(0.0, -4.0 * oney)) * vec4(c4);
  78.   sum += TEX2D(xy + vec2(0.0, -3.0 * oney)) * vec4(c3);
  79.   sum += TEX2D(xy + vec2(0.0, -2.0 * oney)) * vec4(c2);
  80.   sum += TEX2D(xy + vec2(0.0, -1.0 * oney)) * vec4(c1);
  81.   sum += TEX2D(xy);
  82.   sum += TEX2D(xy + vec2(0.0, +1.0 * oney)) * vec4(c1);
  83.   sum += TEX2D(xy + vec2(0.0, +2.0 * oney)) * vec4(c2);
  84.   sum += TEX2D(xy + vec2(0.0, +3.0 * oney)) * vec4(c3);
  85.   sum += TEX2D(xy + vec2(0.0, +4.0 * oney)) * vec4(c4);
  86.  
  87.   gl_FragColor = pow(sum*vec4(norm),vec4(1.0/display_gamma));
  88. }
  89. ]]></fragment>
  90.    <fragment filter="linear" outscale="1.0"><![CDATA[
  91. uniform sampler2D     rubyTexture;
  92. uniform vec2 rubyTextureSize;
  93. uniform vec2 rubyInputSize;
  94. uniform vec2 rubyOutputSize;
  95.  
  96. #define CRTgamma 2.5
  97. #define display_gamma 2.0
  98. #define TEX2D(c) pow(texture2D(rubyTexture,(c)),vec4(CRTgamma))
  99.  
  100. void main()
  101. {
  102.   vec2 xy = gl_TexCoord[0].st;
  103.   float oney = 1.0/rubyTextureSize.y;
  104.  
  105.   float wid = 6.0;
  106.  
  107.   float c1 = exp(-1.0/wid/wid);
  108.   float c2 = exp(-4.0/wid/wid);
  109.   float c3 = exp(-9.0/wid/wid);
  110.   float c4 = exp(-16.0/wid/wid);
  111.   float norm = 1.0 / (1.0 + 2.0*(c1+c2+c3+c4));
  112.  
  113.   vec4 sum = vec4(0.0);
  114.  
  115.   sum += TEX2D(xy + vec2(0.0, -4.0 * oney)) * vec4(c4);
  116.   sum += TEX2D(xy + vec2(0.0, -3.0 * oney)) * vec4(c3);
  117.   sum += TEX2D(xy + vec2(0.0, -2.0 * oney)) * vec4(c2);
  118.   sum += TEX2D(xy + vec2(0.0, -1.0 * oney)) * vec4(c1);
  119.   sum += TEX2D(xy);
  120.   sum += TEX2D(xy + vec2(0.0, +1.0 * oney)) * vec4(c1);
  121.   sum += TEX2D(xy + vec2(0.0, +2.0 * oney)) * vec4(c2);
  122.   sum += TEX2D(xy + vec2(0.0, +3.0 * oney)) * vec4(c3);
  123.   sum += TEX2D(xy + vec2(0.0, +4.0 * oney)) * vec4(c4);
  124.  
  125.   gl_FragColor = pow(sum*vec4(norm),vec4(1.0/display_gamma));
  126. }
  127. ]]></fragment>
  128.  
  129.    <vertex><![CDATA[
  130. attribute vec2 rubyOrigTexCoord;
  131. varying vec2 orig_tex;
  132.  
  133.       void main()
  134.       {
  135.          gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  136.          orig_tex = rubyOrigTexCoord;
  137.          gl_TexCoord[1].xy = gl_MultiTexCoord1.xy;
  138.       }
  139.    ]]></vertex>
  140.    <fragment filter="linear" outscale="1.0"><![CDATA[
  141.       uniform sampler2D rubyOrigTexture;
  142.       uniform sampler2D phosphorLUT;
  143.      varying vec2 orig_tex;
  144.      uniform float brightness;
  145.  
  146.       void main()
  147.       {
  148.       float brightness = 1.2;
  149.          vec4 frame = texture2D(rubyOrigTexture, orig_tex);
  150.        vec4 inverse = 1 - (brightness * texture2D(rubyOrigTexture, orig_tex));
  151.          vec4 screen = texture2D(phosphorLUT, gl_TexCoord[1].xy);
  152.        
  153.          gl_FragColor = screen - inverse;
  154.       }
  155.    ]]></fragment>
  156.    
  157.    <vertex><![CDATA[
  158.     attribute vec2 rubyPass1TexCoord;
  159.     attribute vec2 rubyPass2TexCoord;
  160.     varying vec2 pass1_tex;
  161.     varying vec2 pass2_tex;
  162.  
  163.     void main() {
  164.        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  165.        gl_TexCoord[0] = gl_MultiTexCoord0;
  166.        pass1_tex = rubyPass1TexCoord;
  167.        pass2_tex = rubyPass2TexCoord;
  168.     }
  169.   ]]></vertex>
  170.     <fragment filter="linear"><![CDATA[
  171.     uniform sampler2D rubyPass1Texture; // Result from Pass 1.
  172.      uniform sampler2D rubyPass2Texture; // Result from Pass 2.
  173.      uniform sampler2D rubyTexture; // Result from Pass 3 (previous pass).
  174.      varying vec2 pass1_tex;
  175.      varying vec2 pass2_tex;
  176.    
  177.     //#define LOWRES
  178.  
  179.      void main() {
  180.         vec4 pass1 = texture2D(rubyPass1Texture, pass1_tex);
  181.         vec4 pass2 = texture2D(rubyPass2Texture, pass2_tex);
  182.       vec4 pass3 = texture2D(rubyTexture, gl_TexCoord[0].xy);
  183.    #ifdef LOWRES
  184.       gl_FragColor = 1.0 - (1.0 - pass1) * (1.0 - pass2) * (1.0 - pass2) * (1.0 - pass2);
  185.    #else
  186.       gl_FragColor = 1.0 - (1.0 - pass1) * (1.0 - pass2) * (1.0 - pass3);
  187.    #endif
  188.      }
  189.   ]]></fragment>
  190.    </shader>
RAW Paste Data
Top