Exemple #1
0
 internal static FloatColour Min(FloatColour value1, FloatColour value2)
 {
     FloatColour output;
     output.R = Math.Min(value1.R, value2.R);
     output.G = Math.Min(value1.G, value2.G);
     output.B = Math.Min(value1.B, value2.B);
     return output;
 }
Exemple #2
0
        internal static FloatColour Min(FloatColour value1, FloatColour value2)
        {
            FloatColour output;

            output.R = Math.Min(value1.R, value2.R);
            output.G = Math.Min(value1.G, value2.G);
            output.B = Math.Min(value1.B, value2.B);
            return(output);
        }
Exemple #3
0
        public static FloatColour operator *(FloatColour value, float multiplier)
        {
            FloatColour output = value;

            output.R *= multiplier;
            output.G *= multiplier;
            output.B *= multiplier;
            return(output);
        }
Exemple #4
0
        public FloatColour TraceRay(Primitive pIgnorePrimitive, Ray tRay, int nDepth)
        {
            // check whether we have reached maximum recursion depth
            if (nDepth > 6)
            {
                //return new Colour(0, 0, 0);
                return(new FloatColour(1));
            }

            // declare intersection variables
            float     fClosestIntersectionDistance = float.MaxValue;
            Primitive closestIntersectedPrimitive  = null;

            // loop through all objects in scene
            foreach (Primitive primitive in m_pScene.Primitives)
            {
                // test for intersection
                float fDistance;
                if (primitive.Intersect(tRay, out fDistance))
                {
                    // check that we are closer than the last intersection
                    if (fDistance < fClosestIntersectionDistance)
                    {
                        // set closest intersection
                        fClosestIntersectionDistance = fDistance;
                        closestIntersectedPrimitive  = primitive;
                    }
                }
            }

            // if nothing was intersected, set to background colour
            FloatColour tColour = new FloatColour(Color.CornflowerBlue);

            if (closestIntersectedPrimitive != null)             // test for intersection
            {
                tColour = closestIntersectedPrimitive.Shade(this,
                                                            tRay, fClosestIntersectionDistance, nDepth + 1);
            }

            tColour = FloatColour.Min(tColour, new FloatColour(1));

            // return colour
            return(tColour);
        }
Exemple #5
0
        public bool ProcessFrame()
        {
            // loop through all pixels
            for (int y = 0; y < _height; y++)
            {
                for (int x = 0; x < _width; x++)
                {
                    // set direction of ray
                    Ray tPrimaryRay = _camera.GetUnprojectedRay(x, y);

                    // trace ray (this is recursive)
                    FloatColour tColour = TraceRay(null, tPrimaryRay, 0);

                    // set colour of pixels in bitmap
                    m_pImage[x, y] = tColour;
                }
            }

            return(true);
        }
Exemple #6
0
        public FloatColour TraceRay(Primitive pIgnorePrimitive, Ray tRay, int nDepth)
        {
            // check whether we have reached maximum recursion depth
            if (nDepth > 6)
            {
                //return new Colour(0, 0, 0);
                return new FloatColour(1);
            }

            // declare intersection variables
            float fClosestIntersectionDistance = float.MaxValue;
            Primitive closestIntersectedPrimitive = null;

            // loop through all objects in scene
            foreach (Primitive primitive in m_pScene.Primitives)
            {
                // test for intersection
                float fDistance;
                if (primitive.Intersect(tRay, out fDistance))
                {
                    // check that we are closer than the last intersection
                    if (fDistance < fClosestIntersectionDistance)
                    {
                        // set closest intersection
                        fClosestIntersectionDistance = fDistance;
                        closestIntersectedPrimitive = primitive;
                    }
                }
            }

            // if nothing was intersected, set to background colour
            FloatColour tColour = new FloatColour(Color.CornflowerBlue);
            if (closestIntersectedPrimitive != null) // test for intersection
            {
                tColour = closestIntersectedPrimitive.Shade(this,
                    tRay, fClosestIntersectionDistance, nDepth + 1);
            }

            tColour = FloatColour.Min(tColour, new FloatColour(1));

            // return colour
            return tColour;
        }