Package ca.eandb.jmist.math

Examples of ca.eandb.jmist.math.SphericalCoordinates


      } while (n.dot(out) <= 0.0);

    } else { // specular

      do {
        SphericalCoordinates sc = new SphericalCoordinates(
            Math.atan(alpha * Math.sqrt(-Math.log(1.0 - ru))),
            2.0 * Math.PI * rv);

        Vector3 h = sc.toCartesian(basis);
        out = Optics.reflect(v, h);
      } while (n.dot(out) <= 0.0);

    }

View Full Code Here


     */
    @Override
    public Point2 project(HPoint3 q) {
      Vector3 v = q.isPoint() ? q.toPoint3().unitVectorFromOrigin()
                          : q.toVector3().unit();
      SphericalCoordinates sc = SphericalCoordinates.fromCartesian(v,
          BASIS);
      double x = sc.azimuthal() / (2.0 * Math.PI);
      double y = 0.5 * (1.0 - Math.cos(sc.polar()));
      if (x < 0.0) {
        x += 1.0;
      }
      return new Point2(x, y);
    }
View Full Code Here

     * @see ca.eandb.jmist.framework.path.PathNode#sample(double, double, double)
     */
    @Override
    public ScatteredRay sample(double ru, double rv, double rj) {
      Point2 p = pointOnImagePlane;
      SphericalCoordinates v = new SphericalCoordinates(
          Math.acos(1.0 - 2.0 * p.y()),
          2.0 * Math.PI * p.x());
      Ray3 ray = new Ray3(Point3.ORIGIN, v.toCartesian(BASIS));
      Color color = getWhite();
      double pdf = 1.0 / (4.0 * Math.PI);

      return ScatteredRay.diffuse(ray, color, pdf);
    }
View Full Code Here

  public Color bsdf(SurfacePoint x, Vector3 in, Vector3 out,
      WavelengthPacket lambda) {

    Vector3 p = out.unit().minus(in.unit()).unit();
    Basis3 basis = x.getShadingBasis();
    SphericalCoordinates omegaO = SphericalCoordinates.fromCartesian(out, basis).canonical();
    SphericalCoordinates omegaP = SphericalCoordinates.fromCartesian(p, basis).canonical();

    double NdotI = -basis.w().dot(in);
    double NdotO = basis.w().dot(out);
    double spf = 0.0;

    if (NdotI * NdotO < 0.0) {
      return lambda.getColorModel().getBlack(lambda);
    }

    double phiO = omegaO.azimuthal() < 0.0 ? omegaO.azimuthal() + 2.0 * Math.PI : omegaO.azimuthal();
    double phiP = omegaP.azimuthal() < 0.0 ? omegaP.azimuthal() + 2.0 * Math.PI : omegaP.azimuthal();
    phiP -= phiO;
    if (phiP < 0.0) { phiP += 2.0 * Math.PI; }

    int J = F.length;
    for (int j = 0; j < J; j++) {
      double Fj = MathUtil.bilinearInterpolate(
          0, 0.5 * Math.PI, 0.0, 2.0 * Math.PI, F[j],
          omegaO.polar(), phiO, false, true);

//      double t = (double) (F[j].rows() - 1) * omegaO.polar() / (0.5 * Math.PI);
//      if (Math.abs(t - Math.round(t)) < 0.05) {
//        Fj = 0;
//      }

//      double Gj = 0.0;
//
//      int K = u[j].length;
//      for (int k = 0; k < K; k++) {
//        double ujk = MathUtil.interpolate(0, 0.5 * Math.PI, u[j][k].elements(), omegaP.polar());
//        double vjk = MathUtil.interpolate(0, 2.0 * Math.PI, v[j][k].elements(), phiP);
//
//        Gj += ujk * vjk;
//      }
      double Gj = MathUtil.bilinearInterpolate(
          0, 0.5 * Math.PI, 0.0, 2.0 * Math.PI, G[j],
          omegaP.polar(), phiP, false, true);

      spf += Fj * Gj;
    }

    double intensity = spf / NdotI;

    double Fr = MathUtil.bilinearInterpolate(
        0, 0.5 * Math.PI, 0.0, 2.0 * Math.PI, Fc[0],
        omegaO.polar(), phiO);
    double Fg = MathUtil.bilinearInterpolate(
        0, 0.5 * Math.PI, 0.0, 2.0 * Math.PI, Fc[1],
        omegaO.polar(), phiO);
    double Fb = MathUtil.bilinearInterpolate(
        0, 0.5 * Math.PI, 0.0, 2.0 * Math.PI, Fc[2],
        omegaO.polar(), phiO);
    double Gr = MathUtil.bilinearInterpolate(
        0, 0.5 * Math.PI, 0.0, 2.0 * Math.PI, Gc[0],
        omegaP.polar(), phiP);
    double Gg = MathUtil.bilinearInterpolate(
        0, 0.5 * Math.PI, 0.0, 2.0 * Math.PI, Gc[1],
        omegaP.polar(), phiP);
    double Gb = MathUtil.bilinearInterpolate(
        0, 0.5 * Math.PI, 0.0, 2.0 * Math.PI, Gc[2],
        omegaP.polar(), phiP);

    double r = Fr * Gr * intensity;
    double g = Fg * Gg * intensity;
    double b = Fb * Gb * intensity;
//    double r = intensity;
View Full Code Here

  @Override
  public ScatteredRay emit(SurfacePoint x, WavelengthPacket lambda, double ru, double rv, double rj) {

    if (this.emittance != null) {

      SphericalCoordinates out = RandomUtil.diffuse(ru, rv);
      Ray3 ray = new Ray3(x.getPosition(), out.toCartesian(x.getShadingBasis()));

      if (x.getNormal().dot(ray.direction()) > 0.0) {
        return ScatteredRay.diffuse(ray, emittance.getColor(x, lambda), 1.0 / Math.PI);
      }
View Full Code Here

      WavelengthPacket lambda, double ru, double rv, double rj) {

    if (this.reflectance != null) {

      boolean fromFront = x.getNormal().dot(v) < 0.0;
      SphericalCoordinates out = RandomUtil.diffuse(ru, rv);
      if (!fromFront) {
        out = out.opposite();
      }

      Ray3 ray = new Ray3(x.getPosition(), out.toCartesian(x.getShadingBasis()));
      boolean toFront = ray.direction().dot(x.getNormal()) > 0.0;

      if (fromFront == toFront) {
        return ScatteredRay.diffuse(ray, reflectance.getColor(x, lambda), 1.0 / Math.PI);
      }
View Full Code Here

  /* (non-Javadoc)
   * @see ca.eandb.jmist.framework.RayShader#shadeRay(ca.eandb.jmist.math.Ray3, ca.eandb.jmist.framework.color.WavelengthPacket)
   */
  public Color shadeRay(Ray3 ray, WavelengthPacket lambda) {
    SphericalCoordinates sc = SphericalCoordinates.fromCartesian(ray.direction(), basis);
    double theta = -sc.azimuthal();
    double r = 0.5 * (1.0 - (Math.PI - sc.polar()) / Math.PI);
    Point2 uv = new Point2(
        0.5 + r * Math.cos(theta),
        0.5 + r * Math.sin(theta));
    return texture.evaluate(uv, lambda);
  }
View Full Code Here

  /* (non-Javadoc)
   * @see ca.eandb.jmist.framework.RayShader#shadeRay(ca.eandb.jmist.math.Ray3, ca.eandb.jmist.framework.color.WavelengthPacket)
   */
  public Color shadeRay(Ray3 ray, WavelengthPacket lambda) {
    SphericalCoordinates sc = SphericalCoordinates.fromCartesian(ray.direction(), basis);
    Point2 uv = new Point2(
        (sc.azimuthal() + Math.PI) / (2.0 * Math.PI),
        sc.polar() / Math.PI);
    return texture.evaluate(uv, lambda);
  }
View Full Code Here

  /* (non-Javadoc)
   * @see ca.eandb.jmist.framework.RayShader#shadeRay(ca.eandb.jmist.math.Ray3, ca.eandb.jmist.framework.color.WavelengthPacket)
   */
  public Color shadeRay(Ray3 ray, WavelengthPacket lambda) {
    if (ray.direction().dot(basis.w()) >= 0.0) {
      SphericalCoordinates sc = SphericalCoordinates.fromCartesian(ray.direction(), basis);
      Point2 uv = new Point2(
          (sc.azimuthal() + Math.PI) / (2.0 * Math.PI),
          2.0 * sc.polar() / Math.PI);
      return texture.evaluate(uv, lambda);
    } else {
      return background.shadeRay(ray, lambda);
    }
  }
View Full Code Here

  /* (non-Javadoc)
   * @see ca.eandb.jmist.framework.material.support.IsotropicMicrofacetModel#sample(double, double)
   */
  @Override
  public SphericalCoordinates sample(double ru, double rv) {
    return new SphericalCoordinates(
        Math.acos(Math.pow(ru, 1.0 / (alpha + 2.0))),
        2.0 * Math.PI * rv);
  }
View Full Code Here

TOP

Related Classes of ca.eandb.jmist.math.SphericalCoordinates

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.