public Tuple ShadeHit(World w, Computation comps, int remaining) { Tuple surface = Tuple.Color(0, 0, 0); foreach (var light in w.Lights) { bool shadowed = w.IsShadowed(light, comps.OverPoint); surface += Lighting(comps.Material, comps.Object, light, comps.Point, comps.Eyev, comps.Normalv, shadowed); } Tuple reflected = ReflectedColor(w, comps, remaining); Tuple refracted = RefractedColor(w, comps, remaining); Material material = comps.Material; if (material.Reflective > 0 && material.Transparency > 0) { float reflectance = Fresnel.Schlick(comps); return(surface + reflected * reflectance + refracted * (1 - reflectance)); } return(surface + reflected + refracted); }
public override Tuple Lighting(Material m, Shape shape, Light l, Tuple position, Tuple toEye, Tuple normal, bool inShadow) { Tuple color = (m.Pattern == null)? m.Color : m.Pattern.ColorAtShape(shape, position); Tuple effectiveColor = color * l.Intensity; Tuple toLight = (l.Position - position).Normalize(); Tuple ambient = effectiveColor * m.Ambient; float ndotl = normal.Dot(toLight); Tuple diffuse = Tuple.Color(0, 0, 0); Tuple specular = Tuple.Color(0, 0, 0); if ((inShadow == false) && (ndotl >= 0)) { diffuse = effectiveColor * m.Diffuse * ndotl; Tuple reflect = (-toLight).Reflect(normal); float rdote = reflect.Dot(toEye); if (rdote > 0) { specular = l.Intensity * m.Specular * Pow(rdote, m.Shininess); } } return(ambient + diffuse + specular); }
public Tuple RefractedColor(World w, Computation comps, int remaining) { if ((remaining <= 0) || (Abs(comps.Material.Transparency) < Constants.floatEps)) { return(Tuple.Color(0, 0, 0)); } float nRatio = comps.N1 / comps.N2; float cosTheta_i = comps.Eyev.Dot(comps.Normalv); float sin2Theta_t = nRatio * nRatio * (1 - cosTheta_i * cosTheta_i); if (sin2Theta_t >= 1) { return(Tuple.Color(0, 0, 0)); } float cosTheta_t = Sqrt(1 - sin2Theta_t); Tuple direction = comps.Normalv * (nRatio * cosTheta_i - cosTheta_t) - comps.Eyev * nRatio; Ray refractRay = new Ray(comps.UnderPoint, direction); Tuple color = ColorAt(w, refractRay, remaining - 1); return(color * comps.Material.Transparency); }
public Material() { Color = Tuple.Color(1, 1, 1); Ambient = 0.1f; Diffuse = 0.9f; Specular = 0.9f; Shininess = 200.0f; RefractiveIndex = 1; }
public Tuple ReflectedColor(World w, Computation comps, int remaining) { if ((remaining <= 0) || (Abs(comps.Material.Reflective) < Constants.floatEps)) { return(Tuple.Color(0, 0, 0)); } Ray reflectRay = new Ray(comps.OverPoint, comps.Reflectv); Tuple color = ColorAt(w, reflectRay, remaining - 1); return(color * comps.Material.Reflective); }
public Tuple ColorAt(World w, Ray r, int remaining) { List <Intersection> intersections = w.Intersection(r); Intersection intersection = Intersection.Hit(intersections); if (intersection == null) { return(Tuple.Color(0, 0, 0)); } Computation comps = new Computation(intersection, r, intersections); return(ShadeHit(w, comps, remaining)); }
public Canvas(int width, int height) { Width = width; Height = height; _pixels = new Tuple[Height, Width]; for (int y = 0; y < Height; ++y) { for (int x = 0; x < Width; ++x) { _pixels[y, x] = Tuple.Color(0, 0, 0); } } }
public DefaultWorld() { Lights.Add(new PointLight(Tuple.Point(-10, 10, -10), Tuple.Color(1, 1, 1))); Shape s1 = new Sphere(); s1.Material.Color = Tuple.Color(0.8f, 1, 0.6f); s1.Material.Diffuse = 0.7f; s1.Material.Specular = 0.2f; Shapes.Add(s1); Shape s2 = new Sphere(); s2.Transform = Transformation.Scaling(0.5f, 0.5f, 0.5f); Shapes.Add(s2); }
private static Tuple ReadColor(JToken jToken) { return(Tuple.Color((float)jToken[0], (float)jToken[1], (float)jToken[2])); }