예제 #1
0
 public void updateArea() {
   Vector3 u = new Vector3(), v = new Vector3(), n = new Vector3();
   u.set(
       mesh.verts[3 * v1] - mesh.verts[3 * v0],
       mesh.verts[3 * v1 + 1] - mesh.verts[3 * v0 + 1],
       mesh.verts[3 * v1 + 2] - mesh.verts[3 * v0 + 2]);
   v.set(
       mesh.verts[3 * v2] - mesh.verts[3 * v0],
       mesh.verts[3 * v2 + 1] - mesh.verts[3 * v0 + 1],
       mesh.verts[3 * v2 + 2] - mesh.verts[3 * v0 + 2]);
   n.cross(u, v);
   area = 0.5 * n.length();
   oneOverArea = 1. / area;
 }
예제 #2
0
파일: Phong.java 프로젝트: mjs513/cs4620-1
  /**
   * Calculate the BRDF value for this material at the intersection described in record. Returns the
   * BRDF color in outColor.
   *
   * @param outColor Space for the output color
   * @param scene The scene
   * @param lights The lights
   * @param toEye Vector pointing towards the eye
   * @param record The intersection record, which hold the location, normal, etc.
   * @param depth The depth of recursive calls. You can ignore this parameter.
   * @param contribution The contribution of the current ray. You can ignore this parameter.
   * @param internal You can ignore this parameter.
   */
  public void shade(
      Color outColor,
      Scene scene,
      ArrayList<Light> lights,
      Vector3 toEye,
      IntersectionRecord record,
      int depth,
      double contribution,
      boolean internal) {
    for (Light light : lights) {
      if (!isShadowed(scene, light, record)) {
        L.sub(light.position, record.location);
        L.normalize();

        double dot = L.dot(record.normal);

        if (dot > 0) {
          outColor.r += dot * light.intensity.r * diffuseColor.r;
          outColor.g += dot * light.intensity.g * diffuseColor.g;
          outColor.b += dot * light.intensity.b * diffuseColor.b;
        }

        H.set(L);
        H.add(toEye);
        H.normalize();

        dot = H.dot(record.normal);

        if (dot > 0) {
          dot = Math.pow(dot, exponent);

          outColor.r += dot * light.intensity.r * specularColor.r;
          outColor.g += dot * light.intensity.g * specularColor.g;
          outColor.b += dot * light.intensity.b * specularColor.b;
        }
      }
    }
  }