Advertisement
Guest User

ntsc-test2.shader

a guest
May 15th, 2011
4,960
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
XML 5.87 KB | None | 0 0
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <shader language="GLSL">
  3.    <fragment filter="nearest" size_x="256"><![CDATA[#version 120
  4.  
  5.      uniform sampler2D     rubyTexture;
  6.      uniform vec2          rubyTextureSize;
  7.      uniform vec2          rubyInputSize;
  8.      uniform int rubyFrameCount;
  9.  
  10.      #define TEX2D(c) texture2D(rubyTexture,(c))
  11.  
  12.      #define PI 3.14159265
  13.  
  14.      void main()
  15.      {
  16.        vec2 xy = gl_TexCoord[0].st;
  17.  
  18.        vec2 xyp = xy * rubyTextureSize * 4.0 * PI / 3.0;
  19.        xyp.y = xyp.y / 2.0 + 2.0 * PI / 3.0 * mod(rubyFrameCount,2);
  20.  
  21.        vec4 rgb = TEX2D(xy);
  22.  
  23.        mat3x3 rgb2yuv = mat3x3(0.299,-0.14713, 0.615,
  24.                 0.587,-0.28886,-0.51499,
  25.                 0.114, 0.436  ,-0.10001);
  26.  
  27.        vec3 yuv;
  28.        yuv = rgb2yuv * rgb.rgb;
  29.  
  30.        float dx = PI/3.0;
  31.        xyp.x = xyp.x * rubyInputSize.x/256.0;
  32.        float c0 = yuv.x + yuv.y * sin(xyp.x+xyp.y) + yuv.z*cos(xyp.x+xyp.y);
  33.        float c1 = yuv.x + yuv.y * sin(xyp.x+xyp.y+dx) + yuv.z * cos(xyp.x+xyp.y+dx);
  34.        rgb = TEX2D(xy + vec2(1.0/rubyTextureSize.x * rubyInputSize.x / 512.0, 0.0));
  35.        yuv = rgb2yuv * rgb.rgb;
  36.        float c2 = yuv.x + yuv.y * sin(xyp.x+xyp.y+2.0*dx) + yuv.z * cos(xyp.x+xyp.y+2.0*dx);
  37.        float c3 = yuv.x + yuv.y * sin(xyp.x+xyp.y+3.0*dx) + yuv.z * cos(xyp.x+xyp.y+3.0*dx);
  38.  
  39.        gl_FragColor = (vec4(c0,c1,c2,c3)+0.65)/2.3;
  40.      }
  41.   ]]></fragment>
  42.  
  43.    <fragment filter="nearest" size_x="1024" scale_y="4.0"><![CDATA[#version 120
  44.  
  45.      uniform sampler2D     rubyTexture;
  46.      uniform vec2          rubyTextureSize;
  47.      uniform vec2          rubyOutputSize;
  48.      uniform int rubyFrameCount;
  49.  
  50.      #define TEX2D(c) texture2D(rubyTexture,(c))
  51.  
  52.      #define PI 3.14159265
  53.  
  54.      void main()
  55.      {
  56.        vec2 xy = gl_TexCoord[0].st;
  57.  
  58.        vec2 xyf = fract(xy * rubyTextureSize);
  59.        vec2 xyp = floor(xy * rubyTextureSize)+vec2(0.5);
  60.        xy = xyp / rubyTextureSize;
  61.        xyp.y = -xyp.y-1.0; // fix for inconsistent texture coordinates
  62.        float offs = mod(rubyFrameCount,2)/2.0;
  63.        vec4 phases = (vec4(0.0,0.25,0.5,0.75) + vec4(xyp.x+xyp.y/2.0+offs)) *4.0*PI/3.0;
  64.        vec4 phasesl = (vec4(0.0,0.25,0.5,0.75) + vec4(-1.0+xyp.x+xyp.y/2.0+offs)) *4.0*PI/3.0;
  65.        vec4 phasesr = (vec4(0.0,0.25,0.5,0.75) + vec4( 1.0+xyp.x+xyp.y/2.0+offs)) *4.0*PI/3.0;
  66.        vec4 phsin = sin(phases);
  67.        vec4 phcos = cos(phases);
  68.        vec4 phsinl= sin(phasesl);
  69.        vec4 phcosl= cos(phasesl);
  70.        vec4 phsinr= sin(phasesr);
  71.        vec4 phcosr= cos(phasesr);
  72.        vec4 phone = vec4(1.0);
  73.  
  74.        vec2 one = 1.0/rubyTextureSize;
  75.  
  76.        vec4 c = TEX2D(xy)*2.3-0.65;
  77.        vec4 cl= TEX2D(xy + vec2(-one.x,0.0))*2.3-0.65;
  78.        vec4 cr= TEX2D(xy + vec2( one.x,0.0))*2.3-0.65;
  79.  
  80.        vec3 yuva = vec3((dot(cl.zw,phone.zw)+dot(c.xyz,phone.xyz)+0.5*(cl.y+c.w))/6.0, (dot(cl.zw,phsinl.zw)+dot(c.xyz,phsin.xyz)+0.5*(cl.y*phsinl.y+c.w*phsin.w))/3.0, (dot(cl.zw,phcosl.zw)+dot(c.xyz,phcos.xyz)+0.5*(cl.y*phcosl.y+c.w*phcos.w))/3.0);
  81.  
  82.        vec3 yuvb = vec3((cl.w*phone.w+dot(c.xyzw,phone.xyzw)+0.5*(cl.z+cr.x))/6.0, (cl.w*phsinl.w+dot(c.xyzw,phsin.xyzw)+0.5*(cl.z*phsinl.z+cr.x*phsinr.x))/3.0, (cl.w*phcosl.w+dot(c.xyzw,phcos.xyzw)+0.5*(cl.z*phcosl.z+cr.x*phcosr.x))/3.0);
  83.  
  84.        vec3 yuvc = vec3((cr.x*phone.x+dot(c.xyzw,phone.xyzw)+0.5*(cl.w+cr.y))/6.0, (cr.x*phsinr.x+dot(c.xyzw,phsin.xyzw)+0.5*(cl.w*phsinl.w+cr.y*phsinr.y))/3.0, (cr.x*phcosr.x+dot(c.xyzw,phcos.xyzw)+0.5*(cl.w*phcosl.w+cr.y*phcosr.y))/3.0);
  85.  
  86.        vec3 yuvd = vec3((dot(cr.xy,phone.xy)+dot(c.yzw,phone.yzw)+0.5*(c.x+cr.z))/6.0, (dot(cr.xy,phsinr.xy)+dot(c.yzw,phsin.yzw)+0.5*(c.x*phsin.x+cr.z*phsinr.z))/3.0, (dot(cr.xy,phcosr.xy)+dot(c.yzw,phcos.yzw)+0.5*(c.x*phcos.x+cr.z*phcosr.z))/3.0);
  87.  
  88.        mat3x3 yuv2rgb = mat3x3(1.0, 1.0, 1.0,
  89.                 0.0,-0.39465,2.03211,
  90.                 1.13983,-0.58060,0.0);
  91.  
  92.  
  93.        if (xyf.x < 0.25)
  94.          gl_FragColor = vec4(yuv2rgb*yuva, 0.0);
  95.        else if (xyf.x < 0.5)
  96.          gl_FragColor = vec4(yuv2rgb*yuvb, 0.0);
  97.        else if (xyf.x < 0.75)
  98.          gl_FragColor = vec4(yuv2rgb*yuvc, 0.0);
  99.        else
  100.          gl_FragColor = vec4(yuv2rgb*yuvd, 0.0);
  101.      }
  102.   ]]></fragment>
  103.    
  104.    <fragment filter="nearest" scale="1.0"><![CDATA[#version 120
  105.  
  106.      uniform sampler2D rubyTexture;
  107.      uniform vec2      rubyInputSize;
  108.      uniform vec2      rubyTextureSize;
  109.      uniform vec2      rubyOutputSize;
  110.  
  111.      #define TEX2D(v) texture2D(rubyTexture, (v))
  112.  
  113.      void main()
  114.      {
  115.        mat3x3 rgb2yuv = mat3x3(0.299,-0.14713, 0.615,
  116.                 0.587,-0.28886,-0.51499,
  117.                 0.114, 0.436  ,-0.10001);
  118.        mat3x3 yuv2rgb = mat3x3(1.0, 1.0, 1.0,
  119.                 0.0,-0.39465,2.03211,
  120.                 1.13983,-0.58060,0.0);
  121.  
  122.  
  123.        vec4 sum   = vec4(0.0);
  124.  
  125.        float wid = 3.0;
  126.        vec4 c1 = vec4(exp(-1.0/wid/wid));
  127.        vec4 c2 = vec4(exp(-4.0/wid/wid));
  128.        vec4 c3 = vec4(exp(-9.0/wid/wid));
  129.        vec4 c4 = vec4(exp(-16.0/wid/wid));
  130.        vec4 norm = 1.0 / (vec4(1.0) + vec4(2.0)*(c1+c2+c3+c4));
  131.  
  132.        vec2 xy = gl_TexCoord[0].st;
  133.        float onex = 1.0 / rubyTextureSize.x;
  134.  
  135.        sum += TEX2D(xy + vec2(-4.0 * onex,  0.0)) * c4;
  136.        sum += TEX2D(xy + vec2(-3.0 * onex,  0.0)) * c3;
  137.        sum += TEX2D(xy + vec2(-2.0 * onex,  0.0)) * c2;
  138.        sum += TEX2D(xy + vec2(-1.0 * onex,  0.0)) * c1;
  139.        sum += TEX2D(xy);
  140.        sum += TEX2D(xy + vec2(+1.0 * onex,  0.0)) * c1;
  141.        sum += TEX2D(xy + vec2(+2.0 * onex,  0.0)) * c2;
  142.        sum += TEX2D(xy + vec2(+3.0 * onex,  0.0)) * c3;
  143.        sum += TEX2D(xy + vec2(+4.0 * onex,  0.0)) * c4;
  144.  
  145.        float y = (rgb2yuv * TEX2D(xy).rgb).x;
  146.        vec2 uv = (rgb2yuv * (sum.rgb*norm.rgb)).yz;
  147.  
  148.        gl_FragColor = vec4(yuv2rgb * vec3(y, uv), 0.0);
  149.      }
  150.   ]]></fragment>
  151. </shader>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement