コード例 #1
0
ファイル: PointLight.cs プロジェクト: segafult/SCSRaytracer
 public PointLight(RGBColor c, float i, Point3D l)
 {
     _color = new RGBColor(c);
     _intensity = i;
     _location = new Point3D(l);
     _castsShadows = false;
 }
コード例 #2
0
 public override float EvaluateImplicitFunction(Point3D p)
 {
     float xsqr = p.X * p.X;
     float ysqr = p.Y * p.Y;
     float ln = (float)Math.Log(p.Z + 3.2);
     return xsqr + ysqr - ln * ln - 0.02f;
 }
コード例 #3
0
ファイル: PointLight.cs プロジェクト: segafult/SCSRaytracer
 public PointLight(Point3D l)
 {
     _color = new RGBColor(1, 1, 1);
     _intensity = 0.5f;
     _location = new Point3D(l);
     _castsShadows = false;
 }
コード例 #4
0
 public override float EvaluateImplicitFunction(Point3D p)
 {
     Vector3 sqrd = p.Coordinates * p.Coordinates;
     Vector3 fourpow = sqrd * sqrd;
     float sumsqrd = sqrd.X + sqrd.Y + sqrd.Z;
     return (fourpow.X + fourpow.Y + fourpow.Z + (a * (sumsqrd * sumsqrd)) + (b * sumsqrd) + c);
 }
コード例 #5
0
ファイル: Triangle.cs プロジェクト: segafult/SCSRaytracer
 public Triangle(Point3D vertex1Arg, Point3D vertex2Arg, Point3D vertex3Arg)
 {
     //Shallow copy to save memory. Mesh container class handles duplicate vertices for memory savings.
     Vertex1 = vertex1Arg;
     Vertex2 = vertex2Arg;
     Vertex3 = vertex3Arg;
 }
コード例 #6
0
 public override float EvaluateImplicitFunction(Point3D p)
 {
     Vector3 sqrd = p.Coordinates * p.Coordinates;
     float cbedz = sqrd.Z * p.Z;
     float cubeterm = (sqrd.X + NINEOVERFOUR * sqrd.Y + sqrd.Z - 1);
     return (cubeterm * cubeterm * cubeterm) - (sqrd.X * cbedz) - (NINEOVEREIGHTY * sqrd.Y * cbedz);
 }
コード例 #7
0
 public override float EvaluateImplicitFunction(Point3D p)
 {
     Vector3 one = p.Coordinates;
     Vector3 sqr = one * one;
     float t1 = Convert.ToSingle((sqr.X + sqr.Y + sqr.Z < 0.2));
     float t2 = (Convert.ToSingle(sqr.Y + sqr.Z < 0.08) * Convert.ToSingle(one.X < 0.4) * Convert.ToSingle(one.X > 0));
     //float t3 = Convert.ToSingle(Math.Pow(one.X,2+4*sqr.Y)<(1-Math.Abs(one.Z))
     return t1 + t2;
 }
コード例 #8
0
        public override float EvaluateImplicitFunction(Point3D p)
        {
            float x_sqr = p.X * p.X;
            float y_sqr = p.Y * p.Y;
            float z_sqr = p.Z * p.Z;
            float phi_sqr = PHI * PHI;
            float fin = x_sqr + y_sqr + z_sqr - 1.1f;

            return (4.0f * (phi_sqr * x_sqr - y_sqr) * (phi_sqr * y_sqr - z_sqr) * (phi_sqr * z_sqr - x_sqr)) - (1.0f + 2.0f * phi_sqr) * (fin * fin);
        }
コード例 #9
0
        public override float EvaluateImplicitFunction(Point3D p)
        {
            Vector3 sqrd = p.Coordinates * p.Coordinates;
            Vector3 minusone = sqrd - new Vector3(1);
            float zeropoint8sqr = 0.8f * 0.8f;

            float t1 = sqrd.X + sqrd.Y - zeropoint8sqr;
            float t2 = sqrd.Y + sqrd.Z - zeropoint8sqr;
            float t3 = sqrd.Z + sqrd.X - zeropoint8sqr;

            return (t1 * t1 + minusone.Z * minusone.Z) * (t2 * t2 + minusone.X * minusone.X) * (t3 * t3 + minusone.Y * minusone.Y) - r;
        }
コード例 #10
0
        public override Point2D GetUV(Point3D hitPoint)
        {
            //Map hit point to a unit sphere by normalizing vector from origin to hit point.
            //Vector3 hitNormalized = Vector3.Normalize(hitPoint.Coordinates);
            Vect3D hitNormalized = new Vect3D(hitPoint).Hat();

            float phi = (float)Math.Atan2(hitNormalized.X, hitNormalized.Z) + FastMath.FPI;
            float omega = (float)Math.Acos(hitNormalized.Y);

            //Calculate spherical UV coordinates
            float u = phi * FastMath.FINVTWOPI;
            float v = 1 - (omega * FastMath.FINVPI);

            return new Point2D(u, v);
        }
コード例 #11
0
ファイル: World.cs プロジェクト: segafult/SCSRaytracer
        /// <summary>
        /// Step 1 in rendering pipeline.
        /// Generic intersection detection for objectList called by a Tracer, returns ShadeRec describing intersection.
        /// </summary>
        /// <param name="ray">Ray for intersection calculation</param>
        /// <returns>ShadeRec object with all relevant information about object that was intersected for generating
        /// pixel data</returns>
        public ShadeRec HitObjects(Ray ray)
        {
            ShadeRec sr = new ShadeRec(this); // create shaderec

            // set normal and local hit point to non-null values
            Normal normal = new Normal();
            Point3D local_hit_point = new Point3D();

            float t = GlobalVars.K_HUGE_VALUE - 1.0f; // t value for corrent object
            float tmin = GlobalVars.K_HUGE_VALUE; //  current lowest t value
            int num_objects = _renderList.Count; // store count of objects to minimize unecessary member access
            Material closestmat = null; // material reference for closest object

            //Find the closest intersection point along the given ray
            for(int i = 0; i < num_objects; i++)
            {
                // Intersect each object in render list
                // First term evaluated first, therefore (t < tmin) will be doing a comparison of t value
                // of present object vs minimum t value.
                if (_renderList[i].Hit(ray, ref t, ref sr) && (t < tmin))
                {
                    sr.HitAnObject = true; // at least one intersection has occurred

                    // store temporary references to information about current object with minimum t
                    tmin = t;
                    closestmat = sr.ObjectMaterial;
                    sr.HitPoint = ray.Origin + t * ray.Direction; // calculate hit point in world space by adding t*direction to origin
                    normal = sr.Normal;
                    local_hit_point = sr.HitPointLocal;
                }
            }

            //If we hit an object, store local vars for closest object with ray intersection in sr before returning
            if(sr.HitAnObject)
            {
                sr.TMinimum = tmin;
                sr.Normal = normal;
                sr.HitPointLocal = local_hit_point;
                sr.ObjectMaterial = closestmat;
            }

            return (sr);
        }
コード例 #12
0
        public override bool Hit(Ray r, ref float tMin, ref ShadeRec sr)
        {
            float t = GlobalVars.K_HUGE_VALUE;
            Normal normal = new Normal();
            Point3D localHitPoint = new Point3D();
            bool hit = false;
            tMin = GlobalVars.K_HUGE_VALUE;
            int countObjects = containedObjects.Count;
            Material closestObjectMaterial = null;

            //Traverse the list of renderable objects, and test for collisions in the same manner as in the world
            //hit function
            for(int i = 0; i < countObjects; i++)
            {
                if(containedObjects[i].Hit(r, ref t, ref sr) && (t<tMin))
                {
                    hit = true;
                    tMin = t;
                    closestObjectMaterial = sr.ObjectMaterial;
                    normal = sr.Normal;
                    localHitPoint = sr.HitPointLocal;
                }
            }

            if(hit)
            {
                sr.TMinimum = tMin;
                sr.Normal = normal;
                sr.HitPointLocal = localHitPoint;
                sr.ObjectMaterial = closestObjectMaterial;
            }

            return hit;
        }
コード例 #13
0
 //Evaluates given implicit function at a point, should be overridden in subclasses.
 public virtual float EvaluateImplicitFunction(Point3D p)
 {
     return 1.0f;
 }
コード例 #14
0
 public override float EvaluateImplicitFunction(Point3D p)
 {
     Vector3 pretranslation = p.Coordinates - disp;
     Vector3 tmp = pretranslation * pretranslation;
     return tmp.X + tmp.Y + tmp.Z - r * r;
 }
コード例 #15
0
 protected override float EvaluateDistanceFunction(Point3D p, Vect3D d, ref float cur)
 {
     //Translate the point
     cur = EvaluateImplicitFunction(p);
     return (p.Coordinates - disp).Length() - r;
 }
コード例 #16
0
        //Approximates the gradient of F(p) at a given point p
        protected virtual Normal ApproximateNormal(Point3D p, Vect3D rd)
        {
            float f = EvaluateImplicitFunction(p);
            float f_x = EvaluateImplicitFunction(new Point3D(p.X + EPSILON, p.Y, p.Z));
            float f_y = EvaluateImplicitFunction(new Point3D(p.X, p.Y + EPSILON, p.Z));
            float f_z = EvaluateImplicitFunction(new Point3D(p.X, p.Y, p.Z + EPSILON));

            //Compute vector for normal
            Vect3D raw_normal = (new Vect3D((float)(f_x - f), (float)(f_y - f), (float)(f_z - f))).Hat();

            //Check if dot product is positive, if so, flip the vector so it's facing the ray origin
            if(raw_normal * rd.Hat() > 0.0f) { raw_normal = -raw_normal; }
            return (new Normal(raw_normal));
        }
コード例 #17
0
ファイル: Torus.cs プロジェクト: segafult/SCSRaytracer
        private Normal CalculateNormal(Point3D point)
        {
            Normal result = new Normal();

            float param_squared = _a * _a + _b * _b;

            float x = point.X;
            float y = point.Y;
            float z = point.Z;
            float sum_squared = x * x + y * y + z * z;

            result.X = 4.0f * x * (sum_squared - param_squared);
            result.Y = 4.0f * y * (sum_squared - param_squared + 2.0f * _a * _a);
            result.Z = 4.0f * z * (sum_squared - param_squared);
            result.Normalize();

            return result;
        }
コード例 #18
0
ファイル: Normal.cs プロジェクト: segafult/SCSRaytracer
 public Normal(Point3D p)
 {
     _coords = p.Coordinates;
 }
コード例 #19
0
        protected virtual float EvaluateImplicitFunctionDerivative(Point3D point, Vect3D direction)
        {
            //Find the points just in front of the provided point, and just behind it along the ray
            Point3D behind = point + (direction * EPSILON);
            Point3D infront = point - (direction * EPSILON);

            //Slope = rise over run
            return (EvaluateImplicitFunction(infront) - EvaluateImplicitFunction(behind)) * INVTWOEPSILON;
        }
コード例 #20
0
ファイル: Vect3D.cs プロジェクト: segafult/SCSRaytracer
 public Vect3D(Point3D point)
 {
     _coords = point.Coordinates;
 }
コード例 #21
0
ファイル: Mapper.cs プロジェクト: segafult/SCSRaytracer
 public abstract Point2D GetUV(Point3D hitPoint);
コード例 #22
0
ファイル: Triangle.cs プロジェクト: segafult/SCSRaytracer
        private Point3D Vertex1, Vertex2, Vertex3; //Vertexes

        #endregion Fields

        #region Constructors

        public Triangle()
        {
            Vertex1 = new Point3D(100, 0, 0);
            Vertex2 = new Point3D(-100, 0, 0);
            Vertex3 = new Point3D(0, 100, 0);
        }
コード例 #23
0
ファイル: Triangle.cs プロジェクト: segafult/SCSRaytracer
 //Gets and sets
 public void SetVertices(Point3D v1_arg, Point3D v2_arg, Point3D v3_arg)
 {
     Vertex1 = v1_arg;
     Vertex2 = v2_arg;
     Vertex3 = v3_arg;
 }
コード例 #24
0
ファイル: Triangle.cs プロジェクト: segafult/SCSRaytracer
 public void SetSingleVertices(int vert, Point3D v)
 {
     switch (vert)
     {
         case 1: Vertex1 = v;
             break;
         case 2: Vertex2 = v;
             break;
         case 3: Vertex3 = v;
             break;
     }
 }
コード例 #25
0
 //        protected override float evalD(Point3D p, Vect3D d, ref float cur)
 //        {
 //            return base.evalD(p, d, ref cur);
 //       }
 public override float EvaluateImplicitFunction(Point3D p)
 {
     return parameter0 * _implicit0.EvaluateImplicitFunction(p) + parameter1 * _implicit1.EvaluateImplicitFunction(p);
 }
コード例 #26
0
 //Evaluates distance function at a given point in space. Can be overridden for special cases where exact distance function known (ie. sphere)
 protected virtual float EvaluateDistanceFunction(Point3D point, Vect3D distance, ref float cur)
 {
     //Distance (or at least the approximation of it) is a function d(x) = |f(x)/f'(x)|
     cur = EvaluateImplicitFunction(point);
     return Math.Abs(cur / EvaluateImplicitFunctionDerivative(point, distance));
 }
コード例 #27
0
 public override float EvaluateImplicitFunction(Point3D p)
 {
     return p.Y - (float)(0.5 * Math.Sin(p.X + 3 * w)) - 0.1f * (float)(((1 + 0.2 * Math.Sin(p.X * p.Z))) * Math.Cos(p.Z + 3 * w));
 }
コード例 #28
0
ファイル: Instance.cs プロジェクト: segafult/SCSRaytracer
        /*
        public override Material getMaterial()
        {
            if (_material == null)
            {
                return payload.getMaterial();
            }
            else
            {
                return _material;
            }
        }

        public override BoundingBox get_bounding_box()
        {
            compute_bounding_box();
            return bbox;
        }
        */
        public void ComputeBoundingBox()
        {
            //Get the bounding box of the payload prior to transformation.
            BoundingBox preTransform = payload.BoundingBox;
            float x0 = preTransform.corner0.X;
            float x1 = preTransform.corner1.X;
            float y0 = preTransform.corner0.Y;
            float y1 = preTransform.corner1.Y;
            float z0 = preTransform.corner0.Z;
            float z1 = preTransform.corner1.Z;

            //Get points representing all 8 corners of the bounding box
            Point3D[] points = new Point3D[8];
            points[0] = new Point3D(x0, y0, z0);
            points[1] = new Point3D(x0, y1, z0);
            points[2] = new Point3D(x0, y0, z1);
            points[3] = new Point3D(x0, y1, z1);
            points[4] = new Point3D(x1, y0, z0);
            points[5] = new Point3D(x1, y1, z0);
            points[6] = new Point3D(x1, y0, z1);
            points[7] = new Point3D(x1, y1, z1);

            //Transform all corner points
            for(int i = 0; i < 8; i++)
            {
                points[i] = netTransformationMatrix * points[i];
            }

            float xmin = GlobalVars.K_HUGE_VALUE;
            float xmax = -GlobalVars.K_HUGE_VALUE;
            float ymin = GlobalVars.K_HUGE_VALUE;
            float ymax = -GlobalVars.K_HUGE_VALUE;
            float zmin = GlobalVars.K_HUGE_VALUE;
            float zmax = -GlobalVars.K_HUGE_VALUE;

            //Find xmin, xmax, ymin, ymax, and zmin, zmax
            for(int i = 0; i < 8; i++)
            {
                if (points[i].X < xmin) xmin = points[i].X;
                if (points[i].X > xmax) xmax = points[i].X;
                if (points[i].Y < ymin) ymin = points[i].Y;
                if (points[i].Y > ymax) ymax = points[i].Y;
                if (points[i].Z < zmin) zmin = points[i].Z;
                if (points[i].Z > zmax) zmax = points[i].Z;
            }

            //Create bounding box based on transformed payload bounding box
            boundingBox = new BoundingBox(xmin, xmax, ymin, ymax, zmin, zmax);
        }
コード例 #29
0
ファイル: Box.cs プロジェクト: segafult/SCSRaytracer
 public void SetPoints(Point3D p1, Point3D p2)
 {
     x0 = p1.X < p2.X ? p1.X : p2.X;
     x1 = p1.X > p2.X ? p1.X : p2.X;
     y0 = p1.Y < p2.Y ? p1.Y : p2.Y;
     y1 = p1.Y > p2.Y ? p1.Y : p2.Y;
     z0 = p1.Z < p2.Z ? p1.Z : p2.Z;
     z1 = p1.Z > p2.Z ? p1.Z : p2.Z;
 }
コード例 #30
0
 public void SetBoundaries(Point3D min, Point3D max)
 {
     lowBound = Vector3.Min(min.Coordinates, max.Coordinates);
     highBound = Vector3.Max(min.Coordinates, max.Coordinates);
     SetupBounds();
 }