private static void TestCase04() { // ShadeHit() with a reflective, transparent material World w = new DefaultWorld(); Ray r = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); Shape floor = new Plane(); floor.Transform = Transformation.Translation(0, -1, 0); floor.Material.Reflective = 0.5f; floor.Material.Transparency = 0.5f; floor.Material.RefractiveIndex = 1.5f; w.Shapes.Add(floor); Shape ball = new Sphere(); ball.Material.Color = Tuple.Color(1, 0, 0); ball.Material.Ambient = 0.5f; ball.Transform = Transformation.Translation(0, -3.5f, -0.5f); w.Shapes.Add(ball); List <Intersection> xs = Intersection.Aggregate(new Intersection(Sqrt(2), floor)); Computation comps = new Computation(xs[0], r, xs); LightingModel l = new PhongReflection(); Tuple color = l.ShadeHit(w, comps, 5); Assert.Equal(Tuple.Color(0.93391f, 0.69643f, 0.69243f), color); }
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 TestCase07() { World w = new DefaultWorld(); Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); LightingModel phong = new PhongReflection(); Tuple c = phong.ColorAt(w, r); Assert.Equal(Tuple.Color(0.38066f, 0.47583f, 0.2855f), c); }
private static void TestCase04() { World w = new DefaultWorld(); Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); Shape shape = w.Shapes[0]; Intersection i = new Intersection(4, shape); Computation comps = new Computation(i, r); LightingModel phong = new PhongReflection(); Tuple c = phong.ShadeHit(w, comps); Assert.Equal(Tuple.Color(0.38066f, 0.47583f, 0.2855f), c); }
private static void TestCase05() { // The refracted color with an opaque surface World w = new DefaultWorld(); Shape shape = w.Shapes[0]; Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); List <Intersection> xs = Intersection.Aggregate(new Intersection(4, shape), new Intersection(6, shape)); Computation comps = new Computation(xs[0], r, xs); LightingModel l = new PhongReflection(); Tuple c = l.RefractedColor(w, comps, 5); Assert.Equal(Tuple.Color(0, 0, 0), c); }
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 TestCase08() { World w = new DefaultWorld(); Shape outer = w.Shapes[0]; outer.Material.Ambient = 1; Shape inner = w.Shapes[1]; inner.Material.Ambient = 1; Ray r = new Ray(Tuple.Point(0, 0, 0.75f), Tuple.Vector(0, 0, -1)); LightingModel phong = new PhongReflection(); Tuple c = phong.ColorAt(w, r); Assert.Equal(c, inner.Material.Color); }
private static void TestCase03() { // The reflected color for a nonreflective material World w = new DefaultWorld(); Ray r = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 0, 1)); Shape shape = w.Shapes[1]; shape.Material.Ambient = 1; Intersection i = new Intersection(1, shape); Computation comps = new Computation(i, r); LightingModel l = new PhongReflection(); Tuple color = l.ReflectedColor(w, comps); Assert.Equal(Tuple.Color(0, 0, 0), color); }
private static void TestCase06() { // The refracted color at the maximum recursive depth World w = new DefaultWorld(); Shape shape = w.Shapes[0]; shape.Material.Transparency = 1; shape.Material.RefractiveIndex = 1.5f; Ray r = new Ray(Tuple.Point(0, 0, -5), Tuple.Vector(0, 0, 1)); List <Intersection> xs = Intersection.Aggregate(new Intersection(4, shape), new Intersection(6, shape)); Computation comps = new Computation(xs[0], r, xs); LightingModel l = new PhongReflection(); Tuple c = l.RefractedColor(w, comps, 0); Assert.Equal(Tuple.Color(0, 0, 0), c); }
private static void TestCase07() { // The refracted color under total internal reflection World w = new DefaultWorld(); Shape shape = w.Shapes[0]; shape.Material.Transparency = 1; shape.Material.RefractiveIndex = 1.5f; Ray r = new Ray(Tuple.Point(0, 0, Sqrt(2) / 2), Tuple.Vector(0, 1, 0)); List <Intersection> xs = Intersection.Aggregate(new Intersection(-Sqrt(2) / 2, shape), new Intersection(Sqrt(2) / 2, shape)); Computation comps = new Computation(xs[1], r, xs); LightingModel l = new PhongReflection(); Tuple c = l.RefractedColor(w, comps, 5); Assert.Equal(Tuple.Color(0, 0, 0), c); }
private static void TestCase07() { // The reflected color at the maximum recursive depth World w = new DefaultWorld(); Shape shape = new Plane(); shape.Material.Reflective = 0.5f; shape.Transform = Transformation.Translation(0, -1, 0); w.Shapes.Add(shape); Ray r = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); Intersection i = new Intersection(Sqrt(2), shape); Computation comps = new Computation(i, r); LightingModel l = new PhongReflection(); Tuple color = l.ReflectedColor(w, comps, 0); Assert.Equal(Tuple.Color(0, 0, 0), color); }
private static void TestCase05() { // ShadeHit() with a reflective material World w = new DefaultWorld(); Shape shape = new Plane(); shape.Material.Reflective = 0.5f; shape.Transform = Transformation.Translation(0, -1, 0); w.Shapes.Add(shape); Ray r = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); Intersection i = new Intersection(Sqrt(2), shape); Computation comps = new Computation(i, r); LightingModel l = new PhongReflection(); Tuple color = l.ShadeHit(w, comps); Assert.Equal(Tuple.Color(0.87677f, 0.92436f, 0.82918f), color); }
private static void TestCase04() { World w = new DefaultWorld(); Camera c = new Camera(11, 11, PI / 2.0f); Tuple from = Tuple.Point(0, 0, -5); Tuple to = Tuple.Point(0, 0, 0); Tuple up = Tuple.Vector(0, 1, 0); c.Transform = Transformation.LookAt(from, to, up); LightingModel l = new PhongReflection(); Canvas image = Canvas.Render(c, w, l); Assert.Equal(image.PixelAt(5, 5), Tuple.Color(0.38066f, 0.47583f, 0.2855f)); }
private static void TestCase04() { // The reflected color for a reflective material World w = new DefaultWorld(); Shape shape = new Plane(); shape.Material.Reflective = 0.5f; shape.Transform = Transformation.Translation(0, -1, 0); w.Shapes.Add(shape); Ray r = new Ray(Tuple.Point(0, 0, -3), Tuple.Vector(0, -Sqrt(2) / 2, Sqrt(2) / 2)); Intersection i = new Intersection(Sqrt(2), shape); Computation comps = new Computation(i, r); LightingModel l = new PhongReflection(); Tuple color = l.ReflectedColor(w, comps); Assert.Equal(0.19032f, color.X, 3); Assert.Equal(0.2379f, color.Y, 3); Assert.Equal(0.14274f, color.Z, 3); }
private static void Simulate() { Camera c = new Camera(400, 200, PI / 3); c.Transform = Transformation.LookAt(Tuple.Point(0, 1.5f, -5), Tuple.Point(0, 1, 0), Tuple.Vector(0, 1, 0)); World w = new FirstScene(); LightingModel l = new PhongReflection(); Canvas canvas = Canvas.Render(c, w, l); using (StreamWriter sw = new StreamWriter(@"./firstScene.ppm")) { sw.Write(canvas.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); }
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 TestCase08() { // The refracted color with a refracted ray World w = new DefaultWorld(); Shape A = w.Shapes[0]; A.Material.Ambient = 1; A.Material.Pattern = new PositionPattern(); Shape B = w.Shapes[1]; B.Material.Transparency = 1; B.Material.RefractiveIndex = 1.5f; Ray r = new Ray(Tuple.Point(0, 0, 0.1f), Tuple.Vector(0, 1, 0)); List <Intersection> xs = Intersection.Aggregate(new Intersection(-0.9899f, A), new Intersection(-0.4899f, B), new Intersection(0.4899f, B), new Intersection(0.9899f, A)); Computation comps = new Computation(xs[2], r, xs); LightingModel l = new PhongReflection(); Tuple c = l.RefractedColor(w, comps, 5); Assert.Equal(Tuple.Color(0, 0.99888f, 0.04725f), c); }
private static void TestCase06() { // ColorAt() with mutually reflective surfaces World w = new World(); w.Lights.Add(new PointLight(Tuple.Point(0, 0, 0), Tuple.Color(1, 1, 1))); Shape lower = new Plane(); lower.Material.Reflective = 1; lower.Transform = Transformation.Translation(0, -1, 0); w.Shapes.Add(lower); Shape upper = new Plane(); upper.Material.Reflective = 1; upper.Transform = Transformation.Translation(0, 1, 0); w.Shapes.Add(upper); Ray r = new Ray(Tuple.Point(0, 0, 0), Tuple.Vector(0, 1, 0)); LightingModel l = new PhongReflection(); l.ColorAt(w, r); Assert.True(true); }
private static void TestCase06() { World w = new World(); w.Lights.Add(new PointLight(Tuple.Point(0, 0, -10), Tuple.Color(1, 1, 1))); Shape s1 = new Sphere(); w.Shapes.Add(s1); Shape s2 = new Sphere(); s2.Transform = Transformation.Translation(0, 0, 10); w.Shapes.Add(s2); Ray r = new Ray(Tuple.Point(0, 0, 5), Tuple.Vector(0, 0, 1)); Intersection i = new Intersection(4, s2); Computation comps = new Computation(i, r); PhongReflection phong = new PhongReflection(); Tuple c = phong.ShadeHit(w, comps); Assert.Equal(Tuple.Color(0.1f, 0.1f, 0.1f), c); }