private static void TestCase09() { Material m = new Material(); Tuple position = Tuple.Point(0, 0, 0); Tuple eyev = Tuple.Vector(0, 0, -1); Tuple normalv = Tuple.Vector(0, 0, -1); Light light = new PointLight(Tuple.Point(0, 0, -10), Tuple.Color(1, 1, 1)); LightingModel phong = new PhongReflection(); Tuple result = phong.Lighting(m, new Sphere(), light, position, eyev, normalv, false); Assert.Equal(Tuple.Color(1.9f, 1.9f, 1.9f), result); eyev = Tuple.Vector(0, Sqrt(2) / 2, -Sqrt(2) / 2); result = phong.Lighting(m, new Sphere(), light, position, eyev, normalv, false); Assert.Equal(Tuple.Color(1.0f, 1.0f, 1.0f), result); eyev = Tuple.Vector(0, 0, -1); light = new PointLight(Tuple.Point(0, 10, -10), Tuple.Color(1, 1, 1)); result = phong.Lighting(m, new Sphere(), light, position, eyev, normalv, false); Assert.Equal(Tuple.Color(0.7364f, 0.7364f, 0.7364f), result); eyev = Tuple.Vector(0, -Sqrt(2) / 2, -Sqrt(2) / 2); result = phong.Lighting(m, new Sphere(), light, position, eyev, normalv, false); Assert.Equal(Tuple.Color(1.6364f, 1.6364f, 1.6364f), result); }
private static void TestCase03() { // Lighting with a pattern applied Material m = new Material(); m.Pattern = new StripePattern(white, black); m.Ambient = 1; m.Diffuse = 0; m.Specular = 0; Tuple eyev = Tuple.Vector(0, 0, -1); Tuple normalv = Tuple.Vector(0, 0, -1); Light light = new PointLight(Tuple.Point(0, 0, -10), Tuple.Color(1, 1, 1)); LightingModel l = new PhongReflection(); Tuple c1 = l.Lighting(m, new Sphere(), light, Tuple.Point(0.9f, 0, 0), eyev, normalv, false); Tuple c2 = l.Lighting(m, new Sphere(), light, Tuple.Point(1.1f, 0, 0), eyev, normalv, false); Assert.Equal(white, c1); Assert.Equal(black, c2); }
private static void TestCase10() { Material m = new Material(); Tuple position = Tuple.Point(0, 0, 0); Tuple eyev = Tuple.Vector(0, 0, -1); Tuple normalv = Tuple.Vector(0, 0, -1); Light light = new PointLight(Tuple.Point(0, 0, 10), Tuple.Color(1, 1, 1)); LightingModel phong = new PhongReflection(); Tuple result = phong.Lighting(m, new Sphere(), light, position, eyev, normalv, false); Assert.Equal(Tuple.Color(0.1f, 0.1f, 0.1f), result); }
private static void Simulate() { int canvasPixel = 256; Canvas c = new Canvas(canvasPixel, canvasPixel); Sphere s = new Sphere(); s.Material.Color = Tuple.Color(1, 0.2f, 1); float wallSize = 7.0f; float half = wallSize * 0.5f; float pixelSize = wallSize / canvasPixel; Tuple lightPosition = Tuple.Point(-10, 10, -10); Tuple lightColor = Tuple.Color(1, 1, 1); Light light = new PointLight(lightPosition, lightColor); Tuple rayOrigin = Tuple.Point(0, 0, -5); LightingModel phong = new PhongReflection(); for (int h = 0; h < c.Height; ++h) { float worldY = pixelSize * h - half; for (int w = 0; w < c.Width; ++w) { float worldX = pixelSize * w - half; Tuple position = Tuple.Point(worldX, worldY, 10); Ray r = new Ray(rayOrigin, (position - rayOrigin).Normalize()); List <Intersection> xs = s.Intersect(r); Intersection hit = Intersection.Hit(xs); if (hit != null) { Tuple point = r.Position(hit.T); Tuple normal = hit.Object.NormalAt(point, hit); Tuple eye = -r.Direction; Tuple color = phong.Lighting(hit.Object.Material, hit.Object, light, point, eye, normal, false); c.WritePixel(w, c.Height - h, color); } } } using (StreamWriter sw = new StreamWriter(@"./purpleSphere.ppm")) { sw.Write(c.ToPPM()); } Assert.True(true); }
private static void TestCase05() { World w = new DefaultWorld(); w.Lights[0] = new PointLight(Tuple.Point(0, 0.25f, 0), Tuple.Color(1, 1, 1)); Ray r = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 0, 1)); Shape shape = w.Shapes[1]; Intersection i = new Intersection(0.5f, shape); Computation comps = new Computation(i, r); LightingModel phong = new PhongReflection(); Tuple c = phong.Lighting(comps.Object.Material, comps.Object, w.Lights[0], comps.Point, comps.Eyev, comps.Normalv, false); Assert.Equal(Tuple.Color(0.90498f, 0.90498f, 0.90498f), c); }