Example #1
0
        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);
        }
Example #2
0
            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);
            }
Example #3
0
        // 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 CompositeMaterial(RGBColor ambientColor, RGBColor diffuseColor, RGBColor specularColor, RGBColor transmissionColor, float phongExponent, float IOR, Material material1, Material material2, float amount1, float amount2) : base(ambientColor, diffuseColor, specularColor, transmissionColor, phongExponent, IOR)
 {
     Material1 = material1;
     Material2 = material2;
     Amount1   = amount1;
     Amount2   = amount2;
 }
Example #5
0
 public TextureMaterial() : base()
 {
     OtherDiffuseColor = new RGBColor();
     Tiling            = new Vector3D(1, 1, 0);
     Offset            = new Vector3D();
     Mirror            = false;
     Tile = true;
 }
        public override RGBColor diffuseColor(Vector3D localPoint)
        {
            RGBColor color = material1_.diffuseColor(localPoint).scaleNew(amount1_);

            color.add(material2_.diffuseColor(localPoint).scaleNew(amount2_));

            return(color);
        }
Example #7
0
 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;
 }
Example #8
0
 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);
 }
Example #9
0
        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);
        }
Example #10
0
        // 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]));
        }
Example #11
0
        public Material()
        {
            AmbientColor      = RGBColor.RGBblack();
            DiffuseColor      = RGBColor.RGBblack();
            SpecularColor     = RGBColor.RGBwhite();
            TransmissionColor = RGBColor.RGBwhite();

            PhongExponent = 8;
            setIOR(1);

            Bump = null;
        }
Example #12
0
        public Material(RGBColor ambientColor, RGBColor diffuseColor, RGBColor specularColor, RGBColor transmissionColor, float phongExponent, float IOR)
        {
            AmbientColor      = ambientColor;
            DiffuseColor      = diffuseColor;
            SpecularColor     = specularColor;
            TransmissionColor = transmissionColor;

            PhongExponent = phongExponent;
            setIOR(IOR);

            Bump = null;
        }
Example #13
0
        private RGBColor getColor(bool wrapped, int u, int v)
        {
            RGBColor texel;
            int      RGB;

            if (!tile() && wrapped)
            {
                return(diffuseColor());
            }

            RGB = texture.GetPixel(u, v).ToArgb();

            texel = new RGBColor((RGB >> 16) & 0xff, (RGB >> 8) & 0xff, RGB & 0xff);

            return(texel.convertFrom24Bits());
        }
Example #14
0
            internal Sample(Vector3D p, Vector3D n, double r0, RGBColor irr, RGBColor[] rotGradient, RGBColor[] transGradient, int depth)
            {
                pi = new Vector3D(p);
                ni = new Vector3D(n);
                ni.normalize();
                invR0              = 1.0 / r0;
                this.irr           = new RGBColor(irr);
                this.rotGradient   = rotGradient;
                this.transGradient = transGradient;
                this.depth         = depth;
                next = null;

                //if (Double.IsNaN (transGradient[0].red ()))
                //{
                //	invR0 = 0.0;
                //}
            }
Example #15
0
        public void insert(Vector3D p, Vector3D n, double r0, RGBColor irr, RGBColor[] rotGradient, RGBColor[] transGradient, int depth)
        {
            Node node = root;

            //r0 = MathUtils.clamp(r0 * tolerance, minSpacing, maxSpacing) * invTolerance;
            r0 = r0 * tolerance;

            if (r0 > minSpacing)
            {
                //	System.Diagnostics.Trace.WriteLine ("jatak");
            }

            r0 = (r0 < minSpacing) ? minSpacing : r0;
            r0 = (r0 > maxSpacing) ? maxSpacing : r0;

            r0 *= invTolerance;

            if (root.isInside(p))
            {
                while (node.sideLength >= (4.0 * r0 * tolerance))
                {
                    int k = 0;
                    k |= (p.x() > node.center.x()) ? 1 : 0;
                    k |= (p.y() > node.center.y()) ? 2 : 0;
                    k |= (p.z() > node.center.z()) ? 4 : 0;
                    if (node.children[k] == null)
                    {
                        Vector3D c = new Vector3D(node.center);
                        c.X = c.x() + (((k & 1) == 0) ? -node.quadSideLength : node.quadSideLength);
                        c.Y = c.y() + (((k & 2) == 0) ? -node.quadSideLength : node.quadSideLength);
                        c.Z = c.z() + (((k & 4) == 0) ? -node.quadSideLength : node.quadSideLength);
                        //c.X +=
                        //c.Y += ((k & 2) == 0) ? -node.quadSideLength : node.quadSideLength;
                        //c.Z += ((k & 4) == 0) ? -node.quadSideLength : node.quadSideLength;
                        node.children[k] = new Node(c, node.halfSideLength);
                    }
                    node = node.children[k];
                }
            }
            Sample s = new Sample(p, n, r0, irr, rotGradient, transGradient, depth);

            s.next     = node.first;
            node.first = s;
        }
Example #16
0
        public Material(Material other)
        {
            AmbientColor      = new RGBColor(other.ambientColor());
            DiffuseColor      = new RGBColor(other.diffuseColor());
            SpecularColor     = new RGBColor(other.specularColor());
            TransmissionColor = new RGBColor(other.transmissionColor());

            PhongExponent = other.phongExponent();
            setIOR(other.IOR());

            if (other.bump() != null)
            {
                Bump = new Bump(other.bump());
            }
            else
            {
                Bump = null;
            }
        }
Example #17
0
        public virtual Photon store(RGBColor power, Vector3D position, Vector3D direction, Vector3D surfaceNormal)
        {
            storedPhotons_++;

            Photon photon = new Photon();

            photon.precomputedIrradiance = false;

            photon.power    = new RGBColor(power);
            photon.position = new Vector3D(position);

            photon.number = storedPhotons_;

            photon.toSpherical(direction);
            photon.surfaceToSpherical(surfaceNormal);

            position.updateMinMax(bboxMin, bboxMax);

            photons.Add(photon);

            return(photon);
        }
Example #18
0
 public CheckerMaterial(Material material, RGBColor otherDiffuseColor, float spacing) : base(material)
 {
     OtherDiffuseColor = new RGBColor(otherDiffuseColor);
     Spacing           = spacing;
 }
Example #19
0
 public CheckerMaterial(RGBColor ambientColor, RGBColor diffuseColor, RGBColor specularColor, RGBColor transmissionColor, float phongExponent, float IOR, RGBColor otherDiffuseColor, float spacing) : base(ambientColor, diffuseColor, specularColor, transmissionColor, phongExponent, IOR)
 {
     OtherDiffuseColor = otherDiffuseColor;
     Spacing           = spacing;
 }
Example #20
0
 public CheckerMaterial() : base()
 {
     OtherDiffuseColor = new RGBColor();
     Spacing           = 1;
 }
Example #21
0
 public Vector3D(RGBColor source)
 {
     set(source.red(), source.green(), source.blue());
 }