public static RColor getLight(P3 p, P3 normal) { RColor c = new RColor(0, 0, 0); foreach (Light l in lights) { c = c.Add(l.illumination(p, normal)); } return(c); }
public Form1() { InitializeComponent(); cs = new RColor[(int)width, (int)height]; for (int i = 0; i < cs.GetLength(0); i++) { for (int j = 0; j < cs.GetLength(1); j++) { cs[i, j] = new RColor(0, 0, 0); } } /* * objects = new List<SceneObject> { * new SceneObject(new Sphere(new P3(-0.4f,0,0), 0.5f), * new ImageTexture(RayTrace.Properties.Resources.Earth_texture), * new NonReflective()), * new SceneObject(new Sphere(new P3(0.4f,-.2f,0), 0.3f), * new SolidTexture(new RColor(0,1,0)), * new NonReflective()), * new SceneObject(new Sphere(new P3(0.5f,-0.4f,-0.5f), 0.2f, ve: new P3(1, 0, 0)), * new ImageTexture(RayTrace.Properties.Resources.Earth_texture), * new NonReflective()), * new SceneObject(new Plane(new P3(0,0,0.5f), new P3(0,0,-1)), * new SolidTexture(new RColor(1,0,0)), * new Mirror())}; * lights = new List<Light> { * new AmbientLight(new RColor(0.3f, 0.3f, 0.3f)), * new DirectionalLight(new RColor(1,1,1), new P3(1, -.2f, -.3f).Normalize())}; * */ objects = new List <SceneObject>(); for (int i = -8; i < 9; i++) { for (int j = -8; j < 1; j++) { objects.Add(new SceneObject(new Sphere(new P3(i, 50, j), 0.5f), new ImageTexture(RayTrace.Properties.Resources.Earth_texture), new NonReflective())); } } objects.Add(new SceneObject(new Plane(new P3(0, 0, 0.5f), new P3(0, 0, -1)), new SolidTexture(new RColor(1, 0, 0)), new Mirror())); lights = new List <Light> { new AmbientLight(new RColor(0.2f, 0.2f, 0.2f)), new DirectionalLight(new RColor(1, 1, 1), new P3(1, -.2f, -.3f).Normalize()) }; Trace(); worldBox.Refresh(); }
public RColor illumination(P3 point, P3 normal) { float inten = this.p.Dot(normal); RColor color = new RColor(0, 0, 0); if (inten > 0) { color = c.Scale(inten); float d; SceneObject s = Form1.shootRay(new Ray(point, this.p), out d); if (s != null) { return new RColor(0, 0, 0); } } return color; }
public RColor illumination(P3 point, P3 normal) { float inten = this.p.Dot(normal); RColor color = new RColor(0, 0, 0); if (inten > 0) { color = c.Scale(inten); float d; SceneObject s = Form1.shootRay(new Ray(point, this.p), out d); if (s != null) { return(new RColor(0, 0, 0)); } } return(color); }
public Form1() { InitializeComponent(); cs = new RColor[(int)width, (int)height]; for (int i = 0; i < cs.GetLength(0); i++) { for (int j = 0; j < cs.GetLength(1); j++) { cs[i, j] = new RColor(0, 0, 0); } } /* objects = new List<SceneObject> { new SceneObject(new Sphere(new P3(-0.4f,0,0), 0.5f), new ImageTexture(RayTrace.Properties.Resources.Earth_texture), new NonReflective()), new SceneObject(new Sphere(new P3(0.4f,-.2f,0), 0.3f), new SolidTexture(new RColor(0,1,0)), new NonReflective()), new SceneObject(new Sphere(new P3(0.5f,-0.4f,-0.5f), 0.2f, ve: new P3(1, 0, 0)), new ImageTexture(RayTrace.Properties.Resources.Earth_texture), new NonReflective()), new SceneObject(new Plane(new P3(0,0,0.5f), new P3(0,0,-1)), new SolidTexture(new RColor(1,0,0)), new Mirror())}; lights = new List<Light> { new AmbientLight(new RColor(0.3f, 0.3f, 0.3f)), new DirectionalLight(new RColor(1,1,1), new P3(1, -.2f, -.3f).Normalize())}; * */ objects = new List<SceneObject>(); for (int i = -8; i < 9; i++) { for (int j = -8; j < 1; j++) { objects.Add(new SceneObject(new Sphere(new P3(i, 50, j), 0.5f), new ImageTexture(RayTrace.Properties.Resources.Earth_texture), new NonReflective())); } } objects.Add(new SceneObject(new Plane(new P3(0, 0, 0.5f), new P3(0, 0, -1)), new SolidTexture(new RColor(1, 0, 0)), new Mirror())); lights = new List<Light> { new AmbientLight(new RColor(0.2f, 0.2f, 0.2f)), new DirectionalLight(new RColor(1, 1, 1), new P3(1, -.2f, -.3f).Normalize())}; Trace(); worldBox.Refresh(); }
public void NormalizeColors(RColor[,] cs) { float max = 0; for (int i = 0; i < cs.GetLength(0); i++) { for (int j = 0; j < cs.GetLength(1); j++) { max = Math.Max(max, cs[i, j].Intensity()); } } for (int i = 0; i < cs.GetLength(0); i++) { for (int j = 0; j < cs.GetLength(1); j++) { cs[i, j] = cs[i, j].Normalize(max); } } }
public Ray(P3 start, P3 direction) { this.start = start; this.direction = direction.Normalize(); color = new RColor(0, 0, 0); }
public SolidTexture(RColor c) { this.c = c; }
public RColor Color(P3 p, Ray r, SceneObject s) { RColor light = Form1.getLight(p, s.Geo.Normal(p)); return light.Mul(s.Texture.Color(s.Geo.ToP2(p))); }
public RColor Mul(RColor c) { return(new RColor(this.R * c.R, this.G * c.G, this.B * c.B)); }
public AmbientLight(RColor l) { this.l = l; }
public RColor Add(RColor c) { return(new RColor(this.R + c.R, this.G + c.G, this.B + c.B)); }
public static RColor getLight(P3 p, P3 normal) { RColor c = new RColor(0, 0, 0); foreach (Light l in lights) { c = c.Add(l.illumination(p, normal)); } return c; }
public RColor Add(RColor c) { return new RColor(this.R + c.R, this.G + c.G, this.B + c.B); }
public DirectionalLight(RColor c, float theta, float phi) { this.c = c; this.p = P3.fromSphere(theta, phi); }
public DirectionalLight(RColor c, P3 p) { this.c = c; this.p = p; }
public RColor Mul(RColor c) { return new RColor(this.R * c.R, this.G * c.G, this.B * c.B); }