/// <summary>
        /// Draw occlusion bounding box method with our premade effect and box.
        /// </summary>
        /// <param name="bbox"></param>
        /// <param name="scale"></param>
        /// <param name="enableDepthTesting"></param>
        /// <param name="billboardLike">Indicates whether the occlusion object (box) is rotated to face the camera or not.</param>
        public static void DrawOcclusionBoundingBox(BoundingBox bbox, float scale, bool enableDepthTesting, bool billboardLike = false, bool useDepthTarget = true)
        {
            useDepthTarget &= !MyRenderConstants.RenderQualityProfile.ForwardRender;

            var    cameraToBBox = bbox.GetCenter() - MyCamera.Position;
            Matrix worldMatrix  = billboardLike ? Matrix.CreateWorld(Vector3.Zero, MyMwcUtils.Normalize(cameraToBBox), MyMwcUtils.Normalize(MyCamera.UpVector + MyCamera.LeftVector)) : Matrix.Identity;

            Vector3 scaleV = (bbox.Max - bbox.Min) * scale;

            worldMatrix            *= Matrix.CreateScale(scaleV);
            worldMatrix.Translation = cameraToBBox;



            MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw;

            if (enableDepthTesting && !MyRenderConstants.RenderQualityProfile.ForwardRender)
            {
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabled);
            }
            else
            {
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestDisabled);
            }


            effectOQ.SetWorldMatrix(worldMatrix);
            effectOQ.SetViewMatrix(MyCamera.ViewMatrixAtZero);
            effectOQ.SetProjectionMatrix(MyCamera.ProjectionMatrix);

            if (useDepthTarget)
            {
                var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effectOQ.SetDepthRT(depthRenderTarget);
                effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget));
            }

            effectOQ.Begin();

            //draw
            m_modelBoxLowRes.Render();

            effectOQ.End();
        }
Esempio n. 2
0
        private void IssueSpotQuery()
        {
            if (((LightType & LightTypeEnum.Spotlight) > 0) && SpotQuery != null && SpotQueryState == QueryState.IssueOcc)
            {
                BlendState previousBlendState = BlendState.Current;;
                MyStateObjects.DisabledColorChannels_BlendState.Apply();
                // RasterizerState.CullNone.Apply();
                // DepthStencilState.None.Apply();

                MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw;
                effectOQ.SetTechnique(MyEffectOcclusionQueryDraw.Technique.DepthTestEnabled);

                MatrixD spotWorld = SpotWorld;
                spotWorld.Translation = SpotWorld.Translation - MyRenderCamera.Position;
                effectOQ.SetWorldMatrix((Matrix)spotWorld);
                effectOQ.SetViewMatrix(MyRenderCamera.ViewMatrixAtZero);
                effectOQ.SetProjectionMatrix(MyRenderCamera.ProjectionMatrix);

                var depthRenderTarget = MyRender.GetRenderTarget(MyRenderTargets.Depth);
                effectOQ.SetDepthRT(depthRenderTarget);
                effectOQ.SetScale(MyRender.GetScaleForViewport(depthRenderTarget));

                SpotQuery.Begin();

                effectOQ.Begin();

                MyDebugDraw.ModelCone.Render();

                effectOQ.End();

                SpotQuery.End();

                SpotQueryState = QueryState.CheckOcc;

                previousBlendState.Apply();
            }

            if (SpotQueryState == QueryState.WaitOcc)
            {
                SpotQueryState = QueryState.IssueOcc;
            }
        }
        /// <summary>
        /// Needs to have PrepareFastOcclusionBoundingBoxDraw() called first
        /// </summary>
        public static void FastOcclusionBoundingBoxDraw(BoundingBox bbox, float scale)
        {
            Vector3 scaleV      = (bbox.Max - bbox.Min) * scale;
            Matrix  worldMatrix = Matrix.CreateScale(scaleV);

            worldMatrix.Translation = bbox.GetCenter() - MyCamera.Position;

            MyEffectOcclusionQueryDraw effectOQ = MyRender.GetEffect(MyEffects.OcclusionQueryDrawMRT) as MyEffectOcclusionQueryDraw;

            effectOQ.SetWorldMatrix(worldMatrix);
            effectOQ.SetTechnique(MyRenderConstants.RenderQualityProfile.ForwardRender ? MyEffectOcclusionQueryDraw.Technique.DepthTestDisabled : MyEffectOcclusionQueryDraw.Technique.DepthTestEnabled);

            effectOQ.Begin();

            //draw
            m_modelBoxLowRes.Render();
            MyPerformanceCounter.PerCameraDraw.TotalDrawCalls++;

            effectOQ.End();
        }