Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // shadow intersect functie
- public bool Intersects(Ray r, float d)
- {
- foreach (Primitive p in primitives)
- {
- Intersection q = p.Intersect(r);
- if (q != null)
- {
- if(q.distance < d && q.distance>0)
- {
- return true;
- }
- }
- }
- return false;
- }
- // shadow ray functie
- Vector3 l = Vector3.Normalize(s.Location - i.Location);
- float dotnl = Vector3.Dot(Vector3.Normalize(i.Normal), l);
- //shadow ray
- if(dotnl >= 0)
- {
- Vector3 direction = s.Location - i.Location;
- float shadow_length = direction.Length - 2 * epsilon.X;
- Ray shadow_ray = new Ray(i.Location + epsilon, Vector3.Normalize(direction));
- if (!Intersects(shadow_ray, shadow_length))
- {
- // lambertian
- Vector3 result_lambertian = (Vector3.Multiply(s.Intensity * i.primitive.material.color, Math.Max(0, dotnl)));
- // blinn-phong
- Vector3 v = Vector3.Normalize(c.Position - i.Location);
- Vector3 h = Vector3.Normalize(v + l);
- float dotnh = Vector3.Dot(Vector3.Normalize(i.Normal), h);
- Vector3 result_blinnphong = Vector3.Multiply(s.Intensity * i.primitive.material.ambient_color, (float)Math.Pow(Math.Max(0, dotnh), p));
- total += Vector3.Multiply((result_blinnphong + result_lambertian), 0.7f);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement