Procedurality.Channel.putPixelClip C# (CSharp) Method

putPixelClip() public method

public putPixelClip ( int x, int y, float v ) : void
x int
y int
v float
return void
		public void putPixelClip(int x, int y, float v) {
			if (v < 0f) pixels[y,x] = 0;
			else if (v > 1f) pixels[y,x] = 1;
			else pixels[y,x] = v;
		}
	

Usage Example

コード例 #1
0
ファイル: Channel.cs プロジェクト: N3X15/VoxelSim
		public Channel bump(Channel bumpmap, float lx, float ly, float shadow, float light, float ambient) {
			if(!(bumpmap.getWidth() == width && bumpmap.getHeight() == height))
				throw new Exception("bumpmap does not match channel size");
			Channel channel = new Channel(width, height);
			for (int y = 0; y < height; y++) {
				for (int x = 0; x < width; x++) {
					float nx = bumpmap.getPixelWrap(x + 1, y) - bumpmap.getPixelWrap(x - 1, y);
					float ny = bumpmap.getPixelWrap(x, y + 1) - bumpmap.getPixelWrap(x, y - 1);
					float brightness = nx*lx + ny*ly;
					if (brightness >= 0) {
						channel.putPixelClip(x, y, (getPixel(x, y) + brightness*light)*(bumpmap.getPixel(x, y)*shadow + 1 - shadow));
					} else {
						channel.putPixelClip(x, y, (getPixel(x, y) + brightness*(1 - ambient))*(bumpmap.getPixel(x, y)*shadow + 1 - shadow));
					}
				}
			}
			pixels = channel.getPixels();
			return this;
		}