package ray.shader;

import java.util.List;

import ray.Light;
import ray.Scene;
import ray.math.Color;
import ray.math.Point;
import ray.math.Vector;
import ray.surface.Surface;


/**
 * A Lambertian material scatters light equally in all directions.
 *
 * @author YOUR NAME HERE
 */
public class Lambertian implements Shader {
    // These fields are read in from the input file.
    /** The color of the surface. */
    protected final Color diffuseColor = new Color(1, 1, 1);

    // PARSER METHODS
    public void setDiffuseColor (Color inDiffuseColor) {
        diffuseColor.set(inDiffuseColor);
    }

    /**
     * @see Shader#shade()
     */
    @Override
    public Color shade (Point intersectPt, Surface surface, Scene scene) {
        // TODO: calculate the intensity of the light along this ray
    	Color output = new Color(0,0,0);
    	Vector normal = surface.getNormal(intersectPt).normalize();//unit vector of normal
    	Vector l = new Vector();//vector of light
    	for(Light light :scene.getLights()){
    		
    		l.x += light.position.x -intersectPt.x; 
    		l.y += light.position.y - intersectPt.y;
    		l.z += light.position.z-intersectPt.z;
    		
    		l.normalize();
    		
    		output.x += diffuseColor.x * light.color.x * Math.max(0, normal.dot(l));
    		output.y += diffuseColor.y * light.color.y * Math.max(0, normal.dot(l));
    		output.z += diffuseColor.z * light.color.z * Math.max(0, normal.dot(l));
    	}
    	
        return output;
    }
}

@@ -803,16 +803,18 @@
 his ray%0A
+//
     %09Col
@@ -1058,16 +1058,17 @@
 tion.x -
+ 
 intersec
@@ -1151,17 +1151,19 @@
 sition.z
--
+ - 
 intersec
@@ -1214,17 +1214,24 @@
   %09%09
-output
+diffuseColor
 .x 
+ 
 += d
@@ -1270,35 +1270,35 @@
 Math.max(0, 
-norma
 l.dot(
+norma
 l));%0A    %09%09o
@@ -1300,17 +1300,24 @@
   %09%09
-output
+diffuseColor
 .y 
+ 
 += d
@@ -1356,35 +1356,35 @@
 Math.max(0, 
-norma
 l.dot(
+norma
 l));%0A    %09%09o
@@ -1386,17 +1386,24 @@
   %09%09
-output
+diffuseColor
 .z 
+ 
 += d
@@ -1450,19 +1450,19 @@
 (0, 
-norma
 l.dot(
+norma
 l));
@@ -1475,16 +1475,18 @@
 %7D%0A    %09%0A
+//
         
@@ -1492,22 +1492,66 @@
  return 
-output
+diffuseColor.clamp(0, 1);%0A    %09return diffuseColor
 ;%0A    %7D%0A

update lamb