Exemple #1
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);
            }
        public static OrthoNormalBasis makeFromWV(Vector3D w, Vector3D v)
        {
            OrthoNormalBasis onb = new OrthoNormalBasis();

            onb.w.set(w);
            onb.w.normalize();
            //w.normalize(onb.w);

            onb.u = v.cross(onb.w);
            onb.u.normalize();
            //Vector3.cross(v, onb.w, onb.u).normalize();

            onb.v = onb.w.cross(onb.v);
            //Vector3.cross(onb.w, onb.u, onb.v);

            return(onb);
        }
Exemple #3
0
        public virtual Vector3D perturbNormal(Vector3D normal, Vector3D localPoint, Primitive primitive)
        {
            RGBColor color;
            Vector3D newNormal;
            Vector3D gradientU;
            Vector3D gradientV;
            Vector3D r, s, t;
            Vector3D temp;
            double   height, heightDiff;
            double   dx, dy;
            double   x, y;
            double   rDamping, tDamping;
            double   rDampingAbs, tDampingAbs;
            double   rDampingTotal, tDampingTotal;
            double   rTotal, tTotal;

            s = normal;

            r = s.cross(new Vector3D(0, 1, 0));

            if (r.norm() < photontracer.SceneConstants.EPSILON)
            {
                r = new Vector3D(0, 1, 0);

                if (System.Math.Abs(s.y() - 1) < photontracer.SceneConstants.EPSILON)
                {
                    s = new Vector3D(0, 1, 0);
                }
                else
                {
                    s = new Vector3D(0, -1, 0);
                }
            }

            r.normalize();
            t = r.cross(s);
            t.normalize();

            gradientU = r.scaleNew(gradDisp().x());
            gradientV = t.scaleNew(gradDisp().y());

            color  = source().diffuseColor(primitive.mapTextureCoordinate(localPoint));
            height = color.average();

            dx = (samples().x() > 1.0)?(2.0 / (samples().x() - 1.0)):0;
            dy = (samples().y() > 1.0)?(2.0 / (samples().y() - 1.0)):0;

            rTotal = 0;
            tTotal = 0;

            rDampingTotal = 0;
            tDampingTotal = 0;

            y = -1.0;

            for (int iy = 0; iy < (int)samples().y(); iy++)
            {
                tDampingAbs = (1.0 - (y * y) * 0.8);

                if (tDampingAbs > (1.0 - photontracer.SceneConstants.EPSILON))
                {
                    tDampingAbs = 0;
                }

                tDamping = (y > 0)?tDampingAbs:-tDampingAbs;

                x = -1.0;

                for (int ix = 0; ix < (int)samples().x(); ix++)
                {
                    temp = gradientU.scaleNew(x);
                    temp.add(gradientV.scaleNew(y));
                    temp.add(localPoint);

                    color = source().diffuseColor(primitive.mapTextureCoordinate(temp));

                    heightDiff = height - color.average();

                    rDampingAbs = (1.0 - (x * x) * 0.8);

                    if (rDampingAbs > (1.0 - photontracer.SceneConstants.EPSILON))
                    {
                        rDampingAbs = 0;
                    }

                    rDamping = (x > 0)?rDampingAbs:-rDampingAbs;

                    rDampingTotal += rDampingAbs;
                    tDampingTotal += tDampingAbs;

                    rTotal += heightDiff * rDamping;
                    tTotal += heightDiff * tDamping;

                    x += dx;
                }

                y += dy;
            }

            r.scale(rTotal / rDampingTotal);
            t.scale(tTotal / tDampingTotal);

            newNormal = r.addNew(t);
            newNormal.scale(bumpFactor());
            newNormal.add(s);
            newNormal.normalize();

            return(newNormal);
        }