@Override
	public void shade(Color outIntensity, Scene scene, Ray ray, IntersectionRecord record, int depth) {
		// TODO: fill in this function.
		// You may find it helpful to create helper methods if the code here gets too long.
		Vector3 outgoing = new Vector3(ray.direction);
		outgoing.scale(-1);
		outgoing.normalize();
		Vector3 incident = new Vector3(outgoing);
		incident.scale(-1);
		incident.normalize();
		record.normal.normalize();
		Ray reflected;
		Ray refracted;
		
		double nAir = 1.00;
		double nGlass = refractiveIndex;
		double theta1 = Math.acos(outgoing.dot(record.normal));
		double theta2 = Math.asin((nAir/nGlass)*Math.sin(theta1));
		
		Vector3 newDirection = new Vector3(incident);
		Vector3 temp = new Vector3(record.normal);
		temp.scale(2*incident.dot(record.normal));
		newDirection.sub(temp);
		newDirection.normalize();
		
		Vector3 d = new Vector3(newDirection);
		d.scale(-1);
		d.normalize();
		
		Color reflectedColor = new Color();
		Color refractedColor = new Color();
		
		if (outgoing.dot(record.normal) > 0){ //air to glass
			
		//Schlick's Approximation
		double R0 = Math.pow((nGlass-nAir)/(nGlass+nAir),2);
		double R = R0 + (1-R0)*(Math.pow(1-Math.cos(theta1), 5));
		double number = 1 - (Math.pow(nAir, 2)*(1-Math.pow(newDirection.dot(record.normal), 2))/Math.pow(nGlass, 2));
		
		reflected = new Ray(record.location, newDirection);
		reflected.makeOffsetRay();
		IntersectionRecord iRefl = new IntersectionRecord();
		
		if (number<0) {
			RayTracer.shadeRay(reflectedColor, scene, reflected, depth+1);
		} else {
			RayTracer.shadeRay(reflectedColor, scene, reflected, depth+1);
			scene.getFirstIntersection(iRefl, reflected);
			if (iRefl.surface != null){
				reflected.setAbsorption(iRefl.surface.getOutsideAbsorption());
				reflected.attenuate(reflectedColor, iRefl.location);
			}
		reflectedColor.scale(R);
		outIntensity.add(reflectedColor);
		
		Vector3 rDirection = new Vector3(newDirection);
		rDirection.scale(nAir/nGlass);
		rDirection.scaleAdd(-1*(nAir/nGlass)*newDirection.dot(record.normal), record.normal);
		rDirection.scaleAdd(-1*Math.sqrt(number),record.normal);
		rDirection.normalize();
		refracted = new Ray(record.location, rDirection);
		refracted.makeOffsetRay();
		IntersectionRecord iRefr = new IntersectionRecord();
		
		RayTracer.shadeRay(refractedColor, scene, refracted, depth+1);
		
		scene.getFirstIntersection(iRefr, refracted);
		if (iRefr.surface != null){
		refracted.setAbsorption(iRefr.surface.getInsideAbsorption());
		refracted.attenuate(refractedColor, iRefr.location);
		}
		refractedColor.scale(1-R);
		outIntensity.add(refractedColor);
		}
		
		} else if (outgoing.dot(record.normal) < 0){ //glass to air
			
		Vector3 negNorm = new Vector3(record.normal);
		negNorm.scale(-1);
			
		//Schlick's Approximation
		double R0 = Math.pow((nAir-nGlass)/(nGlass+nAir),2);
		double R = R0 + (1-R0)*(Math.pow(1-Math.cos(theta2), 5));
		double number = 1 - (Math.pow(nGlass, 2)*(1-Math.pow(newDirection.dot(negNorm), 2))/Math.pow(nAir, 2));
		
		reflected = new Ray(record.location, newDirection);
		reflected.makeOffsetRay();
		IntersectionRecord iRefl = new IntersectionRecord();
		
		if (number<0) {
		RayTracer.shadeRay(reflectedColor, scene, reflected, depth+1);
		} else {
		RayTracer.shadeRay(reflectedColor, scene, reflected, depth+1);
		scene.getFirstIntersection(iRefl, reflected);
		if (iRefl.surface != null){
		reflected.setAbsorption(iRefl.surface.getInsideAbsorption());
		reflected.attenuate(reflectedColor, iRefl.location);
		}
		reflectedColor.scale(R);
		outIntensity.add(reflectedColor);
		
		Vector3 rDirection = new Vector3(newDirection);
		rDirection.scale(nGlass/nAir);
		rDirection.scaleAdd(-1*(nGlass/nAir)*newDirection.dot(negNorm), negNorm);
		rDirection.scaleAdd(-1*Math.sqrt(number),negNorm);
		rDirection.normalize();
		
		refracted = new Ray(record.location, rDirection);
		refracted.makeOffsetRay();
		IntersectionRecord iRefr = new IntersectionRecord();
		
		RayTracer.shadeRay(refractedColor, scene, refracted, depth+1);
		scene.getFirstIntersection(iRefr, refracted);
		if (iRefr.surface != null){
		refracted.setAbsorption(iRefr.surface.getOutsideAbsorption());
		refracted.attenuate(refractedColor, iRefr.location);
		}
		refractedColor.scale(1-R);
		outIntensity.add(refractedColor);
		}
		}
		
	}