public IPixelColor GetPixelColor(int col, int row) { int bmpRow = this.World.Camera.Height - 1 - row; if (this.AntiAliasing) { IRay ray = this.World.Camera.GetRay(col, bmpRow, 0, 0); IPixelColor c1 = this.Trace(ray, 0); ray = this.World.Camera.GetRay(col, bmpRow, 0.5f, 0); IPixelColor c2 = this.Trace(ray, 0); ray = this.World.Camera.GetRay(col, bmpRow, 0, 0.5f); IPixelColor c3 = this.Trace(ray, 0); ray = this.World.Camera.GetRay(col, bmpRow, 0.5f, 0.5f); IPixelColor c4 = this.Trace(ray, 0); IPixelColor color = PixelColor.Avg(c1, c2, c3, c4); return(color); } else { IRay ray = this.World.Camera.GetRay(col, bmpRow); IPixelColor color = this.Trace(ray, 0); return(color); } }
public IPixelColor Trace(IRay ray, int depth) { IRayHit hit = this.FindHit(ray); if (hit == null) { return(this.BackGroundColor); } IPixelColor color = new PixelColor { Ambient = new RGBColor(0.0f, 0.0f, 0.0f), Diffuse = new RGBColor(0.0f, 0.0f, 0.0f), Specular = new RGBColor(0.0f, 0.0f, 0.0f), Color = new RGBColor(0.0f, 0.0f, 0.0f) }; this.World.Lights.ForEach(delegate(ILight light) { IPixelColor lightColor = this.Shading.GetColor(hit, light); if (light.Type == LightType.PointLight) { IVector lightRayVec = new Vector(hit.Intersection, light.Position); IRay lightRay = new Ray(hit.Intersection, lightRayVec, lightRayVec.Length()); IRayHit obstruction = this.FindHit(lightRay); if (obstruction != null) { if (obstruction.IntersectShape is Sphere && obstruction.IntersectShape != hit.IntersectShape) { IVector vectorIntersectionToObstruction = new Vector(hit.Intersection, obstruction.Intersection); float distanceToObstruction = vectorIntersectionToObstruction.Length(); float distanceToLight = lightRayVec.Length(); float distanceFactor = distanceToObstruction / distanceToLight; lightColor.Color = lightColor.Color.Intensify(distanceFactor); } } } color = color.Blend(lightColor); }); if (depth < this.MaxRecursionLevel) { if (hit.IntersectShape.Material.IsReflective()) { color = color.Blend(this.Trace(hit.GetReflectionRay(), depth + 1).Intensify(hit.IntersectShape.Material.Reflection)); } if (hit.IntersectShape.Material.IsRefractive()) { color = color.Blend(this.Trace(hit.GetRefractionRay(), depth + 1).Intensify(hit.IntersectShape.Material.Refraction)); } } return(color); }
public IPixelColor Intensify(IPixelColor other) { IPixelColor result = new PixelColor { Ambient = this.Ambient.Intensify(other.Ambient), Diffuse = this.Diffuse.Intensify(other.Diffuse), Specular = this.Specular.Intensify(other.Specular), Color = this.Color.Intensify(other.Color) }; return(result); }
public void Execute(IWorld parameter) { Stopwatch watch = Stopwatch.StartNew(); Logger.Debug("Rendering in RayTracing with {0} levels of recursion", this.MaxRecursionLevel); this.World = parameter; this.AuxiliarShading = new AmbientShading(); this.AuxiliarImage = new Image(this.World.Camera.Width, this.World.Camera.Height); int maxPixels = this.World.Camera.Width * this.World.Camera.Height; IPixelColor[,] pixels = new IPixelColor[this.World.Camera.Width, this.World.Camera.Height]; Parallel.For(0, maxPixels, index => { int r = index / this.World.Camera.Width; int c = index % this.World.Camera.Width; pixels[c, r] = this.GetPixelColor(c, r); }); for (int r = 0; r < this.World.Camera.Height; r++) { for (int c = 0; c < this.World.Camera.Width; c++) { this.World.Image.Pixels[c, r] = pixels[c, r]; } } //this.World.Image.GetBitmap(ColorType.Ambient).Save("ambient.png", ImageFormat.Png); watch.Stop(); Logger.Debug("Rendered in {0} milliseconds", watch.ElapsedMilliseconds); }
public PixelPencil(IPixelColor holder) : base(holder) { }
public PixelStraw(IPixelColor holder) : base(holder) { }
public PixelStraw(IPixelColor holder) :base(holder) { }
public PixelPencil(IPixelColor holder) :base(holder) { }
public DragPixelTool(IPixelColor holder) : base(holder) { }
public PixelFill(IPixelColor holder) :base(holder) { }
public DragPixelTool(IPixelColor holder) :base(holder) { }
public PixelFill(IPixelColor holder) : base(holder) { }
public PixelLine(IPixelColor holder) :base(holder) { }
public PixelToolBase(IPixelColor holder) { ColorHolder = holder; }
public PixelLine(IPixelColor holder) : base(holder) { }