示例#1
0
        void computeViewToProj(ref Vector3 rayDir, BBoundingBox worldBounds, Matrix worldToView, out Matrix viewToProj,
                               int numXSegments, int numYSegments, int xSegment, int ySegment)
        {
            BBoundingBox viewBounds = new BBoundingBox();

            for (int i = 0; i < 8; i++)
            {
                Vector3 corner     = worldBounds.getCorner((BBoundingBox.eCornerIndex)i);
                Vector4 viewCorner = Vector3.Transform(corner, worldToView);

                viewBounds.addPoint(viewCorner.X, viewCorner.Y, viewCorner.Z);
            }

            float minZ = viewBounds.min.Z; // *0.5f;
            float maxZ = viewBounds.max.Z; // *2;

            float distanceX = Math.Abs(viewBounds.max.X - viewBounds.min.X);
            float segSizeX  = distanceX / numXSegments;
            float distanceY = Math.Abs(viewBounds.max.Y - viewBounds.min.Y);
            float segSizeY  = distanceY / numYSegments;

            float minXSeg = viewBounds.min.X + (segSizeX * xSegment);
            float minYSeg = viewBounds.min.Y + (segSizeY * ySegment);

            viewToProj = Matrix.OrthoOffCenterLH(
                minXSeg, minXSeg + segSizeX,
                minYSeg, minYSeg + segSizeY,
                minZ, maxZ);
        }
示例#2
0
        //--------------------------------------------------------------------------
        void computeTransforms(ref Vector3 rayDir, out Matrix worldToView, out Matrix viewToProj)
        {
            Vector3 mWorldMin = mScene.getWorldMin();
            Vector3 mWorldMax = mScene.getWorldMax();

            Vector3 eyePos   = new Vector3((mWorldMin.X + mWorldMax.X) * .5f, mWorldMax.Y + 50.0f, (mWorldMin.Z + mWorldMax.Z) * .5f);
            Vector3 focusPos = eyePos; focusPos.Y -= 1;
            Vector3 upDir    = BMathLib.unitZ;

            worldToView = Matrix.LookAtLH(eyePos, focusPos, upDir);

            BBoundingBox worldBounds = new BBoundingBox();

            worldBounds.min    = mWorldMin;
            worldBounds.min.Y -= 2;    //for depth peeling
            worldBounds.max    = mWorldMax;
            worldBounds.max.Y += 2;    //for depth peeling

            BBoundingBox viewBounds = new BBoundingBox();

            for (int i = 0; i < 8; i++)
            {
                Vector3 corner     = worldBounds.getCorner((BBoundingBox.eCornerIndex)i);
                Vector4 viewCorner = Vector3.Transform(corner, worldToView);

                viewBounds.addPoint(viewCorner.X, viewCorner.Y, viewCorner.Z);
            }

            float minZ = viewBounds.min.Z;
            float maxZ = viewBounds.max.Z;

            float offsetX = 0.5f / (viewBounds.max.X - viewBounds.min.X);
            float offsetY = 0;// -0.5f / (viewBounds.max.Y - viewBounds.min.Y);

            viewToProj = Matrix.OrthoOffCenterLH(
                viewBounds.min.X + offsetX, viewBounds.max.X + offsetX,
                viewBounds.min.Y + offsetY, viewBounds.max.Y + offsetY,
                minZ, maxZ);
        }
示例#3
0
        //--------------------------------------------------------------------------
        void computeTransforms(Vector3 upDir, ref Matrix worldToView, ref Matrix viewToProj, ref BBoundingBox worldBounds, ref double worldMinY, ref double worldMaxY)
        {
            float   diameter    = Vector3.Length(mWorldMax - mWorldMin);
            float   radius      = diameter * 0.5f;
            Vector3 worldCenter = (mWorldMax - mWorldMin) * 0.5f;

            Vector3 eyePos   = worldCenter + (BMathLib.unitY * radius);
            Vector3 focusPos = worldCenter;

            worldToView = Matrix.LookAtLH(eyePos, focusPos, upDir);

            worldBounds.min = mWorldMin;
            //     worldBounds.min.Y -= 2;
            worldBounds.max = mWorldMax;
            //    worldBounds.max.Y += 2;
            //worldBounds.max.X += 1; //CLM WHAT?
            //worldBounds.max.Z += 1; //CLM WHAT?


            BBoundingBox viewBounds = new BBoundingBox();

            for (int i = 0; i < 8; i++)
            {
                Vector3 corner     = worldBounds.getCorner((BBoundingBox.eCornerIndex)i);
                Vector4 viewCorner = Vector3.Transform(corner, worldToView);
                viewBounds.addPoint(viewCorner.X, viewCorner.Y, viewCorner.Z);
            }

            float minZ = viewBounds.min.Z; // *0.5f;
            float maxZ = viewBounds.max.Z; // *2;

            viewToProj = Matrix.OrthoOffCenterLH(
                viewBounds.min.X, viewBounds.max.X,
                viewBounds.min.Y, viewBounds.max.Y,
                minZ, maxZ);

            worldMinY = eyePos.Y + -minZ;
            worldMaxY = eyePos.Y + -maxZ;
        }