changes.
authoryeom <yeom>
Fri, 22 Jan 2010 00:44:27 +0000 (00:44 +0000)
committeryeom <yeom>
Fri, 22 Jan 2010 00:44:27 +0000 (00:44 +0000)
Robust/src/Benchmarks/mlp/raytracer/JGFRayTracerBench.java
Robust/src/Benchmarks/mlp/raytracer/RayTracer.java
Robust/src/Benchmarks/mlp/raytracer/Sphere.java

index f9bd8c2d4f3ca0433da73dba01897f7df9f13a48..027f05bfcebf4535b100add9370329a4b6dbfe96 100644 (file)
@@ -67,11 +67,11 @@ public class JGFRayTracerBench extends RayTracer {
        }
 
        public void JGFtidyup() {
-               scene = null;
-               lights = null;
-               prim = null;
-               tRay = null;
-               inter = null;
+//             scene = null;
+//             lights = null;
+//             prim = null;
+//             tRay = null;
+//             inter = null;
 
                // System.gc();
        }
index 8eeb4664b560c48de7483566502a030e355010ba..33898096da65473c184b6a52571ecd65165b8578 100644 (file)
@@ -1,4 +1,3 @@
-import java.io.FileOutputStream;
 
 
 /**************************************************************************
@@ -47,7 +46,7 @@ public class RayTracer {
         * Temporary ray
         */
 //     Ray tRay= new Ray();
-       Ray tRay;
+//     Ray tRay;
 
        /**
         * Alpha channel
@@ -59,19 +58,19 @@ public class RayTracer {
         * Null vector (for speedup, instead of <code>new Vec(0,0,0)</code>
         */
 //     static final Vec voidVec = new Vec();
-       static final Vec voidVec;
+//     static final Vec voidVec;
 
        /**
         * Temporary vect
         */
 //     Vec L = new Vec();
-       Vec L;
+//     Vec L;
 
        /**
         * Current intersection instance (only one is needed!)
         */
 //     Isect inter = new Isect();
-       Isect inter;
+//     Isect inter;
 
        /**
         * Height of the <code>Image</code> to be rendered
@@ -94,11 +93,11 @@ public class RayTracer {
        int numobjects;
        
        public RayTracer() {
-               tRay = new Ray();
+//             tRay = new Ray();
                alpha = 255 << 24;
-               voidVec = new Vec();
-               L = new Vec();
-               inter = new Isect();
+//             voidVec = new Vec();
+//             L = new Vec();
+//             inter = new Isect();
                checksum=0;
                datasizes = new int[2];
                datasizes[0] = 150;
@@ -195,29 +194,23 @@ public class RayTracer {
                int pixCounter = 0; // iterator
 
                // Rendering variables
-//             int x, y, red, green, blue;
+       //      int x, y, red, green, blue;
 //             double xlen, ylen;
+               
                Vec viewVec;
-
                viewVec = Vec.sub(view.at, view.from);
-
                viewVec.normalize();
-
                Vec tmpVec = new Vec(viewVec);
                tmpVec.scale(Vec.dot(view.up, viewVec));
-
                Vec upVec = Vec.sub(view.up, tmpVec);
                upVec.normalize();
-
                Vec leftVec = Vec.cross(view.up, viewVec);
                leftVec.normalize();
-
                double frustrumwidth = view.dist * Math.tan(view.angle);
-
                upVec.scale(-frustrumwidth);
                leftVec.scale(view.aspect * frustrumwidth);
-
-               Ray r = new Ray(view.from, voidVec);
+               
+//             Ray r = new Ray(view.from, new Vec(0,0,0));
 //             Vec col = new Vec();
 
                // Header for .ppm file
@@ -229,22 +222,28 @@ public class RayTracer {
 
                // For each line
                for (int y = interval.yfrom; y < interval.yto; y++) {
-//             for (int y = 0; y < 3; y++) {
-                       double ylen = (double) (2.0 * y) / (double) interval.width - 1.0;
+//             for (int y = 0; y < 10; y++) {
+                        double ylen = (double) (2.0 * y) / (double) interval.width - 1.0;
 //                      System.out.println("Doing line " + y);
                        // For each pixel of the line, launch parallel sese
                        sese parallel{
                                int tempArray[]=new int[interval.width];
+                               int line_checksum=0;
+                               Ray tRay = new Ray();
+                               Ray r = new Ray(view.from, new Vec(0,0,0));
+                               Isect inter=new Isect();
+                               
                                for (int x = 0; x < interval.width; x++) {
                                        Vec col = new Vec();
+                               
                                        double xlen = (double) (2.0 * x) / (double) interval.width - 1.0;                                       
                                        int pixCounter_t=y*(interval.width)+x;
-                                               
+
                                        r.D = Vec.comb(xlen, leftVec, ylen, upVec);
                                        r.D.add(viewVec);
                                        r.D.normalize();
                                        
-                                       col = trace(0, 1.0, r);
+                                       col = trace(0, 1.0, r,inter,new Ray(),new Vec());
                        
                                        // computes the color of the ray
                                        
@@ -257,11 +256,15 @@ public class RayTracer {
                                        int blue = (int) (col.z * 255.0);
                                        if (blue > 255)
                                                blue = 255;
-
-                                       checksum += red;
-                                       checksum += green;
-                                       checksum += blue;
                                        
+//                                     checksum += red;
+//                                     checksum += green;
+//                                     checksum += blue;
+                                       line_checksum += red;
+                                       line_checksum += green;
+                                       line_checksum += blue;
+                                       
+
                                        // RGB values for .ppm file
                                        // System.out.println(red + " " + green + " " + blue);
                                        // Sets the pixels
@@ -276,6 +279,10 @@ public class RayTracer {
                                    int pixCounter_t=y*(interval.width)+x;
                                        row[pixCounter_t] = tempArray[x];
                            }
+                               checksum+=line_checksum;
+                               if(y== (interval.yto-1)){
+                                       System.out.println("CHECKSUM="+checksum);
+                               }
                        }
                        
                } // end for (y)
@@ -283,8 +290,9 @@ public class RayTracer {
                System.out.println("END OF WORK");
                
        }
+       
 
-       boolean intersect(Ray r, double maxt) {
+       boolean intersect(Ray r, double maxt,Isect inter) {
                Isect tp;
                int i, nhits;
 
@@ -311,8 +319,8 @@ public class RayTracer {
         *            The ray
         * @return Returns 1 if there is a shadow, 0 if there isn't
         */
-       int Shadow(Ray r, double tmax) {
-               if (intersect(r, tmax))
+       int Shadow(Ray r, double tmax,Isect inter) {
+               if (intersect(r, tmax,inter))
                        return 0;
                return 1;
        }
@@ -352,7 +360,7 @@ public class RayTracer {
         * 
         * @return The color in Vec form (rgb)
         */
-       Vec shade(int level, double weight, Vec P, Vec N, Vec I, Isect hit) {
+       Vec shade(int level, double weight, Vec P, Vec N, Vec I, Isect hit,Ray tRay,Vec L) {
                double n1, n2, eta, c1, cs2;
                Vec r;
                Vec tcol;
@@ -371,7 +379,12 @@ public class RayTracer {
 
                // Computes the effectof each light
                for (l = 0; l < lights.length; l++) {
-                       L.sub2(lights[l].pos, P);
+//                     L.sub2(lights[l].pos, P);
+                       
+                       L.x=lights[l].pos.x-P.x;
+                       L.y=lights[l].pos.y-P.y;
+                       L.z=lights[l].pos.z-P.z;
+                       
                        if (Vec.dot(N, L) >= 0.0) {
                                t = L.normalize();
 
@@ -379,7 +392,7 @@ public class RayTracer {
                                tRay.D = L;
 
                                // Checks if there is a shadow
-                               if (Shadow(tRay, t) > 0) {
+                               if (Shadow(tRay, t,hit) > 0) {
                                        diff = Vec.dot(N, L) * surf.kd * lights[l].brightness;
 
                                        col.adds(diff, surf.color);
@@ -399,7 +412,7 @@ public class RayTracer {
                tRay.P = P;
                if (surf.ks * weight > 1e-3) {
                        tRay.D = SpecularDirection(I, N);
-                       tcol = trace(level + 1, surf.ks * weight, tRay);
+                       tcol = trace(level + 1, surf.ks * weight, tRay,hit,tRay,L);
                        col.adds(surf.ks, tcol);
                }
                if (surf.kt * weight > 1e-3) {
@@ -407,7 +420,7 @@ public class RayTracer {
                                tRay.D = TransDir(null, surf, I, N);
                        else
                                tRay.D = TransDir(surf, null, I, N);
-                       tcol = trace(level + 1, surf.kt * weight, tRay);
+                       tcol = trace(level + 1, surf.kt * weight, tRay,hit,tRay,L);
                        col.adds(surf.kt, tcol);
                }
 
@@ -421,7 +434,8 @@ public class RayTracer {
        /**
         * Launches a ray
         */
-       Vec trace(int level, double weight, Ray r) {
+       Vec trace(int level, double weight, Ray r,Isect inter,Ray tRay,Vec L) {
+               
                Vec P, N;
                boolean hit;
 
@@ -429,38 +443,18 @@ public class RayTracer {
                if (level > 6) {
                        return new Vec();
                }
-
-               hit = intersect(r, 1e6);
+               hit = intersect(r, 1e6,inter);
                if (hit) {
                        P = r.point(inter.t);
                        N = inter.prim.normal(P);
                        if (Vec.dot(r.D, N) >= 0.0) {
                                N.negate();
                        }
-                       return shade(level, weight, P, N, r.D, inter);
+                       return shade(level, weight, P, N, r.D, inter,tRay,L);
                }
+               
                // no intersection --> col = 0,0,0
-               return voidVec;
-       }
-
-       public static void main(String argv[]) {
-
-               RayTracer rt = new RayTracer();
-
-               // create the objects to be rendered
-               rt.scene = rt.createScene();
-
-               // get lights, objects etc. from scene.
-               rt.setScene(rt.scene);
-
-               // Set interval to be rendered to the whole picture
-               // (overkill, but will be useful to retain this for parallel versions)
-               Interval interval = new Interval(0, rt.width, rt.height, 0, rt.height,
-                               1);
-
-               // Do the business!
-               rt.render(interval);
-
+               return new Vec(0,0,0);
        }
 
 }
index 03feb1cc2aae4b5dd6043932357b4f4262ed67bc..3e32c0719dfbdc03970b0b94df28de3e84c351b2 100644 (file)
@@ -28,7 +28,7 @@ public class Sphere extends Primitive
 {
   Vec      c;
   double   r, r2;
-  Vec      v,b; // temporary vecs used to minimize the memory load
+//  Vec      v,b; // temporary vecs used to minimize the memory load
   
 
   public Sphere(Vec center, double radius) {
@@ -36,11 +36,51 @@ public class Sphere extends Primitive
     c = center;
     r = radius;
     r2 = r*r;
-    v=new Vec();
-    b=new Vec();
+//    v=new Vec();
+//    b=new Vec();
   }
   
+  public double dot(double x1, double y1, double z1, double x2, double y2, double z2){
+         
+         return x1*x2 + y1*y2 + z1*z2; 
+         
+  }
+     
   public Isect intersect(Ray ry) {
+         
+           
+//         Vec  v=new Vec();        
+           double b, disc, t;
+           Isect ip;
+//         Vec v=Vec.sub(c, ry.P);
+//         v.sub2(c, ry.P);
+           
+           double x=c.x-ry.P.x;
+           double y=c.y-ry.P.y;
+           double z=c.z-ry.P.z;
+           
+           b=dot(x,y,z,ry.D.x,ry.D.y,ry.D.z);
+//         b = Vec.dot(v, ry.D);
+           
+//         disc = b*b - Vec.dot(v, v) + r2;
+           disc = b*b -dot(x,y,z,x,y,z) + r2;
+           if (disc < 0.0) {
+             return null;
+           }
+           disc = Math.sqrt(disc);
+           t = (b - disc < 1e-6) ? b + disc : b - disc;
+           if (t < 1e-6) {
+             return null;
+           }
+           ip = new Isect();
+           ip.t = t;
+           ip.enter = dot(x,y,z,x,y,z) > r2 + 1e-6 ? 1 : 0;
+//         ip.enter = Vec.dot(v, v) > r2 + 1e-6 ? 1 : 0;
+           ip.prim = this;
+           ip.surf = surf;
+           return ip;
+           
+         /*
     double b, disc, t;
     Isect ip;
     v.sub2(c, ry.P);
@@ -60,6 +100,7 @@ public class Sphere extends Primitive
     ip.prim = this;
     ip.surf = surf;
     return ip;
+    */
   }
 
   public Vec normal(Vec p) {