Advertisement
Guest User

Untitled

a guest
May 30th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1. // shadow intersect functie
  2.  
  3. public bool Intersects(Ray r, float d)
  4.         {
  5.             foreach (Primitive p in primitives)
  6.             {
  7.                 Intersection q = p.Intersect(r);
  8.  
  9.                 if (q != null)
  10.                 {
  11.                     if(q.distance < d && q.distance>0)
  12.                     {
  13.                         return true;
  14.                     }
  15.                 }
  16.             }
  17.             return false;
  18.         }
  19.  
  20. // shadow ray functie
  21.  
  22. Vector3 l = Vector3.Normalize(s.Location - i.Location);
  23. float dotnl = Vector3.Dot(Vector3.Normalize(i.Normal), l);
  24.  
  25.              
  26. //shadow ray
  27. if(dotnl >= 0)
  28.     {
  29.                    
  30.                     Vector3 direction = s.Location - i.Location;
  31.                     float shadow_length = direction.Length - 2 * epsilon.X;
  32.                    
  33.                     Ray shadow_ray = new Ray(i.Location + epsilon, Vector3.Normalize(direction));
  34.  
  35.                     if (!Intersects(shadow_ray, shadow_length))
  36.                     {
  37.                        
  38.                         // lambertian
  39.                         Vector3 result_lambertian = (Vector3.Multiply(s.Intensity * i.primitive.material.color, Math.Max(0, dotnl)));
  40.  
  41.                         // blinn-phong
  42.                         Vector3 v = Vector3.Normalize(c.Position - i.Location);
  43.                         Vector3 h = Vector3.Normalize(v + l);
  44.  
  45.                         float dotnh = Vector3.Dot(Vector3.Normalize(i.Normal), h);
  46.                         Vector3 result_blinnphong = Vector3.Multiply(s.Intensity * i.primitive.material.ambient_color,                  (float)Math.Pow(Math.Max(0, dotnh), p));
  47.  
  48.                         total += Vector3.Multiply((result_blinnphong + result_lambertian), 0.7f);
  49.                     }
  50.                 }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement