Example #1
0
 public virtual Vector3D perturbNormal(Vector3D normal, Vector3D localPoint, Primitive primitive)
 {
     if (bump_ != null)
     {
         return(bump_.perturbNormal(normal, localPoint, primitive));
     }
     else
     {
         return(normal);
     }
 }
Example #2
0
        public virtual void  addPrimitive(Primitive primitive)
        {
            primitiveList_.Add(primitive);

            boundingbox.include(primitive.getBoundingBox());
        }
Example #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);
        }
Example #4
0
 public virtual void  set(Vector3D intersectionPoint, Primitive intersectedObject, double lambda)
 {
     IntersectionPoint = intersectionPoint;
     IntersectedObject = intersectedObject;
     Lambda            = lambda;
 }
Example #5
0
 public Intersection(Vector3D intersectionPoint, Primitive intersectedObject, double lambda)
 {
     set(intersectionPoint, intersectedObject, lambda);
 }