v 0. Pasted by NULL_PTR as cpp at 2008-06-17 01:47:49 MSK and set expiration to never.

Paste will expire never.

  1. sampler2D baseMap;
  2.  
  3. float4 main(float2 tc : TEXCOORD0) : COLOR0
  4. {
  5.    float2 size = float2(512, 512);
  6.    float2 isize = 1.0 / size;
  7.    
  8.    //We need this to correctly address all eight texels
  9.    float2 ssize = frac(tc * size);
  10.    tc -= ssize*isize;
  11.    tc.x *= 8.0;
  12.    
  13.    ssize *= 0.5;
  14.    
  15.    float4 eq[8];
  16.    for(int i = 0; i < 8; i++)
  17.       eq[i] = tex2D(baseMap, tc+float2(i,0.0)*isize);
  18.    
  19.    float wind = 1.0;
  20.    for(int i = 0; i < 8; i++)
  21.    {
  22.       float mult = -1.0;
  23.       if(ssize.y <= eq[i].x) //check if point is above line segment
  24.          mult = 1.0;
  25.       if(ssize.y > eq[i].w) //or below
  26.          mult = 1.0;
  27.  
  28.       //find x coordinate of intersection point
  29.       float ty = ssize.y - eq[i].x;
  30.       float ty2 = eq[i].w - eq[i].x;
  31.       float rel = ty / ty2;
  32.       float resx = lerp(eq[i].z, eq[i].y, rel);
  33.  
  34.       if(resx > ssize.x) //if intersection point lies on the ray
  35.          wind *= mult;
  36.    }
  37.    return wind;
  38. }


Editing is locked.