示例#1
0
  private int getEnvironmentMap(Vector3f normal, int[] inPixels, int width, int height) {
    if (environmentMap != null) {
      float angle = (float) Math.acos(-normal.y);

      float x, y;
      y = angle / ImageMath.PI;

      if (y == 0.0f || y == 1.0f) x = 0.0f;
      else {
        float f = normal.x / (float) Math.sin(angle);

        if (f > 1.0f) f = 1.0f;
        else if (f < -1.0f) f = -1.0f;

        x = (float) Math.acos(f) / ImageMath.PI;
      }
      // A bit of empirical scaling....
      x = ImageMath.clamp(x * envWidth, 0, envWidth - 1);
      y = ImageMath.clamp(y * envHeight, 0, envHeight - 1);
      int ix = (int) x;
      int iy = (int) y;

      float xWeight = x - ix;
      float yWeight = y - iy;
      int i = envWidth * iy + ix;
      int dx = ix == envWidth - 1 ? 0 : 1;
      int dy = iy == envHeight - 1 ? 0 : envWidth;
      return ImageMath.bilinearInterpolate(
          xWeight,
          yWeight,
          envPixels[i],
          envPixels[i + dx],
          envPixels[i + dy],
          envPixels[i + dx + dy]);
    }
    return 0;
  }
示例#2
0
  private int getEnvironmentMapP(Vector3f normal, int[] inPixels, int width, int height) {
    if (environmentMap != null) {
      float x = 0.5f * (1 + normal.x);
      float y = 0.5f * (1 + normal.y);
      x = ImageMath.clamp(x * envWidth, 0, envWidth - 1);
      y = ImageMath.clamp(y * envHeight, 0, envHeight - 1);
      int ix = (int) x;
      int iy = (int) y;

      float xWeight = x - ix;
      float yWeight = y - iy;
      int i = envWidth * iy + ix;
      int dx = ix == envWidth - 1 ? 0 : 1;
      int dy = iy == envHeight - 1 ? 0 : envWidth;
      return ImageMath.bilinearInterpolate(
          xWeight,
          yWeight,
          envPixels[i],
          envPixels[i + dx],
          envPixels[i + dy],
          envPixels[i + dx + dy]);
    }
    return 0;
  }