home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 2010 Software/Programs / PCGuia_programas.iso / Software / Utils / SPlayer / SPlayerSetup.exe / splayer.exe / 2052 / FILE / 709 < prev    next >
Encoding:
Text File  |  2009-12-01  |  1.3 KB  |  55 lines

  1. sampler s0 : register(s0);
  2. float4 p0 : register(c0);
  3.  
  4. #define clock (p0[3])
  5.  
  6. #define PI acos(-1)
  7.  
  8. float4 main(float2 tex : TEXCOORD0) : COLOR
  9. {
  10.     // - this is a very simple raytracer, one sphere only
  11.     // - no reflection or refraction, yet (my ati 9800 has a 64 + 32 instruction limit...)
  12.     
  13.     float3 pl = float3(3,-3,-4); // light pos
  14.     float4 cl = 0.4; // light color
  15.     
  16.     float3 pc = float3(0,0,-1); // cam pos
  17.     float3 ps = float3(0,0,0.5); // sphere pos
  18.     float r = 0.65; // sphere radius
  19.     
  20.     float3 pd = normalize(float3(tex.x-0.5, tex.y-0.5, 0) - pc);
  21.     
  22.     float A = 1;
  23.     float B = 2*dot(pd, pc - ps);
  24.     float C = dot(pc - ps, pc - ps) - r*r;
  25.     float D = B*B - 4*A*C;
  26.     
  27.     float4 c0 = 0;
  28.     
  29.     if(D >= 0)
  30.     {
  31.         // t2 is the smaller, obviously...
  32.         // float t1 = (-B + sqrt(D)) / (2*A);
  33.         // float t2 = (-B - sqrt(D)) / (2*A);
  34.         // float t = min(t1, t2); 
  35.         
  36.         float t = (-B - sqrt(D)) / (2*A);
  37.         
  38.         // intersection data
  39.         float3 p = pc + pd*t;
  40.         float3 n = normalize(p - ps);
  41.         float3 l = normalize(pl - p);
  42.         
  43.         // mapping the image onto the sphere
  44.         tex = acos(-n)/PI; 
  45.         
  46.         // rotate it
  47.         tex.x = frac(tex.x + frac(clock/10));
  48.         
  49.         // diffuse + specular
  50.         c0 = tex2D(s0, tex) * dot(n, l) + cl * pow(max(dot(l, reflect(pd, n)), 0), 50);
  51.     }
  52.     
  53.     return c0;
  54. }
  55.