コード例 #1
0
    Renderer(int line) {
      startLine = line;

      if (!scene.antiAliasing) {
        sampled = false;

        samples = Math.max(scene.raysPerPixel, DEBUG_samples);
        // Force it to be a perfect square
        samples = (int) Math.sqrt(samples);
        samples = samples * samples;

        imageSamples = new Double3D[samples];
        for (int i = 0; i < samples; i++) imageSamples[i] = new Double3D(0, 0, 0);

        // Make samples are in the range [0,1]
        Sample.multiJitter(imageSamples, samples);
        // Make samples are in the range [-2,2]
        Sample.cubicSplineFilter(imageSamples, samples);
        // Scale image samples to [-.5,.5] and adjust to worldCoords this should be +-.5 pixels
        // since we're in the middle of a pixel to begin with
        for (int i = 0; i < samples; i++) {
          imageSamples[i].x = widthRatio / 2 * (imageSamples[i].x / 4.0);
          imageSamples[i].y = heightRatio / 2 * (imageSamples[i].y / 4.0);
          // System.out.println("Jitter by: " + imageSamples[i] + " Pixel width: " + widthRatio + "
          // Pixel height: " + heightRatio );
        }
        imageSamples[0].x++;
        imageSamples[0].x--;
      }
    }
コード例 #2
0
    boolean transmissionDirection(Ray ray, HitRecord hit, Ray transmission) {
      double n = transmission.r.prevR.n;
      double nt = transmission.r.n;

      Double3D N = hit.normal;
      Double3D D = ray.dir;

      double cosine = -D.dot(N);
      if (n > nt) { // We're inside, so reverse the normal
        N = N.sMult(-1);
        cosine = -D.dot(N);
      }

      double nRatio = n / nt;

      double cosinePSq = 1.0 - nRatio * nRatio * (1.0f - cosine * cosine);

      // check for total internal refraction here
      if (cosinePSq < 0.0f) return false; // total internal refraction
      else {
        // D - N(N.D)
        // Double3D pOne = D.minus( N.sMult(N.dot(D)) ).sMult(nRatio);
        double inside = nRatio * cosine - Math.sqrt(cosinePSq);
        Double3D temp = D.sMult(nRatio).plus(N.sMult(inside)).getUnit();
        transmission.dir.x = temp.x;
        transmission.dir.y = temp.y;
        transmission.dir.z = temp.z;
      }
      return true;
    }
コード例 #3
0
    Renderer() {
      xMin = scene.camera.viewportLeft + 0.5;
      xMax = scene.camera.viewportRight;
      yMin = scene.camera.viewportBottom + 0.5;
      yMax = scene.camera.viewportTop;

      if (scene.antiAliasing) {
        samples = Math.max(scene.raysPerPixel, DEBUG_samples);
        // Force it to be a perfect square
        samples = (int) Math.sqrt(samples);
        samples = samples * samples;

        imageSamples = new Double3D[samples];
        for (int i = 0; i < samples; i++) imageSamples[i] = new Double3D(0, 0, 0);

        Sample.multiJitter(imageSamples, samples);

        // Samples are in the range [-2,2]
        Sample.cubicSplineFilter(imageSamples, samples);

        // Scale image samples to [-1,1]
        for (int i = 0; i < samples; i++) {
          imageSamples[i].x = widthRatio * imageSamples[i].x / 2.0;
          imageSamples[i].y = heightRatio * imageSamples[i].y / 2.0;
        }
      }
    }