Commits

zercha  committed c87a29d

Fixed shiny shadow bug, quads now have a dynamic jitter soft shadow filter, did a merge thingy... probably done something more that I have no memory of

  • Participants
  • Parent commits 43d8718

Comments (0)

Files changed (6)

File data/scenes/infinite-sphere.xml

 	
 		<!-- Light -->
 	<sphere position="-8 8 -8" radius="0.4" material="light" />
-	<sphere position="-28 14 0" radius="2" material="light" />
+	<sphere position="-28 14 0" radius="2" material="light" /> 
 <!--<sphere position="-1.8 0 -1.5" radius="0.05" material="light" />	-->
 	
 		<!-- Add room -->

File src/frontend/Settings.java

  * @author Mattias
  */
 public class Settings {
-	private File sceneFile = new File("data/scenes/ff-test.js");
+	private File sceneFile = new File("data/scenes/infinite-sphere.xml");
 	private Dimension resolution = new Dimension(800, 600);
 	private boolean debug;
 

File src/frontend/Startup.java

 	*/
 	
 	//I used this because XmlIO doesn't use for loops
-	/*
+	
 	private static Scene getEpicScene(){
 		Scene scene = new Scene();
 		
 		scene.addShape(plane4);
 		return scene;
 	}
-	*/
+
+	//I used this because XLIO doesn't use for loops
+	private static Scene getEpicScene2(){
+		Scene scene = new Scene();
+		
+		
+		
+		Plane plane = new Plane(new Vector3d(0, 0, 0), new Vector3d(0, 1, 0));
+		Material m = new Material();
+		m.setColor(new Color(150,150,150));
+		plane.setMaterial(m);
+
+		Sphere sphere = new Sphere(new Vector3d(0, 5, 0), 3);
+		Material m2 = new Material();
+		m2.setColor(new Color(210,0,0));
+		m2.setDiffuseRatio(0.86);
+		m2.setSpecularRatio(0.73);
+		m2.setReflectionRatio(0.3);
+		sphere.setMaterial(m2);
+
+		Quad light = new Quad(new Vector3d(60,80,0), new Vector3d(-0.7,-0.3, 0), 80, 80);
+		light.setMaterial(Material.getStandardLight());
+
+
+		Camera cam = new Camera(new Vector3d(-24,8,0),new Vector3d(1,0.0,0));
+		
+		Quad wall1 = new Quad(new Vector3d(10,14,0), new Vector3d(-0.7,-0.3,0),300,30);		
+		Quad wall2 = new Quad(new Vector3d(-33.5,115,0), new Vector3d(-0.7,-0.3,0),300,78);
+		Quad wall3 = new Quad(new Vector3d(10,14,-50), new Vector3d(-0.7,-0.3,0),40,300);	
+		Quad wall4 = new Quad(new Vector3d(10,14,50), new Vector3d(-0.7,-0.3,0),40,300);	
+		Quad wall5 = new Quad(new Vector3d(10,14,0), new Vector3d(-0.7,-0.3,0),10,300);
+		Quad wall6 = new Quad(new Vector3d(-7.5,55,0), new Vector3d(-0.7,-0.3,0),300,10);
+		
+		Quad glass1 = new Quad(new Vector3d(-7.5,55,30), new Vector3d(0.7,0.3,0),60,70);
+		Quad glass2 = new Quad(new Vector3d(-7.5,55,-30), new Vector3d(0.7,0.3,0),60,70);
+
+		
+//		Quad plane1 = new Quad(new Vector3d(-15,29,0), new Vector3d(1,0,0),1000,1000);		
+//		Quad plane2 = new Quad(new Vector3d(0,29,15), new Vector3d(0,0,-1),1000,1000);
+//		Quad plane3 = new Quad(new Vector3d(15,29,0), new Vector3d(-1,0,0),1000,1000);
+//		Quad plane4 = new Quad(new Vector3d(0,29,-15), new Vector3d(0,0,1),1000,1000);
+		
+		Material m3 = new Material();
+		m3.setColor(new Color(150,150,150));
+		m3.setReflectionRatio(0);
+		wall1.setMaterial(m3);
+		wall2.setMaterial(m3);
+		wall3.setMaterial(m3);
+		wall4.setMaterial(m3);
+		wall5.setMaterial(m3);
+		wall6.setMaterial(m3);
+		
+		Material glred = new Material();
+		glred.setColor(Color.red.darker());
+		glred.setReflectionRatio(0.3);
+		glred.setRefractionRatio(0.7);
+		glred.setRefractiveIndex(1);
+		glass1.setMaterial(glred);
+		
+		Material glgreen = new Material();
+		glgreen.setColor(Color.green.darker());
+		glgreen.setReflectionRatio(0.3);
+		glgreen.setRefractionRatio(0.7);
+		glgreen.setRefractiveIndex(1);
+		glass2.setMaterial(glgreen);
+
+//		plane1.setMaterial(m3);
+//		plane2.setMaterial(m3);
+//		plane3.setMaterial(m3);
+//		plane4.setMaterial(m3);
+		
+		
+		scene.setCamera(cam);
+		scene.addShape(sphere);
+		scene.addShape(plane);
+		scene.addShape(light);
+		scene.addShape(wall1);
+		scene.addShape(wall2);
+		scene.addShape(wall3);
+		scene.addShape(wall4);
+		scene.addShape(wall5);
+		scene.addShape(wall6);
+		scene.addShape(glass1);
+		scene.addShape(glass2);
+		return scene;
+	}
+
+	
 	
 	/* TODO: FireFly: Translate to XML scene. */
-	/*
+	
 	@SuppressWarnings("unused")
 	private static Scene getScene(){
 		Scene scene = new Scene();
 		
 		return scene;
 	}
-	*/
+	
+	
 	
 	public static void main(String[] args) {
 		final Settings settings = new Settings();

File src/raytracer/RaySettings.java

 	public int shadowQuality = 1;
 	public int depthOfFieldQuality = 1;
 	public MultiRayType antiAliasingType = MultiRayType.Normal;
-	public MultiRayType softShadowType = MultiRayType.Normal;
+	public MultiRayType softShadowType = MultiRayType.Jitter;
 	public MultiRayType depthOfFieldType = MultiRayType.Normal;
 
 	public RaySettings(Settings settings) {

File src/raytracer/Raytracer.java

 	private VectorColor shadowRayIntersection(final Ray r, Shape light){
 		IntersectionData data = light.getIntersection(r); // Position intersecting light source
 		VectorColor color = light.getMaterial().getColor(data);
+
 		if (data == null) return color;
 
 		List<Shape> shapes = scene.getIntersectingShapes(r, data.getPosition()); // Recieve all intersecting shapes
 				double l1 = o1.getPosition().sub(r.getOrigin()).length();
 				double l2 = o2.getPosition().sub(r.getOrigin()).length();
 
-				return (int) (10000 * (l1 - l2));
+				return (int) (10000 * (l2 - l1));
 			}
 		});
 
 		double distance = (r.origin.sub(light.getPosition())).length();
 		double alpha = 1;
-		int amount = 1;
+//		int amount = 1;
 		for (int i = 0; i < shapes.size(); i++) {
 			if(shapes.get(i) == light)
 				continue;
 						return VectorColor.BLACK;
 					}
 					else{
-						color = color.add(data.getShape().getMaterial().getColor(data)).mul(refractiveRatio);
-						alpha *= 1-refractiveRatio;
-						amount++;
+						color = color.add(data.getShape().getMaterial().getColor(data)).mul(1-refractiveRatio);
+						color = color.div(2-refractiveRatio);
+//						alpha *= 1-refractiveRatio;
+//						amount++;
 //						color = color.mul(refractiveRatio);
 					}
 				}
 			}
 		}
-		alpha = 1 - alpha;
-		color.div(amount);
-		color.mul(alpha);
+//		alpha = 1 - alpha;
+//		color.div(amount);
+//		color.mul(alpha);
 		return color;
 	}
 	
 				} else {
 					System.err.println("Soft shadow type \"" + settings.softShadowType + "\" not supported.");
 				}
+				int sharpness = 90; //Used in Jitter mode to control how spreaded the jitter should be
 				for (int i = 0; i < settings.shadowQuality; i++) {
 					for (int j = 0; j < settings.shadowQuality; j++) {
 						// "j + 0.5" moves to the center of the grid, then the random value can't get outside of the grid and position will be in the center if randomness is disabled and 1x1 SS is used.
 						// "settings.shadowQuality - 0.5" start position to the upper left corner.
+//						tmpPos = quadLight.getPosition()
+//								.add(dx.mul(quadLight.getWidth() * ((i + 0.5 + (random ? (Math.random() * 2 - 1) / 2 : 0)) / settings.shadowQuality - 0.5)))
+//								.add(dy.mul(quadLight.getHeight() * ((j + 0.5 + (random ? (Math.random() * 2 - 1) / 2 : 0)) / settings.shadowQuality - 0.5)));
 						tmpPos = quadLight.getPosition()
-								.add(dx.mul(quadLight.getWidth() * ((i + 0.5 + (random ? (Math.random() * 2 - 1) / 2 : 0)) / settings.shadowQuality - 0.5)))
-								.add(dy.mul(quadLight.getHeight() * ((j + 0.5 + (random ? (Math.random() * 2 - 1) / 2 : 0)) / settings.shadowQuality - 0.5)));
-
+						.add(dx.mul(quadLight.getWidth() * (- 0.5 + (i+1.0)/(settings.shadowQuality+1)  + ((random ? (Math.random() * 2 - 1) / 2 : 0) / (settings.shadowQuality*sharpness)))))
+						.add(dy.mul(quadLight.getHeight() * (- 0.5 + (j+1.0)/(settings.shadowQuality+1) + ((random ? (Math.random() * 2 - 1) / 2 : 0) / (settings.shadowQuality*sharpness)))));
+						
+//						System.out.println(- 0.5 + (i+1)/(settings.shadowQuality+1));
 						tmpDir = (tmpPos.sub(id.getPosition())).normalize();
 						
 						color = color.add(shadowRayIntersection(new Ray(id.getPosition().add(tmpDir.mul(EPSILON)),tmpDir), light));
 				avgLightRatio = avgLightRatio.add(tmpLightRatio);
 			}
 		}
+		color  = color.mul(1-shape.getMaterial().getReflectionRatio()-shape.getMaterial().getRefractionRatio());
 		avgLightRatio = avgLightRatio.div(scene.getLights().size()); //Zercha säger att det ska finnas(kommer att påverkas av en light sensitivity variabel)
 //		color *= scene.settings.lightSensitivity;  // Zetro säger att denna ska vara i slutet. Zetro ändrar sig... Denna ska ligga i getPixelAt()
 

File src/scene/shapes/Material.java

 	 */
 	public void setLight(boolean b) {isLight = b;}
 	
-//	public void setColor(Color color){
-//		 setColor(new VectorColor(color.getRed()/255.0, color.getGreen()/255.0, color.getBlue()/255.0));
-//	}
+	public void setColor(Color color){
+		 setColor(new VectorColor(color.getRed()/255.0, color.getGreen()/255.0, color.getBlue()/255.0));
+	}
 
 	public void setColor(int red, int green, int blue){
 		 this.setColor(new VectorColor(red/255.0, green/255.0, blue/255.0));