private float Trace(Ray ray) { // diffuse reflection surface float color = 0f; InterResult inter = collider.Collide(ray); if (inter != null) { foreach (Light l in lights) { color += l.Sample(inter, collider); } } return(color); }
public float Sample(InterResult inter, Collider c) { Vec3d x = inter.position; Ray ray = GetRay(x); InterResult shadow = c.Collide(ray); if (shadow == null) { Vec3d normal = inter.entity.GetNormal(x); float tmp = normal % ray.direction; if (tmp > 0) { return(luminance * tmp); } } return(0); }
public InterResult Collide(Ray ray) { float t = 100000; InterResult inter = null; InterResult tmp; foreach (Shape entity in world) { tmp = entity.Intersect(ray); if (tmp != null && tmp.t >= 0 && tmp.t < t) { t = tmp.t; inter = tmp; } } return(inter); }