示例#1
0
 public override void Process(Camera cam, Texture output, IAccelerator acc)
 {
     uint[] pix = output.Pixel;
     for(int i = 0; i < pix.Length; i++) {
         pix[i] = ColorUtils.AlphaChannel|ColorUtils.Random(pix[i], delta);
     }
 }
示例#2
0
 public void AddTexture(Texture txt)
 {
     if(txt != null) {
         uint[] data = txt.Pixel;
         int n = System.Math.Min(this.Pixel.Length, data.Length);
         for(int i = 0x00; i < n; i++)
             this.Pixel[i].AddColor(data[i]);
     }
 }
示例#3
0
 public Texture Mix(uint n)
 {
     Texture tex = new Texture(this.Width, this.Height);
     uint[] pixel = tex.Pixel;
     ColorCache[] cc = this.Pixel;
     for(int i = 0; i < cc.Length; i++) {
         pixel[i] = cc[i].MixRGB(n);
     }
     return tex;
 }
示例#4
0
 public override void Process(Camera cam, Texture output, Accelerator acc)
 {
     int px = 250;
     int py = 250;
     int cx = 500;
     int cy = 500;
     float dx = (float)(cx-px);
     float dy = (float)(cy-py);
     int posx, posy, xsize, ysize;
     float zoom;
     for(int i = 0; i < flares; i++) {
         zoom = Maths.Pythagoras(dx, dy)/Maths.Pythagoras(cx, cy);
         zoom = 1.5f-0.5f*zoom;
         xsize = flare[i].Width;
         ysize = flare[i].Height;
         posx = px+(int)(dx*flareDist[i]);
         posy = py+(int)(dy*flareDist[i]);
         cam.Raster.AddWithAlpha(flare[i], posx-xsize/2, posy-ysize/2, xsize, ysize);
     }
 }
示例#5
0
 public static Texture BlendTopDown(Texture top, Texture down)
 {
     int h = top.Height;
     int w = top.Width;
     down.Resize(w, h);
     Texture t = new Texture(w, h);
     int pos = 0x00;
     int x;
     uint alpha;
     for(int y = 0x00; y < h; y++) {
         alpha = (uint)(0xff*y/(top.Height-0x01));
         for(x = 0x00; x < top.Width; x++) {
             t.Pixel[pos] = ColorUtils.Transparency(down.Pixel[pos], top.Pixel[pos], alpha);
             pos++;
         }
     }
     return t;
 }
示例#6
0
 public Texture Sub(Texture subtractive)
 {
     uint[] data = subtractive.Pixel;
     int n = System.Math.Min(this.Pixel.Length, data.Length);
     for(int i = 0x00; i < n; i++)
         this.Pixel[i] = ColorUtils.Sub(this.Pixel[i], data[i]);
     return this;
 }
示例#7
0
 public Texture Put(Texture newData)
 {
     uint[] data = newData.Pixel;
     int n = System.Math.Min(this.Pixel.Length, data.Length);
     for(int i = 0x00; i < n; i++)
         this.Pixel[i] = data[i];
     return this;
 }
示例#8
0
 public Texture Multiply(Texture multiplicative)
 {
     uint[] data = multiplicative.Pixel;
     int n = System.Math.Min(this.Pixel.Length, data.Length);
     for(int i = 0x00; i < n; i++)
         this.Pixel[i] = ColorUtils.Multiply(this.Pixel[i], data[i]);
     return this;
 }
示例#9
0
 public Texture Mix(Texture newData)
 {
     uint[] data = newData.Pixel;
     int n = System.Math.Min(this.Pixel.Length, data.Length);
     for(int i = 0x00; i < n; i++)
         this.Pixel[i] = ColorUtils.Mix(this.Pixel[i], data[i]);
     return this;
 }
示例#10
0
 public SobelGenerator(Texture source)
 {
     this.texture = apply (source);
 }
示例#11
0
 private Texture CreateRays(int size, int rays, int rad, uint color)
 {
     int pos;
     float relPos;
     Texture texture = new Texture(size, size);
     int[] radialMap = new int[1024];
     for(int i = 0; i < rays; i++) {
         pos = (int)Maths.Random(rad, 1023-rad);
         for(int k = pos-rad; k <= pos+rad; k++) {
             relPos = (float)(k-pos+rad)/(float)(rad*2);
             radialMap[k] += (int)(255*(1+Math.Sin((relPos-0.25)*3.14159*2))/2);
         }
     }
     int angle, offset;
     float reldist;
     float xrel, yrel;
     for(int y = size-1; y >= 0; y--) {
         offset = y*size;
         for(int x = size-1; x >= 0; x--) {
             xrel = (float)(2*x-size)/(float)size;
             yrel = (float)(2*y-size)/(float)size;
             angle = (int)(1023*Math.Atan2(xrel, yrel)/3.14159/2)&1023;
             reldist = Math.Max(1.0f-Maths.Pythagoras(xrel, yrel), 0.0f);
             texture.Pixel[x+offset] = Color.Scale(color, (uint)(radialMap[angle]*reldist));
         }
     }
     return texture;
 }
示例#12
0
 public Texture Add(Texture additive)
 {
     uint[] data = additive.Pixel;
     int n = System.Math.Min(this.Pixel.Length, data.Length);
     for(int i = 0x00; i < n; i++)
         this.Pixel[i] = ColorUtils.Add(this.Pixel[i], data[i]);
     return this;
 }
示例#13
0
 public static Texture ToCyanRed(Texture cyanTexture, Texture redTexture)
 {
     Texture result = new Texture(cyanTexture.Width, cyanTexture.Height);
     uint[] pixc = cyanTexture.Pixel;
     uint[] pixr = redTexture.Pixel;
     uint[] pix = result.Pixel;
     for(int i = 0; i < pix.Length; i++) {
         pix[i] = ColorUtils.ToCyanRed(pixc[i], pixr[i]);
     }
     return result;
 }
示例#14
0
文件: Camera.cs 项目: KommuSoft/MoRen
		public Camera (int w, int h, double screenDistance, double foVH, IAccelerator acc, Light[] lights, EnvironmentSettings settings, List<CameraPostProcessor> postprocessors = null) {
			this.raster = new Texture(w, h);
			this.foVH = foVH;
			this.acc = acc;
			this.Lights = lights;
			this.antialiasSqrt = settings.AntiAliasingSqrt;
			this.dispersion = settings.Dispersion;
			this.dispersionAntialiasSqrt = settings.DispersingAntiAliasingSqrt;
			this.settings = settings;
			if(postprocessors != null) {
				this.postProcessors = postprocessors;
			}
			else {
				this.postProcessors = new List<CameraPostProcessor>();
			}
		}
示例#15
0
 public Texture apply(Texture source)
 {
     int w = source.Width;
     int h = source.Height;
     Texture t = new Texture(w,h);
     int scan0 = 1;
     int scan1 = w+1;
     int scan2 = w*2+1;
     int r1, r2, g1, g2, b1, b2;
     for(int y = 1; y < h-1; y++) {
         for(int x = 1; x < w-1; x++) {
             r1 = 2*(int) Color.GetRed(source.Pixel[scan1+1])+
                 (int) Color.GetRed(source.Pixel[scan0+1])+
                 (int) Color.GetRed(source.Pixel[scan2+1])-
                 2*(int) Color.GetRed(source.Pixel[scan1+1])-
                 (int) Color.GetRed(source.Pixel[scan0+1])-
                 (int) Color.GetRed(source.Pixel[scan2+1]);
             g1 = 2*(int) Color.GetGreen(source.Pixel[scan1+1])+
                 (int) Color.GetGreen(source.Pixel[scan0+1])+
                 (int) Color.GetGreen(source.Pixel[scan2+1])-
                 2*(int) Color.GetGreen(source.Pixel[scan1+1])-
                 (int) Color.GetGreen(source.Pixel[scan0+1])-
                 (int) Color.GetGreen(source.Pixel[scan2+1]);
             b1 = 2*(int) Color.GetBlue(source.Pixel[scan1+1])+
                 (int) Color.GetBlue(source.Pixel[scan0+1])+
                 (int) Color.GetBlue(source.Pixel[scan2+1])-
                 2*(int) Color.GetBlue(source.Pixel[scan1+1])-
                 (int) Color.GetBlue(source.Pixel[scan0+1])-
                 (int) Color.GetBlue(source.Pixel[scan2+1]);
             r2 = 2*(int) Color.GetRed(source.Pixel[scan2])+
                 (int) Color.GetRed(source.Pixel[scan2+1])+
                 (int) Color.GetRed(source.Pixel[scan2-1])-
                 2*(int) Color.GetRed(source.Pixel[scan0])-
                 (int) Color.GetRed(source.Pixel[scan0+1])-
                 (int) Color.GetRed(source.Pixel[scan0-1]);
             g2 = 2*(int) Color.GetGreen(source.Pixel[scan2])+
                 (int) Color.GetGreen(source.Pixel[scan2+1])+
                 (int) Color.GetGreen(source.Pixel[scan2-1])-
                 2*(int) Color.GetGreen(source.Pixel[scan0])-
                 (int) Color.GetGreen(source.Pixel[scan0+1])-
                 (int) Color.GetGreen(source.Pixel[scan0-1]);
             b2 = 2*(int) Color.GetBlue(source.Pixel[scan2])+
                 (int) Color.GetBlue(source.Pixel[scan2+1])+
                 (int) Color.GetBlue(source.Pixel[scan2-1])-
                 2*(int) Color.GetBlue(source.Pixel[scan0])-
                 (int) Color.GetBlue(source.Pixel[scan0+1])-
                 (int) Color.GetBlue(source.Pixel[scan0-1]);
             r1 = Math.Min(255,(int) Math.Sqrt(r1*r1+r2*r2));
             g1 = Math.Min(255,(int) Math.Sqrt(g1*g1+g2*g2));
             b1 = Math.Min(255,(int) Math.Sqrt(b1*b1+b2*b2));
             r1 = (r1+g1+b1+2)/3;
             t.Pixel[scan1] = Color.GetColor((uint) r1, (uint) r1, (uint) r1);
             scan0++;
             scan1++;
             scan2++;
         }
         scan0 += 2;
         scan1 += 2;
         scan2 += 2;
     }
     return t;
 }
示例#16
0
        private void AddFlareTexture(Texture texture, float relPos)
        {
            flares++;
            if(flares == 1) {
                flare = new Texture[1];
                flareDist = new float[1];
            }
            else {
                Texture[] temp1 = new Texture[flares];
                Array.Copy(flare, 0, temp1, 0, flares-1);
                flare = temp1;

                float[] temp2 = new float[flares];
                Array.Copy(flareDist, 0, temp2, 0, flares-1);
                flareDist = temp2;
            }
            flare[flares-1] = texture;
            flareDist[flares-1] = relPos;
        }
示例#17
0
 private Texture CreateCircle(int w, int h, uint[] colormap, uint[] alphamap)
 {
     int offset;
     float relX, relY;
     Texture newTexture = new Texture(w, h);
     uint[] palette = getPalette(colormap, alphamap);
     for(int y = h-1; y >= 0; y--) {
         offset = y*w;
         for(int x = w-1; x >= 0; x--) {
             relX = (float)(x-(w>>1))/(float)(w>>1);
             relY = (float)(y-(h>>1))/(float)(h>>1);
             newTexture.Pixel[offset+x] = palette[Maths.Border(0, (int)(255*Math.Sqrt(relX*relX+relY*relY)), 255)];
         }
     }
     return newTexture;
 }
示例#18
0
 public void AddWithAlpha(Texture texture, int posx, int posy, int xsize, int ysize)
 {
     int w = xsize;
     int h = ysize;
     int xBase = posx;
     int yBase = posy;
     int tx = texture.Width*255;
     int ty = texture.Height*255;
     int tw = texture.Width;
     int dtx = tx/w;
     int dty = ty/h;
     int txBase = Maths.Border(0, -xBase*dtx, 255*tx);
     int tyBase = Maths.Border(0, -yBase*dty, 255*ty);
     int xend = Maths.Border(0, xBase+w, Width);
     int yend = Maths.Border(0, yBase+h, Height);
     int offset1, offset2;
     xBase = Maths.Border(0, xBase, Width);
     yBase = Maths.Border(0, yBase, Height);
     ty = tyBase;
     for(int j = yBase; j < yend; j++) {
         tx = txBase;
         offset1 = j*Width;
         offset2 = (ty>>8)*tw;
         for(int i = xBase; i < xend; i++) {
             Pixel[i+offset1] = ColorUtils.AlphaChannel|ColorUtils.Add(texture.Pixel[(tx>>8)+offset2], Pixel[i+offset1]);
             tx += dtx;
         }
         ty += dty;
     }
 }
示例#19
0
 public Texture Clone()
 {
     Texture t = new Texture(this.Width, this.Height);
     int n = this.Pixel.Length;
     for(int i = 0x00; i < n; i++)
         t.Pixel[i] = this.Pixel[i];
     return t;
 }
示例#20
0
 public abstract void Process(Camera cam, Texture output, IAccelerator acc);