/** * Changes the extents of the box as needed to include the given {@link org.sunflow.math.Vector3D point} into this box. * Does nothing if the parameter is <code>null</code>. * * @param p point to be included */ public void include(Vector3D p) { if (p != null) { if (p.x() < minimum.x()) { minimum.X = p.x(); } if (p.x() > maximum.x()) { maximum.X = p.x(); } if (p.y() < minimum.y()) { minimum.Y = p.y(); } if (p.y() > maximum.y()) { maximum.Y = p.y(); } if (p.z() < minimum.z()) { minimum.Z = p.z(); } if (p.z() > maximum.z()) { maximum.Z = p.z(); } } }
public Bump() { Source = null; GradDisp = new Vector3D(0.1, 0.1, 0); BumpFactor = 5.0f; Samples = new Vector3D(2, 2, 0); }
public Ring(Vector3D position, double radius, double height) : base(position) { init(); Radius = radius; Height = height; }
public Vector3D transform(Vector3D a, Vector3D dest) { dest.X = (a.x() * u.x()) + (a.y() * v.x()) + (a.z() * w.x()); dest.Y = (a.x() * u.y()) + (a.y() * v.y()) + (a.z() * w.y()); dest.Z = (a.x() * u.z()) + (a.y() * v.z()) + (a.z() * w.z()); return(dest); }
// Lambertian! Replace with general BSDF. public virtual void radianceEstimatePrecomputed(RGBColor rad, Vector3D position, Vector3D normal, float initialDist, float maxDist) { NearestPhotons np; // locate the nearest photon float r = initialDist; do { np = new NearestPhotons(1, r, position); locatePhotonsPrecomputed(normal, np, 1); r = (float)(r * 2.0); }while (np.found == 0 && r < maxDist); if (np.found > 0) { Photon p = getPhoton(np.indices[1]); rad.set(p.accumPower); } else { rad.set(0.0f); } }
public Bump(Bump other) { Source = other.source(); GradDisp = new Vector3D(other.gradDisp()); BumpFactor = other.bumpFactor(); Samples = new Vector3D(other.samples()); }
internal RGBColor getIrradiance(Sample x) { RGBColor temp = new RGBColor(irr); //RGBColor temp = new RGBColor(); //System.Diagnostics.Trace.WriteLine (transGradient[0].scaleNew ((float) (x.pi.x() - pi.x()))); //System.Diagnostics.Trace.Flush (); temp.addLerp((float)(x.pi.x() - pi.x()), transGradient[0]); temp.addLerp((float)(x.pi.y() - pi.y()), transGradient[1]); temp.addLerp((float)(x.pi.z() - pi.z()), transGradient[2]); //temp.addLerp ((float) (pi.x() - x.pi.x()), transGradient[0]); //temp.addLerp ((float) (pi.y() - x.pi.y()), transGradient[1]); //temp.addLerp ((float) (pi.z() - x.pi.z()), transGradient[2]); //temp.madd(x.pi.x() - pi.x(), transGradient[0]); //temp.madd(x.pi.y() - pi.y(), transGradient[1]); //temp.madd(x.pi.z() - pi.z(), transGradient[2]); Vector3D cross = ni.cross(x.ni); temp.addLerp((float)cross.x(), rotGradient[0]); temp.addLerp((float)cross.y(), rotGradient[1]); temp.addLerp((float)cross.z(), rotGradient[2]); //temp.madd(cross.x(), rotGradient[0]); //temp.madd(cross.y(), rotGradient[1]); //temp.madd(cross.z(), rotGradient[2]); //if (Double.IsNaN (temp.red ())) //{ // temp = null; //} return(temp); }
public Bump(Material source, Vector3D gradDisp, float bumpFactor, Vector3D samples) { Source = source; GradDisp = new Vector3D(gradDisp); BumpFactor = bumpFactor; Samples = new Vector3D(samples); }
/** * Creates an empty box. The minimum point will have all components set to positive infinity, and the maximum will * have all components set to negative infinity. */ public BoundingBox() { minimum = new Vector3D(Double.PositiveInfinity, Double.PositiveInfinity, Double.PositiveInfinity); maximum = new Vector3D(Double.NegativeInfinity, Double.NegativeInfinity, Double.NegativeInfinity); center = new Vector3D(); extents = new Vector3D(); }
public RGBColor getIrradiance(Vector3D p, Vector3D n, int depth) { Sample x = new Sample(p, n, depth); double w = root.find(x); //if (first != null) { // System.Diagnostics.Trace.WriteLine ("weight: " + w); } //System.Console.Out.WriteLine (x.irr + " " + w); if (x.irr == null) { return(null); } else { RGBColor a = new RGBColor(x.irr); a.scale(1.0f / (float)w); //x.irr.scale(1.0f / (float) w); return(a); } //return () ? null : x.irr.scaleNew(1.0f / (float) w); }
public static OrthoNormalBasis makeFromW(Vector3D w) { OrthoNormalBasis onb = new OrthoNormalBasis(); onb.w.set(w); onb.w.normalize(); //w.normalize(onb.w); if ((Math.Abs(onb.w.x()) < Math.Abs(onb.w.y())) && (Math.Abs(onb.w.x()) < Math.Abs(onb.w.z()))) { onb.v.X = 0; onb.v.Y = onb.w.z(); onb.v.Z = -onb.w.y(); } else if (Math.Abs(onb.w.y()) < Math.Abs(onb.w.z())) { onb.v.X = onb.w.z(); onb.v.Y = 0; onb.v.Z = -onb.w.x(); } else { onb.v.X = onb.w.y(); onb.v.Y = -onb.w.x(); onb.v.Z = 0; } onb.v.normalize(); onb.u = onb.v.cross(onb.w); //Vector3.cross(onb.v.normalize(), onb.w, onb.u); return(onb); }
public Vector3D untransform(Vector3D a, Vector3D dest) { dest.X = a.dot(u); dest.Y = a.dot(v); dest.Z = a.dot(w); return(dest); }
public override RGBColor diffuseColor(Vector3D localPoint) { int value; value = (int)System.Math.Round(localPoint.x() / spacing_) + (int)System.Math.Round(localPoint.y() / spacing_) + (int)System.Math.Round(localPoint.z() / spacing_); return(((value & 1) == 0)?diffuseColor():otherDiffuseColor()); }
public virtual Ray getRay(double u, double v) { Vector3D direction = new Vector3D(u, v, focalLength_); direction.normalize(); return(new Ray(new Vector3D(u, v, 0), direction)); }
public override RGBColor diffuseColor(Vector3D localPoint) { RGBColor color = material1_.diffuseColor(localPoint).scaleNew(amount1_); color.add(material2_.diffuseColor(localPoint).scaleNew(amount2_)); return(color); }
public Primitive(Vector3D position) { boundingbox = new BoundingBox(); Position = position; material_ = new Material(); }
public Primitive() { boundingbox = new BoundingBox(); Position = new Vector3D(); material_ = new Material(); }
public TextureMaterial() : base() { OtherDiffuseColor = new RGBColor(); Tiling = new Vector3D(1, 1, 0); Offset = new Vector3D(); Mirror = false; Tile = true; }
public TextureMaterial(Material material, RGBColor otherDiffuseColor, Vector3D tiling, Vector3D offset, bool mirror, bool tile, System.String filename) : base(material) { OtherDiffuseColor = new RGBColor(otherDiffuseColor); Tiling = tiling; Offset = offset; Mirror = mirror; Tile = tile; loadJPEG(filename); }
public override RGBColor diffuseColor(Vector3D localPoint) { Vector3D finalLocalPoint; finalLocalPoint = localPoint.scaleNew(tiling_); finalLocalPoint.add(offset_); return(lerpTexel(finalLocalPoint)); }
internal Sample(Vector3D p, Vector3D n, int depth) { pi = new Vector3D(p); ni = new Vector3D(n); ni.normalize(); irr = null; next = null; this.depth = depth; }
public TextureMaterial(RGBColor ambientColor, RGBColor diffuseColor, RGBColor specularColor, RGBColor transmissionColor, float phongExponent, float IOR, RGBColor otherDiffuseColor, Vector3D tiling, Vector3D offset, bool mirror, bool tile, System.String filename) : base(ambientColor, diffuseColor, specularColor, transmissionColor, phongExponent, IOR) { OtherDiffuseColor = otherDiffuseColor; Tiling = tiling; Offset = offset; Mirror = mirror; Tile = tile; loadJPEG(filename); }
public Vector3D transform(Vector3D a) { double x = (a.x() * u.x()) + (a.y() * v.x()) + (a.z() * w.x()); double y = (a.x() * u.y()) + (a.y() * v.y()) + (a.z() * w.y()); double z = (a.x() * u.z()) + (a.y() * v.z()) + (a.z() * w.z()); a.set(x, y, z); return(new Vector3D(a)); }
public void recalcMinMax() { Vector3D halfExtents = extents.scaleNew(1.0 / 2.0); minimum.set(center); minimum.sub(halfExtents); maximum.set(minimum); maximum.add(extents); }
public IrradianceCache(double tolerance, double minSpacing, BoundingBox sceneBounds) { this.tolerance = tolerance; invTolerance = 1.0 / tolerance; this.minSpacing = minSpacing; maxSpacing = 100.0 * minSpacing; Vector3D ext = sceneBounds.getExtents(); root = new Node(sceneBounds.getCenter(), 1.0001 * Math.Max(ext.x(), Math.Max(ext.y(), ext.z()))); }
public override Vector3D normal(Vector3D intersectionPoint, Vector3D viewPoint) { Vector3D normal = new Vector3D(ng); if (viewPoint.subNew(intersectionPoint).dot(normal) < 0.0) { normal.neg(); } return(normal); }
internal NearestPhotons(int nphots, double maxDist, Vector3D pos) { dist2 = new double[nphots + 1]; indices = new int[nphots + 1]; position = new Vector3D(pos); max = nphots; found = 0; gotHeap = false; dist2[0] = maxDist * maxDist; }
public override Vector3D mapTextureCoordinate(Vector3D localPoint) { double x = localPoint.x(); double y = localPoint.y(); double z = localPoint.z(); double elev = System.Math.Atan2(y, System.Math.Sqrt(x * x + z * z)) * invPI; double ang = System.Math.Atan2(z, x) * invPI; return(new Vector3D(ang, elev, 0)); }
public virtual Vector3D perturbNormal(Vector3D normal, Vector3D localPoint, Primitive primitive) { if (bump_ != null) { return(bump_.perturbNormal(normal, localPoint, primitive)); } else { return(normal); } }
// Lambertian! Replace with general BSDF. public virtual void radianceEstimate(RGBColor rad, Vector3D position, Vector3D normal, float maxDist, int noPhotons) { //float ALPHA = 0.918f; float MBETA = -1.953f; float DENOMFACTOR = 1.0f / (1.0f - (float)System.Math.Exp(MBETA)); NearestPhotons np = new NearestPhotons(noPhotons, maxDist, position); rad.set(0.0f); // locate the nearest photons locatePhotons(np, 1); // if less than MINPHOTONS return if (np.found < photontracer.SceneConstants.MIN_PHOTONS) { return; } Vector3D direction = new Vector3D(); //float mittrs = MBETA / (2.0f * (float) np.dist2[0]); float kdenom = (float)(1.0 / (1.1 * Math.Sqrt(np.dist2[0]))); // sum irrandiance from all photons for (int i = 1; i <= np.found; i++) { float cosNL; Photon p = getPhoton(np.indices[i]); // the toCartesian call and following if can be omitted (for speed) // if the scene does not have any thin surfaces p.toCartesian(direction); cosNL = (float)direction.dot(normal); //cosNL = -1.0f; if (cosNL < 0.0) { //float gaussWeight = 1.0f - (1.0f - (float) System.Math.Exp((float) p.position.distanceSqr(position) * mittrs)) * DENOMFACTOR; float coneWeight = 1.0f - (float)(p.position.distance(position) * kdenom); //rad.add(p.power.scaleNew((- cosNL) * gaussWeight)); //rad.add(p.power.scaleNew((- cosNL))); rad.add(p.power.scaleNew(coneWeight)); } } // estimate of density //rad.scale(ALPHA / (float) (System.Math.PI * np.dist2[0])); //rad.scale(1.0f / (float) (System.Math.PI * np.dist2[0])); rad.scale(1.0f / (float)((1.0f - 2.0f / (3.0f * 1.1f)) * System.Math.PI * np.dist2[0])); }