SHARE
TWEET

PhosphorLUT-Standard-Brightness

a guest Mar 22nd, 2013 166 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 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="240pvert.png" filter="linear"/>
  12.  
  13.    <vertex><![CDATA[
  14.       void main()
  15.       {
  16.          gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  17.          gl_TexCoord[0].xy = gl_MultiTexCoord0.xy;
  18.          gl_TexCoord[1].xy = gl_MultiTexCoord1.xy;
  19.       }
  20.    ]]></vertex>
  21.    <fragment filter="linear" outscale="2.0"><![CDATA[
  22.       uniform sampler2D rubyTexture;
  23.       uniform sampler2D phosphorLUT;
  24.  
  25.       void main()
  26.       {
  27.          vec4 frame = texture2D(rubyTexture, gl_TexCoord[0].xy);
  28.        vec4 inverse = 1 - texture2D(rubyTexture, gl_TexCoord[0].xy);
  29.          vec4 screen = texture2D(phosphorLUT, gl_TexCoord[1].xy);
  30.      
  31.          gl_FragColor = screen - inverse;
  32.       }
  33.    ]]></fragment>
  34.    <fragment filter="linear" outscale="1.0"><![CDATA[
  35. uniform sampler2D     rubyTexture;
  36. uniform vec2 rubyTextureSize;
  37. uniform vec2 rubyInputSize;
  38. uniform vec2 rubyOutputSize;
  39.  
  40. #define CRTgamma 2.5
  41. #define display_gamma 2.0
  42. #define TEX2D(c) pow(texture2D(rubyTexture,(c)),vec4(CRTgamma))
  43.  
  44. void main()
  45. {
  46.   vec2 xy = gl_TexCoord[0].st;
  47.   float oney = 1.0/rubyTextureSize.y;
  48.  
  49.   float wid = 2.0;
  50.  
  51.   float c1 = exp(-1.0/wid/wid);
  52.   float c2 = exp(-4.0/wid/wid);
  53.   float c3 = exp(-9.0/wid/wid);
  54.   float c4 = exp(-16.0/wid/wid);
  55.   float norm = 1.0 / (1.0 + 2.0*(c1+c2+c3+c4));
  56.  
  57.   vec4 sum = vec4(0.0);
  58.  
  59.   sum += TEX2D(xy + vec2(0.0, -4.0 * oney)) * vec4(c4);
  60.   sum += TEX2D(xy + vec2(0.0, -3.0 * oney)) * vec4(c3);
  61.   sum += TEX2D(xy + vec2(0.0, -2.0 * oney)) * vec4(c2);
  62.   sum += TEX2D(xy + vec2(0.0, -1.0 * oney)) * vec4(c1);
  63.   sum += TEX2D(xy);
  64.   sum += TEX2D(xy + vec2(0.0, +1.0 * oney)) * vec4(c1);
  65.   sum += TEX2D(xy + vec2(0.0, +2.0 * oney)) * vec4(c2);
  66.   sum += TEX2D(xy + vec2(0.0, +3.0 * oney)) * vec4(c3);
  67.   sum += TEX2D(xy + vec2(0.0, +4.0 * oney)) * vec4(c4);
  68.  
  69.   gl_FragColor = pow(sum*vec4(norm),vec4(1.0/display_gamma));
  70. }
  71. ]]></fragment>
  72.    <fragment filter="linear" outscale="1.0"><![CDATA[
  73. uniform sampler2D     rubyTexture;
  74. uniform vec2 rubyTextureSize;
  75. uniform vec2 rubyInputSize;
  76. uniform vec2 rubyOutputSize;
  77.  
  78. #define CRTgamma 2.5
  79. #define display_gamma 2.0
  80. #define TEX2D(c) pow(texture2D(rubyTexture,(c)),vec4(CRTgamma))
  81.  
  82. void main()
  83. {
  84.   vec2 xy = gl_TexCoord[0].st;
  85.   float oney = 1.0/rubyTextureSize.y;
  86.  
  87.   float wid = 6.0;
  88.  
  89.   float c1 = exp(-1.0/wid/wid);
  90.   float c2 = exp(-4.0/wid/wid);
  91.   float c3 = exp(-9.0/wid/wid);
  92.   float c4 = exp(-16.0/wid/wid);
  93.   float norm = 1.0 / (1.0 + 2.0*(c1+c2+c3+c4));
  94.  
  95.   vec4 sum = vec4(0.0);
  96.  
  97.   sum += TEX2D(xy + vec2(0.0, -4.0 * oney)) * vec4(c4);
  98.   sum += TEX2D(xy + vec2(0.0, -3.0 * oney)) * vec4(c3);
  99.   sum += TEX2D(xy + vec2(0.0, -2.0 * oney)) * vec4(c2);
  100.   sum += TEX2D(xy + vec2(0.0, -1.0 * oney)) * vec4(c1);
  101.   sum += TEX2D(xy);
  102.   sum += TEX2D(xy + vec2(0.0, +1.0 * oney)) * vec4(c1);
  103.   sum += TEX2D(xy + vec2(0.0, +2.0 * oney)) * vec4(c2);
  104.   sum += TEX2D(xy + vec2(0.0, +3.0 * oney)) * vec4(c3);
  105.   sum += TEX2D(xy + vec2(0.0, +4.0 * oney)) * vec4(c4);
  106.  
  107.   gl_FragColor = pow(sum*vec4(norm),vec4(1.0/display_gamma));
  108. }
  109. ]]></fragment>
  110.  
  111.    <vertex><![CDATA[
  112. attribute vec2 rubyOrigTexCoord;
  113. varying vec2 orig_tex;
  114.  
  115.       void main()
  116.       {
  117.          gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  118.          orig_tex = rubyOrigTexCoord;
  119.          gl_TexCoord[1].xy = gl_MultiTexCoord1.xy;
  120.       }
  121.    ]]></vertex>
  122.    <fragment filter="linear" outscale="1.0"><![CDATA[
  123.       uniform sampler2D rubyOrigTexture;
  124.       uniform sampler2D phosphorLUT;
  125.      varying vec2 orig_tex;
  126.          uniform float brightness;
  127.  
  128.       void main()
  129.       {
  130.       float brightness = 1.2;
  131.          vec4 frame = texture2D(rubyOrigTexture, orig_tex);
  132.        vec4 inverse = 1 - (brightness * texture2D(rubyOrigTexture, orig_tex));
  133.          vec4 screen = texture2D(phosphorLUT, gl_TexCoord[1].xy);
  134.      
  135.          gl_FragColor = screen - inverse;
  136.       }
  137.    ]]></fragment>
  138.    
  139.    <vertex><![CDATA[
  140.     attribute vec2 rubyPass1TexCoord;
  141.     attribute vec2 rubyPass2TexCoord;
  142.     varying vec2 pass1_tex;
  143.     varying vec2 pass2_tex;
  144.  
  145.     void main() {
  146.        gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  147.        gl_TexCoord[0] = gl_MultiTexCoord0;
  148.        pass1_tex = rubyPass1TexCoord;
  149.        pass2_tex = rubyPass2TexCoord;
  150.     }
  151.   ]]></vertex>
  152.     <fragment filter="linear"><![CDATA[
  153.     uniform sampler2D rubyPass1Texture; // Result from Pass 1.
  154.      uniform sampler2D rubyPass2Texture; // Result from Pass 2.
  155.      uniform sampler2D rubyTexture; // Result from Pass 3 (previous pass).
  156.      varying vec2 pass1_tex;
  157.      varying vec2 pass2_tex;
  158.    
  159. //    #define LOWRES
  160.  
  161.      void main() {
  162.         vec4 pass1 = texture2D(rubyPass1Texture, pass1_tex);
  163.         vec4 pass2 = texture2D(rubyPass2Texture, pass2_tex);
  164.       vec4 pass3 = texture2D(rubyTexture, gl_TexCoord[0].xy);
  165.    #ifdef LOWRES
  166.       gl_FragColor = 1.0 - (1.0 - pass1) * (1.0 - pass2) * (1.0 - pass2) * (1.0- pass2);
  167.    #else
  168.       gl_FragColor = 1.0 - (1.0 - pass1) * (1.0 - pass2) * (1.0 - pass3);
  169.    #endif
  170.      }
  171.   ]]></fragment>
  172.    </shader>
RAW Paste Data
Top