My favorites | Sign in
Logo
                
Changes to /trunk/lab/effects/shaders/plane_deformations/deploy/shaders/tunnel.pbk
r0 vs. r170   Edit
  Compare: vs.   Format:
Revision r170
Go to: 
Project members, sign in to write a code review
/trunk/lab/effects/shaders/plane_deformations/deploy/shaders/tunnel.pbk /trunk/lab/effects/shaders/plane_deformations/deploy/shaders/tunnel.pbk   r170
  1 <languageVersion : 1.0;>
  2
  3 kernel NewFilter
  4 < namespace : "Tunnel";
  5 vendor : "Mr.doob";
  6 version : 1;
  7 description : "Tunnel effect";
  8 >
  9 {
  10 input image4 src;
  11 output pixel4 dst;
  12
  13 parameter float2 imgSize
  14 <
  15 defaultValue : float2(512.0, 512.0);
  16 minValue : float2(0.0,0.0);
  17 maxValue : float2(512.0,512.0);
  18 >;
  19
  20 parameter float2 center
  21 <
  22 defaultValue : float2(256.0, 256.0);
  23 minValue : float2(0.0,0.0);
  24 maxValue : float2(512.0,512.0);
  25 >;
  26
  27 parameter float2 offset;
  28
  29 void evaluatePixel()
  30 {
  31 float2 pos = (outCoord() - center) / imgSize;
  32
  33 float pi = 3.141592653589793;
  34 float a = atan(pos.y,pos.x);
  35 float r = sqrt(pow(pos.x,2.0)+pow(pos.y,2.0));
  36
  37 float u = 0.0;
  38 float v = 0.0;
  39 float w = 0.0;
  40
  41 u += offset.x;
  42 v += offset.y;
  43
  44 u += 1.0/r;
  45 v += 3.0*a/pi;
  46 w += r*2.0;
  47
  48 u *= imgSize.x;
  49 v *= imgSize.y;
  50
  51 if (u < 0.0) u += imgSize.x * ceil(-u / imgSize.x);
  52 if (v < 0.0) v += imgSize.y * ceil(-v / imgSize.y);
  53 if (u > imgSize.x) u -= imgSize.x * floor(u / imgSize.x);
  54 if (v > imgSize.y) v -= imgSize.y * floor(v / imgSize.y);
  55
  56 dst = sampleNearest(src,float2(u, v));
  57 dst.rgb *= w;
  58 }
  59 }
Hosted by Google Code