public class Colorizer {
	public PointyPoint sources_[] = new PointyPoint[1]; // overload pt=dir, v=rgb
	Vector3D ambient_ = new Vector3D(.1,.1,.1);
	Colorizer() {
		sources_[0] = new PointyPoint(new Vector3D(50,25,50),new Vector3D(1,1,1));
		sources_[0].pt.normalize();
	}
	Vector3D sum_ = new Vector3D(),
		part_ = new Vector3D(),
		refl_ = new Vector3D(),
		eye_ = new Vector3D(0,0,1);
	public void colorize(Vector3D normal,Vector3D color,Vector3D glare,double shiny,Vector3D outColor) {
		color.times(ambient_,sum_);
		for(PointyPoint source : sources_)
			if(source!=null) {
				double ndotl = Math.max(0.,normal.dot(source.pt));
				// diffuse
				color.times(source.v,part_);
				part_.times(ndotl);
				sum_.add(part_);
				
				// specular
				normal.times(2*ndotl,refl_);
				refl_.subtract(source.pt);
				glare.times(source.v,part_);
				double eyedotrefl=Math.max(0.,eye_.dot(refl_));
				part_.times(Math.pow(eyedotrefl,shiny));
				sum_.add(part_);
			}
		outColor.set(0,Math.min(1.,sum_.get(0)));
		outColor.set(1,Math.min(1.,sum_.get(1)));
		outColor.set(2,Math.min(1.,sum_.get(2)));
		/*
		double val = (1.+normal.x()-normal.y()+normal.z())/2.75;
		val = Math.min(1.,Math.max(0.,val));
		normal.set(0,val);	
		normal.set(1,val);	
		normal.set(2,val);	
		*/
	}
}
