Exemple #1
0
 public void MixTest()
 {
     for(int i = 0; i < TestParameters.ColorTest; i++) {
         ColorCache cc = new ColorCache(0x00);
         uint rgb = (uint)((uint)Maths.RandomGenerator.Next()&Color.Color8Mask);
         cc.AddColor(rgb);
         Assert.AreEqual(rgb, cc.MixRGB(0x01));
     }
 }
Exemple #2
0
		private void CalculateImage (int yfrom, int yto) {
			double sd = this.screenDistance;
			double sh = 2.0d*sd*Math.Tan(0.5d*this.foVH);
			int w = this.Width;
			int h = this.Height;
			double sw = sh*w/h;
			double dwh = sw/w;
			Ray ray = new Ray(0.0d, 0.0d, 0.0d, 0.0d, 0.0d, 1.0d);
			uint[] pixel = this.raster.Pixel;
			int k = Width*yfrom, ks = Width*yto, kc;
			uint l, m;
			uint aasqrt = this.antialiasSqrt;
			uint aadsqrt = this.dispersionAntialiasSqrt;
			RayTracer rt = new RayTracer(this.acc, this.Lights, settings);
			uint aa = aasqrt*aasqrt, aac, aad = aadsqrt*aadsqrt, aadc;
			Point3 tmp = new Point3(0.0d, 0.0d, 0.0d);
			double focusLength = Point3.DiffLength(this.position, this.lookAt);
			double frac = 1.0d+focusLength/this.screenDistance;
			uint aaaad = aa*aad;
			double dwha = dwh/aasqrt;
			double dwhad = dispersion*dwh;
			double yp = dwh*yfrom-0.5d*sh-0.5d*dwha*aasqrt, xp;
			double yd, xd;
			double dis = this.displacement;
			ColorCache cc;
			#region PIXEL
			for(; k < ks;) {
				kc = k+Width;
				xp = -0.5d*sw-0.5d*dwha*aasqrt-dis;
				for(; k < kc;) {
					l = 0x00;
					cc = new ColorCache(0x00);
					#region ANTIALIASING
					for(; l < aa;) {
						aac = l+aasqrt;
						for(; l < aac; l++) {
							m = 0x00;
							tmp.SetValues(xp*frac, -yp*frac, focusLength);
							yd = -0.5d*dwhad*(aadsqrt-0x01);
							#region DISPERSION
							for(; m < aad;) {
								xd = -0.5d*dwhad*(aadsqrt-0x01);
								aadc = m+aadsqrt;
								for(; m < aadc; m++) {
									ray.Offset.SetValues(xp+xd, -yp-yd, 0.0d);
									ray.Direction.SetValues(ray.Offset, tmp);
									ray.Direction.Normalize();
									ray.NormalizeDirection();
									ray.Transform(this.matrix);
#if FAST_COLOR_INTERSECTION
									rt.CalculateColor(ray, 0, Color.White);
									cc.AddColor(new Color(ColorUtils.FromWavelength(350+5*(int)SystemDiagnostics.Intersections)));
									SystemDiagnostics.Intersections = 0x00;
#elif FAST_COLOR_MIGRATION
									rt.CalculateColor(ray, 0, Color.White);
									cc.AddColor(new Color(ColorUtils.FromWavelength(350+5*(int)SystemDiagnostics.Migrations)));
									SystemDiagnostics.Migrations = 0x00;
#else
									cc.AddColor(rt.CalculateColor(ray, 0, Color.White));
#endif
									xd += dwhad;
								}
								yd += dwhad;
							}
							#endregion
							xp += dwha;
						}
						yp += dwha;
						xp -= dwh;
					}
					#endregion
					yp -= dwh;
					xp += dwh;
					pixel[k++] = ColorUtils.AlphaChannel|cc.Mix(aaaad).RGB8;
				}
				#endregion
				yp += dwh;
			}
		}